예제 #1
0
파일: chroma.py 프로젝트: jck/beets
 def submit_chunk():
     """Submit the current accumulated fingerprint data."""
     log.info(u'submitting {0} fingerprints', len(data))
     try:
         acoustid.submit(API_KEY, userkey, data)
     except acoustid.AcoustidError as exc:
         log.warn(u'acoustid submission error: {0}', exc)
     del data[:]
예제 #2
0
 def submit_chunk():
     """Submit the current accumulated fingerprint data."""
     log.info(u'submitting {0} fingerprints', len(data))
     try:
         acoustid.submit(API_KEY, userkey, data)
     except acoustid.AcoustidError as exc:
         log.warn(u'acoustid submission error: {0}', exc)
     del data[:]
예제 #3
0
    def submit(self, fns):
        if not self.__user_key:
            raise SubmissionError(
                translate("AcoustID",
                          "Please enter AcoustID user key in settings."))

        fns_len = len(fns)
        data = []
        for i, fn in enumerate(fns):

            try:
                disp_fn = audioinfo.decode_fn(fn.filepath)
            except AttributeError:
                disp_fn = fn['__path']
            write_log(FILE_MSG.arg(i + 1).arg(disp_fn))

            try:
                fp = id_in_tag(fn)
                if fp:
                    write_log(FOUND_ID_MSG)
                    dur, fp = fp
                else:
                    write_log(CALCULATE_MSG)
                    dur, fp = fingerprint_file(fn.filepath)

                info = {
                    'duration': str(dur),
                    'fingerprint': str(fp),
                }

                info.update(convert_for_submit(fn))
                data.append(info)

                if len(data) > 9 or i == fns_len - 1:
                    msg = SUBMIT_MSG.arg(i - len(data) + 2)
                    msg = msg.arg(i + 1).arg(fns_len)
                    write_log(msg)
                    set_status(msg)
                    acoustid.submit(API_KEY, self.__user_key, data)
                    data = []

            except acoustid.FingerprintGenerationError as e:
                traceback.print_exc()
                write_log(FP_ERROR_MSG.arg(str(e)))
                continue
            except acoustid.WebServiceError as e:
                traceback.print_exc()
                set_status(SUBMIT_ERROR_MSG.arg(str(e)))
                write_log(SUBMIT_ERROR_MSG.arg(str(e)))
                break
예제 #4
0
    def submit(self, fns):
        if not self.__user_key:
            raise SubmissionError(translate("AcoustID",
                "Please enter AcoustID user key in settings."))

        fns_len = len(fns)
        data = []
        for i, fn in enumerate(fns):

            try:
                disp_fn = audioinfo.decode_fn(fn.filepath)
            except AttributeError:
                disp_fn = fn['__path']
            write_log(FILE_MSG.arg(i + 1).arg(disp_fn))

            try:
                fp = id_in_tag(fn)
                if fp:
                    write_log(FOUND_ID_MSG)
                    dur, fp = fp
                else:
                    write_log(CALCULATE_MSG)
                    dur, fp = fingerprint_file(fn.filepath)

                info = {
                    'duration':unicode(dur),
                    'fingerprint': unicode(fp),
                    }

                info.update(convert_for_submit(fn))
                data.append(info)

                if len(data) > 9 or i == fns_len - 1:
                    msg = SUBMIT_MSG.arg(i - len(data) + 2)
                    msg = msg.arg(i + 1).arg(fns_len)
                    write_log(msg)
                    set_status(msg)
                    acoustid.submit(API_KEY, self.__user_key, data)
                    data = []

            except acoustid.FingerprintGenerationError, e:
                traceback.print_exc()
                write_log(FP_ERROR_MSG.arg(unicode(e)))
                continue
            except acoustid.WebServiceError, e:
                traceback.print_exc()
                set_status(SUBMIT_ERROR_MSG.arg(unicode(e)))
                write_log(SUBMIT_ERROR_MSG.arg(unicode(e)))
                break
예제 #5
0
def returnMatch(id=None):
    file = mockDB[id]["title"]
    filename = "./pyacoustid-1.1.5/" + file
    duration, fingerprint = acoustid.fingerprint_file(filename)
    try:
        results = list(acoustid.match(API_KEY, filename))
    except acoustid.NoBackendError:
        print("chromaprint library/tool not found")
        sys.exit(1)
    except acoustid.FingerprintGenerationError:
        print("fingerprint could not be calculated")
        sys.exit(1)
    except acoustid.WebServiceError as exc:
        print("web service request failed:", exc.message)
        sys.exit(1)
    if len(results) > 0:
        resp = make_response(json.dumps(results), 200)
        resp.headers['mimetype'] = 'application/json'
        # check if there's a payment pointer in our db for this ID. If so then this is verified.
        print("match", results)
        return resp
    else:
        # Submit fingerprint to database.
        data = {
            'fingerprint': fingerprint,
            'duration': int(duration),
            'title': basename(filename)
        }
        print("DATA", data)
        # check if license is there. If so then return license, but note this is NOT verified since it is not in MusicBrainz database.
        try:
            result = acoustid.submit(API_KEY, USER_KEY, data)
        except acoustid.FingerprintGenerationError:
            print("fingerprint could not be calculated")
            sys.exit(1)
        except acoustid.WebServiceError as exc:
            print("web service request failed:", exc.message)
            sys.exit(1)
        return "success!"
예제 #6
0
파일: chroma.py 프로젝트: encukou/beets
 def submit_chunk():
     """Submit the current accumulated fingerprint data."""
     log.info('submitting {0} fingerprints'.format(len(data)))
     acoustid.submit(API_KEY, userkey, data)
     del data[:]
예제 #7
0
파일: chroma.py 프로젝트: encukou/beets
 def submit_chunk():
     """Submit the current accumulated fingerprint data."""
     log.info('submitting {0} fingerprints'.format(len(data)))
     acoustid.submit(API_KEY, userkey, data)
     del data[:]