-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathalbums.py
More file actions
70 lines (56 loc) · 1.9 KB
/
albums.py
File metadata and controls
70 lines (56 loc) · 1.9 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from mopidy import models
from mopidy_beets.browsers import GenericBrowserBase
from mopidy_beets.translator import assemble_uri
class AlbumsCategoryBrowser(GenericBrowserBase):
field = None
sort_fields = None
label_fields = None
def get_toplevel(self):
keys = self.api.get_sorted_unique_album_attributes(self.field)
return [
models.Ref.directory(
name=key, uri=assemble_uri(self.ref.uri, id_value=key)
)
for key in keys
]
def get_directory(self, key):
albums = self.api.get_albums_by(
[(self.field, key)], True, self.sort_fields
)
return [
models.Ref.album(uri=album.uri, name=self._get_label(album))
for album in albums
]
class AlbumsByArtistBrowser(AlbumsCategoryBrowser):
field = "albumartist"
sort_fields = ("original_year+", "year+", "album+")
def _get_label(self, album):
return album.name
class AlbumsByGenreBrowser(AlbumsCategoryBrowser):
field = "genre"
sort_fields = ("albumartist", "original_year+", "year+", "album+")
def _get_label(self, album):
artists = " / ".join([artist.name for artist in album.artists])
if artists and album.date:
return "{0} - {1} ({2})".format(
artists, album.name, album.date.split("-")[0]
)
elif artists:
return "{0} - {1}".format(artists, album.name)
else:
return album.name
class AlbumsByYearBrowser(AlbumsCategoryBrowser):
field = "year"
sort_fields = (
"original_month+",
"original_day+",
"month+",
"day+",
"album+",
)
def _get_label(self, album):
artists = " / ".join([artist.name for artist in album.artists])
if artists:
return "{0} - {1}".format(artists, album.name)
else:
return album.name