mirror of
https://github.com/vale981/clay
synced 2025-03-05 09:31:40 -05:00
Debug.
This commit is contained in:
parent
9170fa8e32
commit
37fcd42d5f
5 changed files with 85 additions and 68 deletions
28
clay/app.py
28
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'),
|
||||
]
|
||||
|
|
115
clay/gp.py
115
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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue