Fixing issue with DBus Playlist interface
This commit is contained in:
@@ -218,8 +218,6 @@ class SublimeMusicApp(Gtk.Application):
|
||||
)
|
||||
self.player = self.mpv_player
|
||||
|
||||
self.player.volume = self.state.volume
|
||||
|
||||
if self.state.current_device != 'this device':
|
||||
# TODO figure out how to activate the chromecast if possible
|
||||
# without blocking the main thread. Also, need to make it obvious
|
||||
@@ -228,6 +226,9 @@ class SublimeMusicApp(Gtk.Application):
|
||||
|
||||
self.state.current_device = 'this device'
|
||||
|
||||
# Need to do this after we set the current device.
|
||||
self.player.volume = self.state.volume
|
||||
|
||||
# Prompt to load the play queue from the server.
|
||||
# TODO should this be behind sync enabled?
|
||||
if self.state.config.server.sync_enabled:
|
||||
@@ -260,7 +261,7 @@ class SublimeMusicApp(Gtk.Application):
|
||||
invocation,
|
||||
):
|
||||
second_microsecond_conversion = 1000000
|
||||
track_id_re = re.compile(r'/song/(.*)(?:/(.*))')
|
||||
track_id_re = re.compile(r'/song/(.*)(?:/(.*))?')
|
||||
playlist_id_re = re.compile(r'/playlist/(.*)')
|
||||
|
||||
def seek_fn(offset):
|
||||
@@ -288,6 +289,7 @@ class SublimeMusicApp(Gtk.Application):
|
||||
def get_track_metadata(track_ids):
|
||||
metadatas = []
|
||||
|
||||
# TODO fix
|
||||
song_details_futures = [
|
||||
CacheManager.get_song_details(track_id) for track_id in (
|
||||
track_id_re.match(tid).group(1) for tid in track_ids)
|
||||
|
@@ -191,17 +191,6 @@ class DBusManager:
|
||||
),
|
||||
)
|
||||
|
||||
seen_counts = defaultdict(int)
|
||||
tracks = []
|
||||
for song_id in state.play_queue:
|
||||
suffix = ''
|
||||
id_ = seen_counts.get(song_id)
|
||||
if id_ is not None:
|
||||
suffix = '/' + str(id_)
|
||||
|
||||
tracks.append(f'/song/{song_id}{suffix}')
|
||||
seen_counts[song_id] += 1
|
||||
|
||||
return {
|
||||
'org.mpris.MediaPlayer2': {
|
||||
'CanQuit': True,
|
||||
@@ -227,8 +216,10 @@ class DBusManager:
|
||||
'Shuffle':
|
||||
state.shuffle_on,
|
||||
'Metadata':
|
||||
self.get_mpris_metadata(state.current_song)
|
||||
if state.current_song else {},
|
||||
self.get_mpris_metadata(
|
||||
state.current_song_index,
|
||||
state.play_queue,
|
||||
) if state.current_song else {},
|
||||
'Volume':
|
||||
0.0 if state.is_muted else state.volume / 100,
|
||||
'Position': (
|
||||
@@ -255,7 +246,7 @@ class DBusManager:
|
||||
True,
|
||||
},
|
||||
'org.mpris.MediaPlayer2.TrackList': {
|
||||
'Tracks': tracks,
|
||||
'Tracks': self.get_dbus_playlist(state.play_queue),
|
||||
'CanEditTracks': False,
|
||||
},
|
||||
'org.mpris.MediaPlayer2.Playlists': {
|
||||
@@ -269,13 +260,15 @@ class DBusManager:
|
||||
},
|
||||
}
|
||||
|
||||
def get_mpris_metadata(self, song: Child):
|
||||
def get_mpris_metadata(self, idx: int, play_queue):
|
||||
song = CacheManager.get_song_details(play_queue[idx]).result
|
||||
trackid = self.get_dbus_playlist(play_queue)[idx]
|
||||
duration = (
|
||||
'x',
|
||||
(song.duration or 0) * self.second_microsecond_conversion,
|
||||
)
|
||||
return {
|
||||
'mpris:trackid': '/song/' + song.id,
|
||||
'mpris:trackid': trackid,
|
||||
'mpris:length': duration,
|
||||
'mpris:artUrl': CacheManager.get_cover_art_url(song.id, 1000),
|
||||
'xesam:album': song.album or '',
|
||||
@@ -284,6 +277,20 @@ class DBusManager:
|
||||
'xesam:title': song.title,
|
||||
}
|
||||
|
||||
def get_dbus_playlist(self, play_queue):
|
||||
seen_counts = defaultdict(int)
|
||||
tracks = []
|
||||
for song_id in play_queue:
|
||||
suffix = ''
|
||||
id_ = seen_counts.get(song_id)
|
||||
if id_ is not None:
|
||||
suffix = '/' + str(id_)
|
||||
|
||||
tracks.append(f'/song/{song_id}{suffix}')
|
||||
seen_counts[song_id] += 1
|
||||
|
||||
return tracks
|
||||
|
||||
diff_parse_re = re.compile(r"root\['(.*?)'\]\['(.*?)'\](?:\[.*\])?")
|
||||
|
||||
def property_diff(self):
|
||||
|
@@ -87,7 +87,7 @@ class Server:
|
||||
def _subsonic_error_to_exception(self, error) -> Exception:
|
||||
return Exception(f'{error.code}: {error.message}')
|
||||
|
||||
def _get(self, url, **params):
|
||||
def _get(self, url, timeout=(3.05, 2), **params):
|
||||
params = {**self._get_params(), **params}
|
||||
print(f'[START] get: {url}')
|
||||
|
||||
@@ -100,6 +100,7 @@ class Server:
|
||||
url,
|
||||
params=params,
|
||||
verify=not self.disable_cert_verify,
|
||||
timeout=timeout,
|
||||
)
|
||||
# TODO make better
|
||||
if result.status_code != 200:
|
||||
|
Reference in New Issue
Block a user