コード例 #1
0
def parse_lookup_result(data, albums=False, fp=None):
    if data['status'] != 'ok':
        raise acoustid.WebServiceError("status: %s" % data['status'])
    if 'results' not in data:
        raise acoustid.WebServiceError("results not included")

    try:
        result = data['results'][0]
    except IndexError:
        return None
    info = {}
    info['#score'] = result['score']
    if not result.get('recordings'):
        # No recording attached. This result is not very useful.
        return {
            'acoustid_id': result['id'],
            '#score': result['score'],
            'acoustid_fingerprint': fp,
        }

    if fp:
        info['acoustid_fingerprint'] = fp

    tracks = [parse_recording_data(r, info) for r in result['recordings']]

    return tracks
コード例 #2
0
 def _send_request(self, req):
     """Given a urllib2 Request object, make the request and return a
     tuple containing the response data and headers.
     """
     if time.time() - self.__lasttime < 0.4:
         time.sleep(time.time() - self.__lasttime + 0.1)
     try:
         with contextlib.closing(urllib.request.urlopen(req)) as f:
             return f.read(), f.info()
     except urllib.error.HTTPError as exc:
         raise acoustid.WebServiceError('HTTP status %i' % exc.code, exc.read())
     except http.client.BadStatusLine:
         raise acoustid.WebServiceError('bad HTTP status line')
     except IOError:
         raise acoustid.WebServiceError('connection failed')
コード例 #3
0
ファイル: acoust_id.py プロジェクト: korala1968/tago
class AcoustID(object):
    name = 'AcoustID'
    group_by = ['album', None]

    def __init__(self):
        object.__init__(self)
        self.min_score = 0.80
        self.preferences = [[
            translate("AcoustID", 'Minimum Score'), SPINBOX, [0, 100, 80]
        ], [translate("AcoustID", "AcoustID Key"), TEXT, u""]]
        self.__lasttime = time.time()
        acoustid._send_request = self._send_request
        self.__user_key = ""

    def _send_request(self, req):
        """Given a urllib2 Request object, make the request and return a
        tuple containing the response data and headers.
        """
        if time.time() - self.__lasttime < 0.4:
            time.sleep(time.time() - self.__lasttime + 0.1)
        try:
            with contextlib.closing(urllib2.urlopen(req)) as f:
                return f.read(), f.info()
        except urllib2.HTTPError, exc:
            raise acoustid.WebServiceError('HTTP status %i' % exc.code,
                                           exc.read())
        except httplib.BadStatusLine:
            raise acoustid.WebServiceError('bad HTTP status line')
コード例 #4
0
ファイル: acoust_id.py プロジェクト: korala1968/tago
 def _send_request(self, req):
     """Given a urllib2 Request object, make the request and return a
     tuple containing the response data and headers.
     """
     if time.time() - self.__lasttime < 0.4:
         time.sleep(time.time() - self.__lasttime + 0.1)
     try:
         with contextlib.closing(urllib2.urlopen(req)) as f:
             return f.read(), f.info()
     except urllib2.HTTPError, exc:
         raise acoustid.WebServiceError('HTTP status %i' % exc.code,
                                        exc.read())
コード例 #5
0
ファイル: acoust_id.py プロジェクト: korala1968/tago
    def _send_request(self, req):
        """Given a urllib2 Request object, make the request and return a
        tuple containing the response data and headers.
        """
        if time.time() - self.__lasttime < 0.4:
            time.sleep(time.time() - self.__lasttime + 0.1)
        try:
            with contextlib.closing(urllib2.urlopen(req)) as f:
                return f.read(), f.info()
        except urllib2.HTTPError, exc:
            raise acoustid.WebServiceError('HTTP status %i' % exc.code,
                                           exc.read())
        except httplib.BadStatusLine:
            raise acoustid.WebServiceError('bad HTTP status line')
        except IOError:
            raise acoustid.WebServiceError('connection failed')

    def search(self, artist, fns=None):

        tracks = []
        albums = []

        fns_len = len(fns)
        for i, fn in enumerate(fns):
            try:
                disp_fn = audioinfo.decode_fn(fn.filepath)
            except AttributeError:
                disp_fn = fn['__path']
            write_log(disp_fn)
            try: