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

Imported Upstream version 1.0.0

parent bb5d6110
Metadata-Version: 1.0
Metadata-Version: 1.1
Name: pyacoustid
Version: 0.7
Version: 1.0.0
Summary: bindings for Chromaprint acoustic fingerprinting and the Acoustid API
Home-page: https://github.com/sampsyo/pyacoustid
Author: Adrian Sampson
......@@ -108,6 +108,13 @@ Description: Chromaprint and Acoustid for Python
Version History
---------------
1.0.0
Include ``fpcalc.py``, a script mimicking the ``fpcalc`` program from the
Chromaprint package.
Handle a ``UnicodeDecodeError`` raised when using the ``fpcalc`` backend on
Windows with Unicode filenames.
Standard error output from ``fpcalc`` is suppressed.
0.7
Properly encode Unicode parameters (resolves a ``UnicodeEncodeError``
in fingerprint submission).
......
......@@ -100,6 +100,13 @@ used when the Chromaprint library or fpcalc command-line tool cannot be found.
Version History
---------------
1.0.0
Include ``fpcalc.py``, a script mimicking the ``fpcalc`` program from the
Chromaprint package.
Handle a ``UnicodeDecodeError`` raised when using the ``fpcalc`` backend on
Windows with Unicode filenames.
Standard error output from ``fpcalc`` is suppressed.
0.7
Properly encode Unicode parameters (resolves a ``UnicodeEncodeError``
in fingerprint submission).
......
......@@ -143,7 +143,7 @@ def _send_request(req):
try:
with contextlib.closing(urllib2.urlopen(req)) as f:
return f.read(), f.info()
except urllib2.HTTPError, exc:
except urllib2.HTTPError as exc:
raise WebServiceError('HTTP status %i' % exc.code, exc.read())
except httplib.BadStatusLine:
raise WebServiceError('bad HTTP status line')
......@@ -181,14 +181,14 @@ def _api_request(url, params):
except ValueError:
raise WebServiceError('response is not valid JSON')
def fingerprint(samplerate, channels, pcmiter):
def fingerprint(samplerate, channels, pcmiter, maxlength=MAX_AUDIO_LENGTH):
"""Fingerprint audio data given its sample rate and number of
channels. pcmiter should be an iterable containing blocks of PCM
data as byte strings. Raises a FingerprintGenerationError if
anything goes wrong.
"""
# Maximum number of samples to decode.
endposition = samplerate * MAX_AUDIO_LENGTH
endposition = samplerate * channels * maxlength
try:
fper = chromaprint.Fingerprinter()
......@@ -246,29 +246,36 @@ def parse_lookup_result(data):
yield score, recording['id'], recording.get('title'), artist_name
def _fingerprint_file_audioread(path):
def _fingerprint_file_audioread(path, maxlength):
"""Fingerprint a file by using audioread and chromaprint."""
try:
with audioread.audio_open(path) as f:
duration = f.duration
fp = fingerprint(f.samplerate, f.channels, iter(f))
fp = fingerprint(f.samplerate, f.channels, iter(f), maxlength)
except audioread.DecodeError:
raise FingerprintGenerationError("audio could not be decoded")
return duration, fp
def _fingerprint_file_fpcalc(path):
def _fingerprint_file_fpcalc(path, maxlength):
"""Fingerprint a file by calling the fpcalc application."""
fpcalc = os.environ.get(FPCALC_ENVVAR, FPCALC_COMMAND)
command = [fpcalc, "-length", str(MAX_AUDIO_LENGTH), path]
command = [fpcalc, "-length", str(maxlength), path]
try:
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
output, _ = proc.communicate()
except OSError, exc:
with open(os.devnull, 'wb') as devnull:
proc = subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=devnull)
output, _ = proc.communicate()
except OSError as exc:
if exc.errno == errno.ENOENT:
raise NoBackendError("fpcalc not found")
else:
raise FingerprintGenerationError("fpcalc invocation failed: %s" %
str(exc))
except UnicodeEncodeError:
# Due to a bug in Python 2's subprocess on Windows, Unicode
# filenames can fail to encode on that platform. See:
# http://bugs.python.org/issue1759845
raise FingerprintGenerationError("argument encoding failed")
retcode = proc.poll()
if retcode:
raise FingerprintGenerationError("fpcalc exited with status %i" %
......@@ -292,16 +299,16 @@ def _fingerprint_file_fpcalc(path):
raise FingerprintGenerationError("missing fpcalc output")
return duration, fp
def fingerprint_file(path):
def fingerprint_file(path, maxlength=MAX_AUDIO_LENGTH):
"""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)
return _fingerprint_file_audioread(path, maxlength)
else:
return _fingerprint_file_fpcalc(path)
return _fingerprint_file_fpcalc(path, maxlength)
def match(apikey, path, meta=DEFAULT_META, parse=True):
"""Look up the metadata for an audio file. If ``parse`` is true,
......
Metadata-Version: 1.0
Metadata-Version: 1.1
Name: pyacoustid
Version: 0.7
Version: 1.0.0
Summary: bindings for Chromaprint acoustic fingerprinting and the Acoustid API
Home-page: https://github.com/sampsyo/pyacoustid
Author: Adrian Sampson
......@@ -108,6 +108,13 @@ Description: Chromaprint and Acoustid for Python
Version History
---------------
1.0.0
Include ``fpcalc.py``, a script mimicking the ``fpcalc`` program from the
Chromaprint package.
Handle a ``UnicodeDecodeError`` raised when using the ``fpcalc`` backend on
Windows with Unicode filenames.
Standard error output from ``fpcalc`` is suppressed.
0.7
Properly encode Unicode parameters (resolves a ``UnicodeEncodeError``
in fingerprint submission).
......
......@@ -25,7 +25,7 @@ def _read(fn):
return data
setup(name='pyacoustid',
version='0.7',
version='1.0.0',
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