mirror of
https://github.com/vale981/clay
synced 2025-03-05 09:31:40 -05:00
Auto start songs; Unicode config option; Rating icons
This commit is contained in:
parent
0fc0d0ae79
commit
78a297e279
4 changed files with 48 additions and 11 deletions
|
@ -21,10 +21,11 @@ hotkeys:
|
||||||
handle_escape: esc, mod + _
|
handle_escape: esc, mod + _
|
||||||
|
|
||||||
library_item:
|
library_item:
|
||||||
play: enter
|
activate: enter
|
||||||
|
play: mod + p
|
||||||
append: mod + a
|
append: mod + a
|
||||||
unappend: mod + u
|
unappend: mod + u
|
||||||
request_station: mod + p
|
request_station: meta + s
|
||||||
show_context_menu: meta + p
|
show_context_menu: meta + p
|
||||||
thumbs_up: meta + u
|
thumbs_up: meta + u
|
||||||
thumbs_down: meta + d
|
thumbs_down: meta + d
|
||||||
|
@ -51,6 +52,7 @@ hotkeys:
|
||||||
|
|
||||||
clay_settings:
|
clay_settings:
|
||||||
x_keybinds: false
|
x_keybinds: false
|
||||||
|
unicode: true
|
||||||
|
|
||||||
play_settings:
|
play_settings:
|
||||||
authtoken:
|
authtoken:
|
||||||
|
|
|
@ -5,6 +5,7 @@ PlayBar widget.
|
||||||
import urwid
|
import urwid
|
||||||
|
|
||||||
from clay.player import player
|
from clay.player import player
|
||||||
|
from clay.settings import settings
|
||||||
from clay import meta
|
from clay import meta
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,8 +72,11 @@ class PlayBar(urwid.Pile):
|
||||||
"""
|
"""
|
||||||
A widget that shows currently played track, playback progress and flags.
|
A widget that shows currently played track, playback progress and flags.
|
||||||
"""
|
"""
|
||||||
|
_unicode = settings.get('unicode', 'clay_settings')
|
||||||
ROTATING = u'|' u'/' u'\u2014' u'\\'
|
ROTATING = u'|' u'/' u'\u2014' u'\\'
|
||||||
|
RATING_ICONS = {0: ' ',
|
||||||
|
1: u'\U0001F593' if _unicode else '-',
|
||||||
|
5: u'\U0001F592' if _unicode else '+'}
|
||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
# super(PlayBar, self).__init__(*args, **kwargs)
|
# super(PlayBar, self).__init__(*args, **kwargs)
|
||||||
|
@ -130,7 +134,7 @@ class PlayBar(urwid.Pile):
|
||||||
)
|
)
|
||||||
progress = player.get_play_progress_seconds()
|
progress = player.get_play_progress_seconds()
|
||||||
total = player.get_length_seconds()
|
total = player.get_length_seconds()
|
||||||
return (self.get_style(), u' {} {} - {} [{:02d}:{:02d} / {:02d}:{:02d}]'.format(
|
return (self.get_style(), u' {} {} - {} {} [{:02d}:{:02d} / {:02d}:{:02d}]'.format(
|
||||||
# u'|>' if player.is_playing else u'||',
|
# u'|>' if player.is_playing else u'||',
|
||||||
# self.get_rotating_bar(),
|
# self.get_rotating_bar(),
|
||||||
u'\u2505' if player.is_loading
|
u'\u2505' if player.is_loading
|
||||||
|
@ -138,6 +142,7 @@ class PlayBar(urwid.Pile):
|
||||||
else u'\u25A0',
|
else u'\u25A0',
|
||||||
track.artist,
|
track.artist,
|
||||||
track.title,
|
track.title,
|
||||||
|
self.RATING_ICONS[track.rating],
|
||||||
progress // 60,
|
progress // 60,
|
||||||
progress % 60,
|
progress % 60,
|
||||||
total // 60,
|
total // 60,
|
||||||
|
|
|
@ -144,7 +144,6 @@ class _Settings(object):
|
||||||
except (KeyError, TypeError):
|
except (KeyError, TypeError):
|
||||||
return self._get_section(self._default_config, *sections)
|
return self._get_section(self._default_config, *sections)
|
||||||
|
|
||||||
|
|
||||||
def get_default_config_section(self, *sections):
|
def get_default_config_section(self, *sections):
|
||||||
"""
|
"""
|
||||||
Always get a section from the default/system configuration. You would use this whenever
|
Always get a section from the default/system configuration. You would use this whenever
|
||||||
|
|
|
@ -24,8 +24,10 @@ class SongListItem(urwid.Pile):
|
||||||
"""
|
"""
|
||||||
Widget that represents single song item.
|
Widget that represents single song item.
|
||||||
"""
|
"""
|
||||||
|
_unicode = settings.get('unicode', 'clay_settings')
|
||||||
signals = [
|
signals = [
|
||||||
'activate',
|
'activate',
|
||||||
|
'play',
|
||||||
'append-requested',
|
'append-requested',
|
||||||
'unappend-requested',
|
'unappend-requested',
|
||||||
'station-requested',
|
'station-requested',
|
||||||
|
@ -57,8 +59,13 @@ class SongListItem(urwid.Pile):
|
||||||
3: u'\u25A0'
|
3: u'\u25A0'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RATING_ICONS = {0: ' ',
|
||||||
|
1: u'\U0001F593' if _unicode else '-',
|
||||||
|
5: u'\U0001F592' if _unicode else '+'}
|
||||||
|
|
||||||
def __init__(self, track):
|
def __init__(self, track):
|
||||||
self.track = track
|
self.track = track
|
||||||
|
self.rating = self.RATING_ICONS[track.rating]
|
||||||
self.index = 0
|
self.index = 0
|
||||||
self.state = SongListItem.STATE_IDLE
|
self.state = SongListItem.STATE_IDLE
|
||||||
self.line1_left = urwid.SelectableIcon('', cursor_position=1000)
|
self.line1_left = urwid.SelectableIcon('', cursor_position=1000)
|
||||||
|
@ -107,7 +114,6 @@ class SongListItem(urwid.Pile):
|
||||||
"""
|
"""
|
||||||
return SongListItem.STATE_ICONS[state]
|
return SongListItem.STATE_ICONS[state]
|
||||||
|
|
||||||
|
|
||||||
def update_text(self):
|
def update_text(self):
|
||||||
"""
|
"""
|
||||||
Update text of this item from the attached track.
|
Update text of this item from the attached track.
|
||||||
|
@ -118,13 +124,16 @@ class SongListItem(urwid.Pile):
|
||||||
icon=self.get_state_icon(self.state),
|
icon=self.get_state_icon(self.state),
|
||||||
title=self.track.title,
|
title=self.track.title,
|
||||||
minutes=self.track.duration // (1000 * 60),
|
minutes=self.track.duration // (1000 * 60),
|
||||||
seconds=(self.track.duration // 1000) % 60
|
seconds=(self.track.duration // 1000) % 60,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if settings.get_is_file_cached(self.track.filename):
|
if settings.get_is_file_cached(self.track.filename):
|
||||||
self.line1_right.set_text(u' \u25bc Cached')
|
self.line1_right.set_text(u' \u25bc Cached')
|
||||||
else:
|
else:
|
||||||
self.line1_right.set_text(u'')
|
self.line1_right.set_text(u'')
|
||||||
|
|
||||||
|
self.line1_right.set_text(u'{rating}'.format(rating=self.rating))
|
||||||
self.line2.set_text(
|
self.line2.set_text(
|
||||||
u' {} \u2015 {}'.format(self.track.artist, self.track.album_name)
|
u' {} \u2015 {}'.format(self.track.artist, self.track.album_name)
|
||||||
)
|
)
|
||||||
|
@ -136,9 +145,10 @@ class SongListItem(urwid.Pile):
|
||||||
"""
|
"""
|
||||||
Return song artist and title.
|
Return song artist and title.
|
||||||
"""
|
"""
|
||||||
return u'{} - {}'.format(
|
return u'{} - {} {}'.format(
|
||||||
self.track.artist,
|
self.track.artist,
|
||||||
self.track.title
|
self.track.title,
|
||||||
|
self.rating
|
||||||
)
|
)
|
||||||
|
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
|
@ -158,27 +168,37 @@ class SongListItem(urwid.Pile):
|
||||||
|
|
||||||
def thumbs_up(self):
|
def thumbs_up(self):
|
||||||
"""
|
"""
|
||||||
Toggle the thumbs up of this song.
|
Thumb the currently selected song up.
|
||||||
"""
|
"""
|
||||||
self.track.rate_song((0 if self.track.rating == 5 else 5))
|
self.track.rate_song((0 if self.track.rating == 5 else 5))
|
||||||
|
|
||||||
def thumbs_down(self):
|
def thumbs_down(self):
|
||||||
|
"""
|
||||||
|
Thumb the currently selected song down.
|
||||||
|
"""
|
||||||
self.track.rate_song((0 if self.track.rating == 1 else 1))
|
self.track.rate_song((0 if self.track.rating == 1 else 1))
|
||||||
|
|
||||||
def _send_signal(self, signal):
|
def _send_signal(self, signal):
|
||||||
urwid.emit_signal(self, signal, self)
|
urwid.emit_signal(self, signal, self)
|
||||||
|
|
||||||
|
def activate(self):
|
||||||
|
"""
|
||||||
|
Add the entire list to queue and begin playing
|
||||||
|
"""
|
||||||
|
self._send_signal("activate")
|
||||||
|
|
||||||
def play(self):
|
def play(self):
|
||||||
"""
|
"""
|
||||||
Play this song.
|
Play this song.
|
||||||
"""
|
"""
|
||||||
self._send_signal("activate")
|
self._send_signal("play")
|
||||||
|
|
||||||
def append(self):
|
def append(self):
|
||||||
"""
|
"""
|
||||||
Add this song to the queue.
|
Add this song to the queue.
|
||||||
"""
|
"""
|
||||||
self._send_signal("append-requested")
|
self._send_signal("append-requested")
|
||||||
|
self.play()
|
||||||
|
|
||||||
def unappend(self):
|
def unappend(self):
|
||||||
"""
|
"""
|
||||||
|
@ -466,6 +486,10 @@ class SongListBox(urwid.Frame):
|
||||||
urwid.connect_signal(
|
urwid.connect_signal(
|
||||||
songitem, 'activate', self.item_activated
|
songitem, 'activate', self.item_activated
|
||||||
)
|
)
|
||||||
|
|
||||||
|
urwid.connect_signal(
|
||||||
|
songitem, 'play', self.item_play_pause
|
||||||
|
)
|
||||||
urwid.connect_signal(
|
urwid.connect_signal(
|
||||||
songitem, 'append-requested', self.item_append_requested
|
songitem, 'append-requested', self.item_append_requested
|
||||||
)
|
)
|
||||||
|
@ -481,6 +505,13 @@ class SongListBox(urwid.Frame):
|
||||||
items.append(songitem)
|
items.append(songitem)
|
||||||
return (items, current_index)
|
return (items, current_index)
|
||||||
|
|
||||||
|
def item_play_pause(self, songitem):
|
||||||
|
"""
|
||||||
|
Called when you want to start playing a song.
|
||||||
|
"""
|
||||||
|
if songitem.is_currently_played:
|
||||||
|
player.play_pause()
|
||||||
|
|
||||||
def item_activated(self, songitem):
|
def item_activated(self, songitem):
|
||||||
"""
|
"""
|
||||||
Called when specific song item is activated.
|
Called when specific song item is activated.
|
||||||
|
|
Loading…
Add table
Reference in a new issue