slightly improved cover loading (#39)

This commit is contained in:
Martin Wagner 2021-07-25 18:22:37 +02:00
parent f0789d7170
commit 968158dede

View File

@ -505,7 +505,7 @@ class ClientHelper():
"date": "", "date": "",
"genre": "" "genre": ""
} }
if "range" in song: # translate .cue 'range' to 'duration' if needed if "range" in song: # translate .cue 'range' to 'duration' if needed (unneeded since MPD 0.22.4)
start, end=song["range"].split("-") start, end=song["range"].split("-")
if start != "" and end != "": if start != "" and end != "":
base_song["duration"]=str((float(end)-float(start))) base_song["duration"]=str((float(end)-float(start)))
@ -787,6 +787,7 @@ class Client(MPDClient):
return None return None
def get_albums(self, artist, genre): def get_albums(self, artist, genre):
self.tagtypes("clear")
albums=[] albums=[]
artist_type=self._settings.get_artist_type() artist_type=self._settings.get_artist_type()
if genre is None: if genre is None:
@ -797,16 +798,21 @@ class Client(MPDClient):
for album in album_candidates: for album in album_candidates:
years=self.comp_list("date", "album", album, artist_type, artist, *genre_filter) years=self.comp_list("date", "album", album, artist_type, artist, *genre_filter)
for year in years: for year in years:
songs=self.find("album", album, "date", year, artist_type, artist, *genre_filter) count=self.count(artist_type, artist, "album", album, "date", year, *genre_filter)
cover_path=self.get_cover_path(songs[0]) song=self.find("album", album, "date", year, artist_type, artist, *genre_filter, "window", "0:1")[0]
cover_path=self.get_cover_path(song)
if cover_path is None: if cover_path is None:
cover_binary=self.get_cover_binary(songs[0].get("file")) cover_binary=self.get_cover_binary(song.get("file"))
if cover_binary is None: if cover_binary is None:
albums.append({"artist": artist, "album": album, "year": year, "songs": songs}) albums.append({"artist": artist,"album": album,"year": year,
"length": count["songs"],"duration": count["playtime"]})
else: else:
albums.append({"artist":artist,"album":album,"year":year,"songs":songs,"cover_binary":cover_binary}) albums.append({"artist": artist,"album": album,"year": year,
"length": count["songs"],"duration": count["playtime"],"cover_binary": cover_binary})
else: else:
albums.append({"artist": artist, "album": album, "year": year, "songs": songs, "cover_path": cover_path}) albums.append({"artist": artist,"album": album,"year": year,
"length": count["songs"],"duration": count["playtime"], "cover_path": cover_path})
self.tagtypes("all")
return albums return albums
def toggle_play(self): def toggle_play(self):
@ -2248,8 +2254,8 @@ class AlbumWindow(FocusFrame):
self._done=True self._done=True
self._pending=[] self._pending=[]
# cover, display_label, display_label_artist, tooltip(titles), album, year, artist # cover, display_label, display_label_artist, tooltip(titles), album, year, artist, index
self._store=Gtk.ListStore(GdkPixbuf.Pixbuf, str, str, str, str, str, str) self._store=Gtk.ListStore(GdkPixbuf.Pixbuf, str, str, str, str, str, str, int)
self._sort_settings() self._sort_settings()
# iconview # iconview
@ -2368,21 +2374,13 @@ class AlbumWindow(FocusFrame):
except MPDBase.ConnectionError: except MPDBase.ConnectionError:
self._done_callback() self._done_callback()
return return
# temporarily display all albums with fallback cover
def display_albums(): size=self._settings.get_int("album-cover")
fallback_cover=GdkPixbuf.Pixbuf.new_from_file_at_size(FALLBACK_COVER, size, size)
for i, album in enumerate(albums): for i, album in enumerate(albums):
# tooltip # tooltip
duration=ClientHelper.calc_display_duration(album["songs"]) duration=ClientHelper.seconds_to_display_time(int(album["duration"]))
length=len(album["songs"]) length=int(album["length"])
discs=album["songs"][-1].get("disc", 1)
if isinstance(discs, list):
discs=int(discs[0])
else:
discs=int(discs)
if discs > 1:
tooltip=_("{number} songs on {discs} discs ({duration})").format(
number=length, discs=discs, duration=duration)
else:
tooltip=ngettext("{number} song ({duration})", "{number} songs ({duration})", length).format( tooltip=ngettext("{number} song ({duration})", "{number} songs ({duration})", length).format(
number=length, duration=duration) number=length, duration=duration)
# album label # album label
@ -2395,31 +2393,31 @@ class AlbumWindow(FocusFrame):
display_label_artist=display_label_artist.replace("&", "&") display_label_artist=display_label_artist.replace("&", "&")
# add album # add album
self._store.append( self._store.append(
[album["cover"], display_label, display_label_artist, [fallback_cover, display_label, display_label_artist,
tooltip, album["album"], album["year"], album["artist"]] tooltip, album["album"], album["year"], album["artist"], i]
) )
self._iconview.set_model(self._store) self._iconview.set_model(self._store)
self._done_callback()
return False
def render_covers(): def render_covers():
def set_cover(row, cover):
row[0]=cover
size=self._settings.get_int("album-cover") size=self._settings.get_int("album-cover")
fallback_cover=GdkPixbuf.Pixbuf.new_from_file_at_size(FALLBACK_COVER, size, size)
total_albums=len(albums) total_albums=len(albums)
for i, album in enumerate(albums): for i, row in enumerate(self._store):
album=albums[row[7]]
if self._stop_flag: if self._stop_flag:
break break
if "cover_path" in album: if "cover_path" in album:
album["cover"]=ClientHelper.file_to_pixbuf(album["cover_path"], size) cover=ClientHelper.file_to_pixbuf(album["cover_path"], size)
else: else:
if "cover_binary" in album: if "cover_binary" in album:
album["cover"]=ClientHelper.binary_to_pixbuf(album["cover_binary"], size) cover=ClientHelper.binary_to_pixbuf(album["cover_binary"], size)
else: else:
album["cover"]=GdkPixbuf.Pixbuf.new_from_file_at_size(FALLBACK_COVER, size, size) cover=fallback_cover
GLib.idle_add(set_cover, row, cover)
GLib.idle_add(self._progress_bar.set_fraction, (i+1)/total_albums) GLib.idle_add(self._progress_bar.set_fraction, (i+1)/total_albums)
if self._stop_flag:
GLib.idle_add(self._done_callback) GLib.idle_add(self._done_callback)
else:
GLib.idle_add(display_albums)
cover_thread=threading.Thread(target=render_covers, daemon=True) cover_thread=threading.Thread(target=render_covers, daemon=True)
cover_thread.start() cover_thread.start()