Commit c4532e4d authored by SVN-Git Migration's avatar SVN-Git Migration

Imported Upstream version 0.6

parent d94514f1
Metadata-Version: 1.0
Name: pyacoustid
Version: 0.4
Version: 0.6
Summary: bindings for Chromaprint acoustic fingerprinting and the Acoustid API
Home-page: https://github.com/sampsyo/pyacoustid
Author: Adrian Sampson
......@@ -78,6 +78,9 @@ Description: Chromaprint and Acoustid for Python
- ``fingerprint(samplerate, channels, pcmiter)``: Generate a fingerprint for raw
audio data. Specify the audio parameters and give an iterable containing
blocks of PCM data.
- ``fingerprint_file(path)``: Using either the Chromaprint dynamic library or
the ``fpcalc`` command-line tool, fingerprint an audio file. Returns a pair
consisting of the file's duration and its fingerprint.
- ``lookup(apikey, fingerprint, duration)``: Make a request to the `Acoustid`_
API to look up the fingerprint returned by the previous function. An API key
is required, as is the length, in seconds, of the source audio. Returns a
......@@ -96,7 +99,8 @@ Description: Chromaprint and Acoustid for Python
Calls to the library can raise ``AcoustidError`` exceptions of two subtypes:
``FingerprintGenerationError`` and ``WebServiceError``. Catch these exceptions
if you want to proceed when audio can't be decoded or no match is found on the
server.
server. ``NoBackendError``, a subclass of ``FingerprintGenerationError``, is
used when the Chromaprint library or fpcalc command-line tool cannot be found.
.. _Web service documentation: http://acoustid.org/webservice
......@@ -104,6 +108,15 @@ Description: Chromaprint and Acoustid for Python
Version History
---------------
0.6
Add a new function, ``fingerprint_file``, that automatically selects a
backend for fingerprinting a single file.
0.5
Fix response parsing when recording has no artists or title.
Fix compatibility with Python < 2.7.
Add specific ``NoBackendError`` exception.
0.4
Fingerprinting can now fall back to using the ``fpcalc`` command-line tool
instead of the Chromaprint dynamic library so the library can be used with
......
......@@ -70,6 +70,9 @@ parts of the process:
- ``fingerprint(samplerate, channels, pcmiter)``: Generate a fingerprint for raw
audio data. Specify the audio parameters and give an iterable containing
blocks of PCM data.
- ``fingerprint_file(path)``: Using either the Chromaprint dynamic library or
the ``fpcalc`` command-line tool, fingerprint an audio file. Returns a pair
consisting of the file's duration and its fingerprint.
- ``lookup(apikey, fingerprint, duration)``: Make a request to the `Acoustid`_
API to look up the fingerprint returned by the previous function. An API key
is required, as is the length, in seconds, of the source audio. Returns a
......@@ -88,7 +91,8 @@ for all API calls with the ``set_base_url`` function.
Calls to the library can raise ``AcoustidError`` exceptions of two subtypes:
``FingerprintGenerationError`` and ``WebServiceError``. Catch these exceptions
if you want to proceed when audio can't be decoded or no match is found on the
server.
server. ``NoBackendError``, a subclass of ``FingerprintGenerationError``, is
used when the Chromaprint library or fpcalc command-line tool cannot be found.
.. _Web service documentation: http://acoustid.org/webservice
......@@ -96,6 +100,15 @@ server.
Version History
---------------
0.6
Add a new function, ``fingerprint_file``, that automatically selects a
backend for fingerprinting a single file.
0.5
Fix response parsing when recording has no artists or title.
Fix compatibility with Python < 2.7.
Add specific ``NoBackendError`` exception.
0.4
Fingerprinting can now fall back to using the ``fpcalc`` command-line tool
instead of the Chromaprint dynamic library so the library can be used with
......
......@@ -18,6 +18,7 @@ import urllib
import urllib2
import httplib
import contextlib
import errno
try:
import audioread
have_audioread = True
......@@ -47,6 +48,11 @@ class AcoustidError(Exception):
class FingerprintGenerationError(AcoustidError):
"""The audio could not be fingerprinted."""
class NoBackendError(FingerprintGenerationError):
"""The audio could not be fingerprinted because neither the
Chromaprint library nor the fpcalc command-line tool is installed.
"""
class FingerprintSubmissionError(AcoustidError):
"""Missing required data for a fingerprint submission."""
......@@ -221,13 +227,13 @@ def parse_lookup_result(data):
recording = result['recordings'][0]
# Get the artist if available.
if recording['artists']:
if recording.get('artists'):
artist = recording['artists'][0]
artist_name = artist['name']
else:
artist_name = None
yield score, recording['id'], recording['title'], artist_name
yield score, recording['id'], recording.get('title'), artist_name
def _fingerprint_file_audioread(path):
"""Fingerprint a file by using audioread and chromaprint."""
......@@ -244,9 +250,18 @@ def _fingerprint_file_fpcalc(path):
fpcalc = os.environ.get(FPCALC_ENVVAR, FPCALC_COMMAND)
command = [fpcalc, "-length", str(MAX_AUDIO_LENGTH), path]
try:
output = subprocess.check_output(command)
except (OSError, subprocess.CalledProcessError):
raise FingerprintGenerationError("fpcalc invocation failed")
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
output, _ = proc.communicate()
except OSError, exc:
if exc.errno == errno.ENOENT:
raise NoBackendError("fpcalc not found")
else:
raise FingerprintGenerationError("fpcalc invocation failed: %s" %
str(exc))
retcode = proc.poll()
if retcode:
raise FingerprintGenerationError("fpcalc exited with status %i" %
retcode)
duration = fp = None
for line in output.splitlines():
......@@ -266,17 +281,24 @@ def _fingerprint_file_fpcalc(path):
raise FingerprintGenerationError("missing fpcalc output")
return duration, fp
def fingerprint_file(path):
"""Fingerprint a file either using the Chromaprint dynamic library
or the fpcalc command-line tool, whichever is available. Returns the
duration and the fingerprint.
"""
path = os.path.abspath(os.path.expanduser(path))
if have_audioread and have_chromaprint:
return _fingerprint_file_audioread(path)
else:
return _fingerprint_file_fpcalc(path)
def match(apikey, path, meta=DEFAULT_META, parse=True):
"""Look up the metadata for an audio file. If ``parse`` is true,
then ``parse_lookup_result`` is used to return an iterator over
small tuple of relevant information; otherwise, the full parsed JSON
response is returned.
"""
path = os.path.abspath(os.path.expanduser(path))
if have_audioread and have_chromaprint:
duration, fp = _fingerprint_file_audioread(path)
else:
duration, fp = _fingerprint_file_fpcalc(path)
duration, fp = fingerprint_file(path)
response = lookup(apikey, fp, duration, meta)
if parse:
return parse_lookup_result(response)
......
......@@ -26,6 +26,9 @@ API_KEY = 'cSpUJKpD'
def aidmatch(filename):
try:
results = acoustid.match(API_KEY, filename)
except acoustid.NoBackendError:
print >>sys.stderr, "chromaprint library/tool not found"
sys.exit(1)
except acoustid.FingerprintGenerationError:
print >>sys.stderr, "fingerprint could not be calculated"
sys.exit(1)
......
Metadata-Version: 1.0
Name: pyacoustid
Version: 0.4
Version: 0.6
Summary: bindings for Chromaprint acoustic fingerprinting and the Acoustid API
Home-page: https://github.com/sampsyo/pyacoustid
Author: Adrian Sampson
......@@ -78,6 +78,9 @@ Description: Chromaprint and Acoustid for Python
- ``fingerprint(samplerate, channels, pcmiter)``: Generate a fingerprint for raw
audio data. Specify the audio parameters and give an iterable containing
blocks of PCM data.
- ``fingerprint_file(path)``: Using either the Chromaprint dynamic library or
the ``fpcalc`` command-line tool, fingerprint an audio file. Returns a pair
consisting of the file's duration and its fingerprint.
- ``lookup(apikey, fingerprint, duration)``: Make a request to the `Acoustid`_
API to look up the fingerprint returned by the previous function. An API key
is required, as is the length, in seconds, of the source audio. Returns a
......@@ -96,7 +99,8 @@ Description: Chromaprint and Acoustid for Python
Calls to the library can raise ``AcoustidError`` exceptions of two subtypes:
``FingerprintGenerationError`` and ``WebServiceError``. Catch these exceptions
if you want to proceed when audio can't be decoded or no match is found on the
server.
server. ``NoBackendError``, a subclass of ``FingerprintGenerationError``, is
used when the Chromaprint library or fpcalc command-line tool cannot be found.
.. _Web service documentation: http://acoustid.org/webservice
......@@ -104,6 +108,15 @@ Description: Chromaprint and Acoustid for Python
Version History
---------------
0.6
Add a new function, ``fingerprint_file``, that automatically selects a
backend for fingerprinting a single file.
0.5
Fix response parsing when recording has no artists or title.
Fix compatibility with Python < 2.7.
Add specific ``NoBackendError`` exception.
0.4
Fingerprinting can now fall back to using the ``fpcalc`` command-line tool
instead of the Chromaprint dynamic library so the library can be used with
......
......@@ -25,7 +25,7 @@ def _read(fn):
return data
setup(name='pyacoustid',
version='0.4',
version='0.6',
description=
'bindings for Chromaprint acoustic fingerprinting and the '
'Acoustid API',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment