-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathalbum_arts.py
30 lines (24 loc) · 1.08 KB
/
album_arts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from gi.repository import RB
NO_ALBUM = 'UnknownAlbum'
class AlbumArtManager(object):
def __init__(self):
self.storage = RB.ExtDB(name="album-art")
@staticmethod
def _gen_storage_key(album, artist):
key = RB.ExtDBKey.create_storage("album", album)
key.add_field("artist", artist)
return key
@staticmethod
def _gen_lookup_key(album, artist):
key = RB.ExtDBKey.create_lookup("album", album)
key.add_field("artist", artist)
return key
def ensure_art_exists(self, track, size: str = '200x200'):
artists = ', '.join(artist.name for artist in track.artists)
album_title = track.albums[0].title if track.albums else NO_ALBUM
lookup_key = self._gen_lookup_key(album_title, artists)
lookup_result = self.storage.lookup(lookup_key)[0]
if track.cover_uri and not lookup_result:
uri = f'https://{track.cover_uri.replace("%%", size)}'
storage_key = self._gen_storage_key(album_title, artists)
self.storage.store_uri(storage_key, RB.ExtDBSourceType.SEARCH, uri)