Did some cleanup of search when in browse by filesystem mode
This commit is contained in:
@@ -549,13 +549,23 @@ class SublimeMusicApp(Gtk.Application):
|
||||
self.update_window()
|
||||
|
||||
def on_go_to_album(self, action, album_id):
|
||||
# Switch to the By Year view to guarantee that the album is there.
|
||||
# Switch to the By Year view (or genre, if year is not available) to
|
||||
# guarantee that the album is there.
|
||||
album = CacheManager.get_album(album_id.get_string()).result()
|
||||
self.state.current_album_sort = 'byYear'
|
||||
self.state.current_album_from_year = album.year
|
||||
self.state.current_album_to_year = album.year
|
||||
self.state.selected_album_id = album_id.get_string()
|
||||
if album.get('year'):
|
||||
self.state.current_album_sort = 'byYear'
|
||||
self.state.current_album_from_year = album.year
|
||||
self.state.current_album_to_year = album.year
|
||||
elif album.get('genre'):
|
||||
self.state.current_album_sort = 'byGenre'
|
||||
self.state.current_album_genre = album.genre
|
||||
else:
|
||||
# TODO message?
|
||||
print(album)
|
||||
return
|
||||
|
||||
self.state.current_tab = 'albums'
|
||||
self.state.selected_album_id = album_id.get_string()
|
||||
self.update_window(force=True)
|
||||
|
||||
def on_go_to_artist(self, action, artist_id):
|
||||
|
@@ -482,8 +482,7 @@ class CacheManager(metaclass=Singleton):
|
||||
|
||||
# Playlists have the song details, so save those too.
|
||||
for song in (playlist.entry or []):
|
||||
self.cache['song_details'][song.id] = song
|
||||
self.cache['song_details_id3'][song.id] = song
|
||||
self.cache[self.id3ify('song_details')][song.id] = song
|
||||
|
||||
self.save_cache_info()
|
||||
|
||||
@@ -608,7 +607,7 @@ class CacheManager(metaclass=Singleton):
|
||||
force: bool = False,
|
||||
) -> 'CacheManager.Result[Optional[str]]':
|
||||
def do_get_artist_artwork(artist_info):
|
||||
lastfm_url = ''.join(artist_info.largeImageUrl)
|
||||
lastfm_url = ''.join(artist_info.largeImageUrl or [])
|
||||
|
||||
# If it is the placeholder LastFM image, try and use the cover
|
||||
# art filename given by the server.
|
||||
@@ -623,6 +622,9 @@ class CacheManager(metaclass=Singleton):
|
||||
return CacheManager.get_cover_art_filename(
|
||||
artist.child[0].coverArt, size=300)
|
||||
|
||||
if lastfm_url == '':
|
||||
return CacheManager.Result.from_data('')
|
||||
|
||||
url_hash = hashlib.md5(lastfm_url.encode('utf-8')).hexdigest()
|
||||
return self.return_cached_or_download(
|
||||
f'cover_art/artist.{url_hash}',
|
||||
@@ -730,9 +732,9 @@ class CacheManager(metaclass=Singleton):
|
||||
self.cache[cache_name][album_id] = album
|
||||
|
||||
# Albums have the song details as well, so save those too.
|
||||
for song in (album.song or []):
|
||||
self.cache['song_details'][song.id] = song
|
||||
self.cache['song_details_id3'][song.id] = song
|
||||
for song in (album.get('song') or album.get('child')
|
||||
or []):
|
||||
self.cache[self.id3ify('song_details')][song.id] = song
|
||||
self.save_cache_info()
|
||||
|
||||
return CacheManager.Result.from_server(
|
||||
@@ -940,8 +942,11 @@ class CacheManager(metaclass=Singleton):
|
||||
|
||||
for i, f in enumerate(as_completed(map(
|
||||
CacheManager.create_future, search_future_fns))):
|
||||
for member, result in f.result():
|
||||
search_result.add_results(member, result)
|
||||
try:
|
||||
for member, result in f.result():
|
||||
search_result.add_results(member, result)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
search_callback(
|
||||
search_result,
|
||||
|
@@ -161,6 +161,8 @@
|
||||
|
||||
#search-artwork {
|
||||
margin-right: 5px;
|
||||
min-width: 30px;
|
||||
min-height: 30px;
|
||||
}
|
||||
|
||||
/* ********** Artists & Albums ********** */
|
||||
|
@@ -27,6 +27,8 @@ class SpinnerImage(Gtk.Overlay):
|
||||
self.add_overlay(self.spinner)
|
||||
|
||||
def set_from_file(self, filename):
|
||||
if filename == '':
|
||||
filename = None
|
||||
if self.image_size is not None and filename:
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||
filename,
|
||||
|
@@ -76,6 +76,8 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
self.connect('button-release-event', self.on_button_release)
|
||||
|
||||
def update(self, state: ApplicationState, force=False):
|
||||
self.browse_by_tags = state.config.server.browse_by_tags
|
||||
|
||||
# Update the Connected to label on the popup menu.
|
||||
if state.config.current_server >= 0:
|
||||
server_name = state.config.servers[
|
||||
@@ -337,7 +339,7 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
widget.remove(c)
|
||||
|
||||
def create_search_result_row(
|
||||
self, text, action_name, value, artwork_future):
|
||||
self, text, action_name, value, artwork_future):
|
||||
row = Gtk.Button(relief=Gtk.ReliefStyle.NONE)
|
||||
row.connect(
|
||||
'button-press-event',
|
||||
@@ -370,9 +372,10 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
)
|
||||
cover_art_future = CacheManager.get_cover_art_filename(
|
||||
song.coverArt, size=50)
|
||||
album_id = song.albumId if self.browse_by_tags else song.parent
|
||||
self.song_results.add(
|
||||
self.create_search_result_row(
|
||||
label_text, 'album', song.albumId, cover_art_future))
|
||||
label_text, 'album', album_id, cover_art_future))
|
||||
|
||||
self.song_results.show_all()
|
||||
|
||||
|
@@ -117,14 +117,14 @@ def diff_model_store(store_to_edit, new_store):
|
||||
|
||||
|
||||
def show_song_popover(
|
||||
song_ids,
|
||||
x: int,
|
||||
y: int,
|
||||
relative_to: Any,
|
||||
position: Gtk.PositionType = Gtk.PositionType.BOTTOM,
|
||||
on_download_state_change: Callable[[int], None] = lambda x: None,
|
||||
show_remove_from_playlist_button: bool = False,
|
||||
extra_menu_items: List[Tuple[Gtk.ModelButton, Any]] = [],
|
||||
song_ids,
|
||||
x: int,
|
||||
y: int,
|
||||
relative_to: Any,
|
||||
position: Gtk.PositionType = Gtk.PositionType.BOTTOM,
|
||||
on_download_state_change: Callable[[int], None] = lambda x: None,
|
||||
show_remove_from_playlist_button: bool = False,
|
||||
extra_menu_items: List[Tuple[Gtk.ModelButton, Any]] = [],
|
||||
):
|
||||
def on_download_songs_click(button):
|
||||
CacheManager.batch_download_songs(
|
||||
@@ -192,31 +192,38 @@ def show_song_popover(
|
||||
action_name='app.add-to-queue',
|
||||
action_target=GLib.Variant('as', song_ids),
|
||||
),
|
||||
Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL),
|
||||
go_to_album_button,
|
||||
go_to_artist_button,
|
||||
Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL),
|
||||
(
|
||||
Gtk.ModelButton(
|
||||
text=f"Download {pluralize('song', song_count)}",
|
||||
sensitive=download_sensitive,
|
||||
),
|
||||
on_download_songs_click,
|
||||
),
|
||||
(
|
||||
Gtk.ModelButton(
|
||||
text=f"Remove {pluralize('download', song_count)}",
|
||||
sensitive=remove_download_sensitive,
|
||||
),
|
||||
on_remove_downloads_click,
|
||||
),
|
||||
Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL),
|
||||
Gtk.ModelButton(
|
||||
text=f"Add {pluralize('song', song_count)} to playlist",
|
||||
menu_name='add-to-playlist',
|
||||
),
|
||||
*extra_menu_items,
|
||||
]
|
||||
if CacheManager.browse_by_tags:
|
||||
menu_items.extend(
|
||||
[
|
||||
Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL),
|
||||
go_to_album_button,
|
||||
go_to_artist_button,
|
||||
])
|
||||
menu_items.extend(
|
||||
[
|
||||
Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL),
|
||||
(
|
||||
Gtk.ModelButton(
|
||||
text=f"Download {pluralize('song', song_count)}",
|
||||
sensitive=download_sensitive,
|
||||
),
|
||||
on_download_songs_click,
|
||||
),
|
||||
(
|
||||
Gtk.ModelButton(
|
||||
text=f"Remove {pluralize('download', song_count)}",
|
||||
sensitive=remove_download_sensitive,
|
||||
),
|
||||
on_remove_downloads_click,
|
||||
),
|
||||
Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL),
|
||||
Gtk.ModelButton(
|
||||
text=f"Add {pluralize('song', song_count)} to playlist",
|
||||
menu_name='add-to-playlist',
|
||||
),
|
||||
*extra_menu_items,
|
||||
])
|
||||
|
||||
for item in menu_items:
|
||||
if type(item) == tuple:
|
||||
@@ -263,9 +270,9 @@ def show_song_popover(
|
||||
|
||||
|
||||
def async_callback(
|
||||
future_fn,
|
||||
before_download=None,
|
||||
on_failure=None,
|
||||
future_fn,
|
||||
before_download=None,
|
||||
on_failure=None,
|
||||
):
|
||||
"""
|
||||
Defines the ``async_callback`` decorator.
|
||||
|
Reference in New Issue
Block a user