[Closes #5] Scrobble plays to server when playing cached versions

This commit is contained in:
Sumner Evans
2019-08-31 20:38:22 -06:00
parent 0e2dabbb71
commit 6e0ef1b1b8
3 changed files with 17 additions and 6 deletions

View File

@@ -283,7 +283,7 @@ class LibremsonicApp(Gtk.Application):
def reset_cache_manager(self):
CacheManager.reset(
self.state.config,
self.state.config.servers[self.state.config.current_server]
self.current_server
if self.state.config.current_server >= 0 else None,
)
@@ -387,6 +387,11 @@ class LibremsonicApp(Gtk.Application):
self.save_play_queue()
CacheManager.shutdown()
# ########## PROPERTIES ########## #
@property
def current_server(self):
return self.state.config.servers[self.state.config.current_server]
# ########## HELPER METHODS ########## #
def show_configure_servers_dialog(self):
"""Show the Connect to Server dialog."""
@@ -501,6 +506,9 @@ class LibremsonicApp(Gtk.Application):
self.update_window),
)
if self.current_server.sync_enabled:
CacheManager.scrobble(song.id)
song_details_future = CacheManager.get_song_details(song)
song_details_future.add_done_callback(
lambda f: GLib.idle_add(do_play_song, f.result()), )
@@ -509,10 +517,7 @@ class LibremsonicApp(Gtk.Application):
position = self.state.song_progress
self.last_play_queue_update = position
current_server = self.state.config.current_server
current_server = self.state.config.servers[current_server]
if current_server.sync_enabled:
if self.current_server.sync_enabled:
CacheManager.executor.submit(
CacheManager.save_play_queue,
id=self.state.play_queue,

View File

@@ -570,6 +570,12 @@ class CacheManager(metaclass=Singleton):
def get_play_queue(self) -> Future:
return CacheManager.executor.submit(self.server.get_play_queue)
def scrobble(self, song_id: int) -> Future:
def do_scrobble():
self.server.scrobble(song_id)
return CacheManager.executor.submit(do_scrobble)
def get_song_filename_or_stream(
self,
song: Child,

View File

@@ -66,7 +66,7 @@ class EditServerDialog(EditFormDialog):
)
dialog.format_secondary_markup(
f'Connection to {server_address} resulted in the following '
'error:\n\n{err}')
f'error:\n\n{err}')
dialog.run()
dialog.destroy()