Support “albumart” command (close #30)
Load the album covers using MPD’s new “albumart” command instead of reading the covers from the harddrive. Remove the corresponding UI elements and configuration option.
This commit is contained in:
parent
c53681ea82
commit
bb8b816e8f
5 changed files with 266 additions and 230 deletions
46
mcg/utils.py
46
mcg/utils.py
|
|
@ -14,45 +14,31 @@ from gi.repository import GdkPixbuf
|
|||
|
||||
|
||||
class Utils:
|
||||
def load_cover(url):
|
||||
if not url:
|
||||
return None
|
||||
if url.startswith('/'):
|
||||
try:
|
||||
return GdkPixbuf.Pixbuf.new_from_file(url)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return None
|
||||
else:
|
||||
try:
|
||||
response = urllib.request.urlopen(url)
|
||||
loader = GdkPixbuf.PixbufLoader()
|
||||
loader.write(response.read())
|
||||
loader.close()
|
||||
return loader.get_pixbuf()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return None
|
||||
|
||||
|
||||
def load_thumbnail(cache, album, size):
|
||||
def load_pixbuf(data):
|
||||
loader = GdkPixbuf.PixbufLoader()
|
||||
try:
|
||||
loader.write(data)
|
||||
finally:
|
||||
loader.close()
|
||||
return loader.get_pixbuf()
|
||||
|
||||
|
||||
def load_thumbnail(cache, client, album, size):
|
||||
cache_url = cache.create_filename(album)
|
||||
pixbuf = None
|
||||
|
||||
if os.path.isfile(cache_url):
|
||||
try:
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file(cache_url)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file(cache_url)
|
||||
else:
|
||||
url = album.get_cover()
|
||||
pixbuf = Utils.load_cover(url)
|
||||
# Load cover from server
|
||||
albumart = client.get_albumart_now(album.get_id())
|
||||
if albumart:
|
||||
pixbuf = Utils.load_pixbuf(albumart)
|
||||
if pixbuf is not None:
|
||||
pixbuf = pixbuf.scale_simple(size, size, GdkPixbuf.InterpType.HYPER)
|
||||
filetype = os.path.splitext(url)[1][1:]
|
||||
if filetype == 'jpg':
|
||||
filetype = 'jpeg'
|
||||
pixbuf.savev(cache.create_filename(album), filetype, [], [])
|
||||
pixbuf.savev(cache_url, 'jpeg', [], [])
|
||||
return pixbuf
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue