#!/usr/bin/python

import sys
import os
import re
import time
import urllib2
import json
from editing import MusicBrainzClient
from utils import out, colored_out, bcolors, monkeypatch_mechanize
import config as cfg

# Work around mechanize bug. See: https://github.com/jjlee/mechanize/pull/58
monkeypatch_mechanize()

mb = MusicBrainzClient(cfg.MB_USERNAME, cfg.MB_PASSWORD, cfg.MB_SITE)

FILE_RE = re.compile(r'^(?P<mbid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})-(?P<type>front|back|medium|booklet|tray)(?:-\d+)?\.(?:jpeg|jpg|png|gif)', re.I)

class CoverArtArchiveReleaseInfo(object):
	def __init__(self, release_id):
		try:
			data = urllib2.urlopen('http://coverartarchive.org/release/%s/' % release_id)
			self.metadata = json.load(data)
		except urllib2.HTTPError:
			self.metadata = {'images':  [], 'release': 'http://musicbrainz.org/release/%s' % release_id}

	def hasType(self, type):
		for image in self.metadata['images']:
			for img_type in image['types']:
				if img_type.lower() == type.lower():
#!/usr/bin/python

import sys
import os
import re
import time
import urllib2
import json
from editing import MusicBrainzClient
from utils import out, colored_out, bcolors, monkeypatch_mechanize
import config as cfg

# Work around mechanize bug. See: https://github.com/jjlee/mechanize/pull/58
monkeypatch_mechanize()

mb = MusicBrainzClient(cfg.MB_USERNAME, cfg.MB_PASSWORD, cfg.MB_SITE)

FILE_RE = re.compile(
    r'^(?P<mbid>[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})-(?P<type>front|back|medium|booklet|tray|sticker)(?:-\d+)?\.(?:jpeg|jpg|png|gif)',
    re.I)


class CoverArtArchiveReleaseInfo(object):
    def __init__(self, release_id):
        try:
            data = urllib2.urlopen('http://coverartarchive.org/release/%s/' %
                                   release_id)
            self.metadata = json.load(data)
        except urllib2.HTTPError:
            self.metadata = {
                'images': [],
Beispiel #3
0
    except ImportError:
        zbar = None
        print "Warning: Cannot import zbar. Install python-zbar for barcode scanning"
except ImportError:
    Image = None
    print "Warning: Cannot import PIL. Install python-imaging for image dimension information"

try:
    import psycopg2
    from psycopg2.extras import NamedTupleCursor
except ImportError:
    psycopg2 = None

ACC_CACHE = 'acc-cache'

utils.monkeypatch_mechanize()

def re_find1(regexp, string):
    m = re.findall(regexp, string)
    if len(m) != 1:
        pat = getattr(regexp, 'pattern', regexp)
        if len(string) > 200:
            filename = '/tmp/debug.html'
            with open(filename, 'wb') as f:
                f.write(string)
            raise AssertionError("Expression %s matched %d times, see %s" % (pat, len(m), filename))
        else:
            raise AssertionError("Expression %s matched %d times: %r" % (pat, len(m), string))
    return m[0]

def create_parent_dir(filename):