Skip to content
Snippets Groups Projects
Commit fe6c8c0f authored by ale's avatar ale
Browse files

in the album art cache, when the album name ends with a number, try

querying last.fm again without the number at the end
parent d9f5497c
Branches
No related tags found
No related merge requests found
import hashlib import hashlib
import os import os
import re
import subprocess import subprocess
import urllib import urllib
import urllib2 import urllib2
...@@ -12,6 +13,12 @@ class AlbumImageDiskCache(object): ...@@ -12,6 +13,12 @@ class AlbumImageDiskCache(object):
Files are saved and converted to JPEG using Imagemagick. Negative Files are saved and converted to JPEG using Imagemagick. Negative
matches are saved as empty files. matches are saved as empty files.
If you want to periodically retry 'missed' entries (to recover from
temporary errors, for example), you can simply run:
find $DIR -type f -size 0 -mtime +$DAYS -exec rm -f \{\} +
""" """
def __init__(self, root): def __init__(self, root):
...@@ -61,16 +68,25 @@ class AlbumImageRetriever(object): ...@@ -61,16 +68,25 @@ class AlbumImageRetriever(object):
def get_album_image(self, artist, album): def get_album_image(self, artist, album):
if not self.cache.has(artist, album): if not self.cache.has(artist, album):
try: queries = [(artist, album)]
xml = self._get_album_info(artist, album) # Fix a minor annoyance that is popular in ID3 tags: if the
xp = etree.XPath('album/image[@size="extralarge"]') # album name ends in a number, it might be part of a series;
img = xp(xml) # in that case, try again without the number.
if img: m = re.search(r'^(.+) \d+$', album)
self.cache.download(artist, album, img[0].text) if m:
else: queries.append((artist, m.group(1)))
self.cache.set_negative_match(artist, album) for query_artist, query_album in queries:
except: try:
return None xml = self._get_album_info(query_artist, query_album)
xp = etree.XPath('album/image[@size="extralarge"]')
img = xp(xml)
if img:
self.cache.download(artist, album, img[0].text)
else:
self.cache.set_negative_match(artist, album)
except:
continue
break
return self.cache.get(artist, album) return self.cache.get(artist, album)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment