thedonvaughn / cover_grabber

Recursively traverse directory containing media files (MP3, ogg, FLAC) and download album cover art
https://sourceforge.net/projects/covergrabber/
GNU General Public License v3.0
17 stars 8 forks source link

XML namespace error on LastFM-API #6

Open joernroeder opened 8 years ago

joernroeder commented 8 years ago

I've got the following error on the LastFM API: Errors in file xml-schema: The prefix "opensearch" for element "opensearch:Query" is not bound. https://ws.audioscrobbler.com/2.0/?method=album.search&album=Foobar&api_key=a42ead6d2dcc2938bec2cda08a03b519 _The link is equal to LASTFM_URL_

After looking at the source i've removed the outer xml elements (including the namespaced <query> element) which aren't used by the parser.

# /cover_grabber/downloader/lastfm_downloader.py#L44
response = urllib.urlopen(self.url).read() # Send HTTP request to LastFM

# removing invalid formatted wrapper xml.
start_index = response.index("<albummatches>")
end_index = response.index("</albummatches>") + len("</albummatches>")
response = response[start_index:end_index]

xml_data = ETree.fromstring(response) # Read in XML data

Now the stripped response is passed to the xml parser and everything works again. I could submit a pull request – Just let me know.

:ghost: