Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that argument to decode_fingerprint is bytes #39

Open
patatetom opened this issue Jan 24, 2018 · 3 comments
Open

Check that argument to decode_fingerprint is bytes #39

patatetom opened this issue Jan 24, 2018 · 3 comments

Comments

@patatetom
Copy link

hello,

I'm trying to play with pyacoustid but I'm encountering a mistake I can't get past.

I have the same audio recording in mp3 and ogg format on which I run the program fpcalc with the -plain option :

# pacman -S chromaprint
...
Packages (1) chromaprint-1.4.3-1
...

$ pip install --user pyacoustid
...
Successfully installed pyacoustid-1.1.5

$ fpcalc -plain neil.*
AQAAH5ukTWESCRcDJqFToetxRQlKCe7hX8JfpNORrEftTPAfUJRmVJJT9EiYI2SFuwq-HVvMB98adBpzeDzSPMoFzXbwZNagJ8R95CPSaZwAiAAARjkgETAUKQEQU4AoRwAB
AQAAIJukTckUCRcLJqFToWOOKwtKCe7hX8JfpNORrEftTPAfUJRmVJJT9EiYI2SFuwo-5dj-4NwadBpzeDzSPMoFzXbwzBp0JsR95CPSaZyg0wGIAABGOSARMBQpARBgChBmCCAI

in python3, I'm trying this piece of code inspired by https://gist.github.com/lalinsky/1132166 :

import chromaprint
a = 'AQAAH5ukTWESCRcDJqFToetxRQlKCe7hX8JfpNORrEftTPAfUJRmVJJT9EiYI2SFuwq-HVvMB98adBpzeDzSPMoFzXbwZNagJ8R95CPSaZwAiAAARjkgETAUKQEQU4AoRwAB'
A = chromaprint.decode_fingerprint(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pascal/.local/lib/python3.6/site-packages/chromaprint.py", line 149, in decode_fingerprint
    ctypes.byref(algorithm), 1 if base64 else 0
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

a does not appear to be base64 encoded :

import base64
base64.b64decode(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/base64.py", line 87, in b64decode
    return binascii.a2b_base64(s)
binascii.Error: Incorrect padding

what's the mistake I'm making ?

regards, lacsaP.

@lalinsky
Copy link
Collaborator

I guess this is a Python 3 issue and if you pass the fingerprint to decode_fingerprint as bytes instead of str, it will work.

But do you know that you can get the decoded fingerprint from fpcalc? Just add the -raw option and then you don't need to use the chromaprint library at all.

@patatetom
Copy link
Author

yes, it works better with this :

a = b'AQAAH5ukTWESCRcDJqFToetxRQlKCe7hX8JfpNORrEftTPAfUJRmVJJT9EiYI2SFuwq-HVvMB98adBpzeDzSPMoFzXbwZNagJ8R95CPSaZwAiAAARjkgETAUKQEQU4AoRwAB'

thanks and sorry for the inconvenience !

@sampsyo sampsyo changed the title ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type Check that argument to decode_fingerprint is bytes Jan 24, 2018
@sampsyo
Copy link
Member

sampsyo commented Jan 24, 2018

Thanks, @lalinsky!

I'm going to reopen this issue as a reminder that we should add an earlier type check to make it clear what's gone wrong when this happens.

@sampsyo sampsyo reopened this Jan 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants