From 37fcd42d5f495efa8ac4f7f82313f65785ccdd9e Mon Sep 17 00:00:00 2001 From: Andrew Dunai Date: Tue, 30 Jan 2018 11:41:31 +0200 Subject: [PATCH] Debug. --- clay/app.py | 28 +++++----- clay/gp.py | 115 ++++++++++++++++++++++------------------- clay/pages/settings.py | 2 +- clay/playbar.py | 6 ++- clay/songlist.py | 2 +- 5 files changed, 85 insertions(+), 68 deletions(-) diff --git a/clay/app.py b/clay/app.py index 303e4f1..f689353 100755 --- a/clay/app.py +++ b/clay/app.py @@ -22,8 +22,12 @@ from clay.settings import Settings from clay.notifications import NotificationArea from clay.gp import GP +BG = '#222' + PALETTE = [ - ('logo', '', '', '', '#F54', ''), + (None, '', '', '', '#FFF', BG), + ('default', '', '', '', '#FFF', BG), + ('logo', '', '', '', '#F54', BG), ('bg', '', '', '', '#FFF', '#222'), ('primary', '', '', '', '#F54', '#FFF'), @@ -34,30 +38,30 @@ PALETTE = [ ('progress', '', '', '', '#FFF', '#F54'), ('progress_remaining', '', '', '', '#FFF', '#444'), - ('progressbar_done', '', '', '', '#F54', ''), - ('progressbar_done_paused', '', '', '', '', ''), - ('progressbar_remaining', '', '', '', '#222', ''), + ('progressbar_done', '', '', '', '#F54', BG), + ('progressbar_done_paused', '', '', '', '', BG), + ('progressbar_remaining', '', '', '', '#222', BG), - ('title-idle', '', '', '', '', ''), - ('title-playing', '', '', '', '#F54', ''), + ('title-idle', '', '', '', '', BG), + ('title-playing', '', '', '', '#F54', BG), ('panel', '', '', '', '#FFF', '#222'), ('panel_focus', '', '', '', '#FFF', '#F54'), ('panel_divider', '', '', '', '#444', '#222'), ('panel_divider_focus', '', '', '', '#444', '#F54'), - ('line1', '', '', '', '#FFF', ''), + ('line1', '', '', '', '#FFF', BG), ('line1_focus', '', '', '', '#FFF', '#333'), - ('line1_active', '', '', '', '#F54', ''), + ('line1_active', '', '', '', '#F54', BG), ('line1_active_focus', '', '', '', '#F54', '#333'), - ('line2', '', '', '', '#AAA', ''), - ('line2_focus', '', '', '', '#AAA', '#333'), + ('line2', '', '', '', '#AAA,italics', BG), + ('line2_focus', '', '', '', '#AAA,italics', '#333'), ('input', '', '', '', '#FFF', '#444'), ('input_focus', '', '', '', '#FFF', '#F54'), - ('flag', '', '', '', '#AAA', ''), - ('flag-active', '', '', '', '#F54', ''), + ('flag', '', '', '', '#AAA', BG), + ('flag-active', '', '', '', '#F54', BG), ('notification', '', '', '', '#F54', '#222'), ] diff --git a/clay/gp.py b/clay/gp.py index 284d255..f258e29 100644 --- a/clay/gp.py +++ b/clay/gp.py @@ -126,68 +126,77 @@ class Track(object): if many: return [cls.from_data(one, source) for one in data] - if source == Track.SOURCE_SEARCH: - # Data contains a nested track representation. - return Track( - title=data['track']['title'], - artist=data['track']['artist'], - duration=int(data['track']['durationMillis']), - source=source, - store_id=data['track']['storeId'], # or data['trackId'] - album_name=data['track']['album'], - album_url=data['track']['albumArtRef'][0]['url'] - ) - elif source == Track.SOURCE_STATION: - # Station tracks have all the info in place. - return Track( - title=data['title'], - artist=data['artist'], - duration=int(data['durationMillis']), - source=source, - store_id=data['storeId'], - album_name=data['album'], - album_url=data['albumArtRef'][0]['url'] - ) - elif source == Track.SOURCE_LIBRARY: - # Data contains all info about track - # including ID in library and ID in store. - UUID(data['id']) - return Track( - title=data['title'], - artist=data['artist'], - duration=int(data['durationMillis']), - source=source, - store_id=data['storeId'], - library_id=data['id'], - album_name=data['album'], - album_url=data['albumArtRef'][0]['url'] - ) - elif source == Track.SOURCE_PLAYLIST: - if 'track' in data: - # Data contains a nested track representation that can be used - # to construct new track. + try: + if source == Track.SOURCE_SEARCH: + # Data contains a nested track representation. return Track( title=data['track']['title'], artist=data['track']['artist'], duration=int(data['track']['durationMillis']), source=source, store_id=data['track']['storeId'], # or data['trackId'] - playlist_item_id=data['id'], album_name=data['track']['album'], album_url=data['track']['albumArtRef'][0]['url'] ) - # We need to find a track in Library by trackId. - UUID(data['trackId']) - track = GP.get().get_track_by_id(data['trackId']) - return Track( - title=track.title, - artist=track.artist, - duration=track.duration, - source=source, - store_id=track.store_id, - album_name=track.album_name, - album_url=track.album_url - ) + elif source == Track.SOURCE_STATION: + # Station tracks have all the info in place. + return Track( + title=data['title'], + artist=data['artist'], + duration=int(data['durationMillis']), + source=source, + store_id=data['storeId'], + album_name=data['album'], + album_url=data['albumArtRef'][0]['url'] + ) + elif source == Track.SOURCE_LIBRARY: + # Data contains all info about track + # including ID in library and ID in store. + UUID(data['id']) + return Track( + title=data['title'], + artist=data['artist'], + duration=int(data['durationMillis']), + source=source, + store_id=data['storeIda'], + library_id=data['id'], + album_name=data['album'], + album_url=data['albumArtRef'][0]['url'] + ) + elif source == Track.SOURCE_PLAYLIST: + if 'track' in data: + # Data contains a nested track representation that can be used + # to construct new track. + return Track( + title=data['track']['title'], + artist=data['track']['artist'], + duration=int(data['track']['durationMillis']), + source=source, + store_id=data['track']['storeId'], # or data['trackId'] + playlist_item_id=data['id'], + album_name=data['track']['album'], + album_url=data['track']['albumArtRef'][0]['url'] + ) + # We need to find a track in Library by trackId. + UUID(data['trackId']) + track = GP.get().get_track_by_id(data['trackId']) + return Track( + title=track.title, + artist=track.artist, + duration=track.duration, + source=source, + store_id=track.store_id, + album_name=track.album_name, + album_url=track.album_url + ) + except Exception as e: # pylint: disable=bare-except + print('Failed to create track from data.') + print('Failing payload was:') + print(data) + raise Exception('Failed to create track from data. Original error: {}. Payload: {}'.format( + str(e), + data + )) raise AssertionError() def get_url(self, callback): diff --git a/clay/pages/settings.py b/clay/pages/settings.py index 022e011..ae97758 100644 --- a/clay/pages/settings.py +++ b/clay/pages/settings.py @@ -71,7 +71,7 @@ class Slider(urwid.Widget): rows.append(self.freq_str) text = urwid.AttrMap(urwid.Text('\n'.join( rows - ), align=urwid.CENTER), '', 'panel_focus') + ), align=urwid.CENTER), 'default', 'panel_focus') return text.render(size, focus) def keypress(self, _, key): diff --git a/clay/playbar.py b/clay/playbar.py index 111687e..89387ef 100644 --- a/clay/playbar.py +++ b/clay/playbar.py @@ -5,6 +5,7 @@ PlayBar widget. import urwid from clay.player import Player +from clay import meta class ProgressBar(urwid.Widget): @@ -126,7 +127,10 @@ class PlayBar(urwid.Pile): player = Player.get() track = player.get_current_track() if track is None: - return u'Idle' + return u'{} {}'.format( + meta.APP_NAME, + meta.VERSION + ) progress = player.get_play_progress_seconds() total = player.get_length_seconds() return (self.get_style(), u' {} {} - {} [{:02d}:{:02d} / {:02d}:{:02d}]'.format( diff --git a/clay/songlist.py b/clay/songlist.py index 8361ab5..a9a2973 100644 --- a/clay/songlist.py +++ b/clay/songlist.py @@ -106,7 +106,7 @@ class SongListItem(urwid.Pile): ) ) self.line2.set_text( - u' {} ({})'.format(self.track.artist, self.track.album_name) + u' {} \u2015 {}'.format(self.track.artist, self.track.album_name) ) self.line1_wrap.set_attr(title_attr) self.line2_wrap.set_attr(artist_attr)