beetbox / pyacoustid

Python bindings for Chromaprint acoustic fingerprinting and the Acoustid Web service
MIT License
325 stars 66 forks source link

create a function that yields (score, track id) tuples #7

Closed weisslj closed 12 years ago

weisslj commented 12 years ago

it should be simpler to just get the result of an API request without or empty "meta" parameter

sampsyo commented 12 years ago

To be clear, are you interested in an alternative to parse_lookup_result() that just gets the score and the internal Acoustid track ID? (Or did you mean the MusicBrainz recording ID?)

weisslj commented 12 years ago

Yes, score and "internal" Acoustid track id (it is not really that internal, as it is written to tags by Picard, and also visible on the MusicBrainz page). Initially I wanted to modify parse_lookup_result(), but it would be bad to make the output dependent on the parameter of "meta", wouldn't it?

sampsyo commented 12 years ago

Sounds good. I was thinking of changing the "parse" parameter to "match" so that, instead of a boolean, it takes a function. It defaults to parse_lookup_result, but can be this hypothetical new parser that just pulls out the score and ID. (It can also be None, which causes the raw response to be returned.) Does that make sense?

weisslj commented 12 years ago

Well, but that is not any different from just passing False to "parse" and calling a function (what I'm doing now). I think I don't get "parse_lookup_result" at all: Why does it return all results (even with low score), but not all recordings (only the first, even from a result with high score)?

sampsyo commented 12 years ago

Yep, not that different from writing your own "parser" to extract the results you want. Is there an API style you think would be better?

The idea behind the existing function is to make it easy to get a snapshot of the most relevant/useful information. It's a compromise between completeness and straightforwardness of the API, the idea being that if you want arbitrary information, you can process the parsed JSON object yourself. I'd be open to more flexible built in processing, though, because it can be kind of tricky to get the response-walking right.

weisslj commented 12 years ago

Hmm, I thought about it, but to be honest I can't come up with a better API... I thought of renaming "parse_lookup_result" to "get_recordings" (and introduce new "get_track_ids" etc.), but it doesn't make much sense either. The output of "match()" (the parsed JSON response) is actually good enough already, it doesn't really need to be parsed much further (besides maybe strip the status code).

So I will close the issue request, sorry for all the fuss :-).