Auto start songs; Unicode config option; Rating icons

This commit is contained in:
Valentijn 2018-05-26 21:56:17 +02:00
parent 0fc0d0ae79
commit 78a297e279
4 changed files with 48 additions and 11 deletions

View file

@ -21,10 +21,11 @@ hotkeys:
handle_escape: esc, mod + _
library_item:
play: enter
activate: enter
play: mod + p
append: mod + a
unappend: mod + u
request_station: mod + p
request_station: meta + s
show_context_menu: meta + p
thumbs_up: meta + u
thumbs_down: meta + d
@ -51,6 +52,7 @@ hotkeys:
clay_settings:
x_keybinds: false
unicode: true
play_settings:
authtoken:

View file

@ -5,6 +5,7 @@ PlayBar widget.
import urwid
from clay.player import player
from clay.settings import settings
from clay import meta
@ -71,8 +72,11 @@ class PlayBar(urwid.Pile):
"""
A widget that shows currently played track, playback progress and flags.
"""
_unicode = settings.get('unicode', 'clay_settings')
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):
# super(PlayBar, self).__init__(*args, **kwargs)
@ -130,7 +134,7 @@ class PlayBar(urwid.Pile):
)
progress = player.get_play_progress_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'||',
# self.get_rotating_bar(),
u'\u2505' if player.is_loading
@ -138,6 +142,7 @@ class PlayBar(urwid.Pile):
else u'\u25A0',
track.artist,
track.title,
self.RATING_ICONS[track.rating],
progress // 60,
progress % 60,
total // 60,

View file

@ -144,7 +144,6 @@ class _Settings(object):
except (KeyError, TypeError):
return self._get_section(self._default_config, *sections)
def get_default_config_section(self, *sections):
"""
Always get a section from the default/system configuration. You would use this whenever

View file

@ -24,8 +24,10 @@ class SongListItem(urwid.Pile):
"""
Widget that represents single song item.
"""
_unicode = settings.get('unicode', 'clay_settings')
signals = [
'activate',
'play',
'append-requested',
'unappend-requested',
'station-requested',
@ -57,8 +59,13 @@ class SongListItem(urwid.Pile):
3: u'\u25A0'
}
RATING_ICONS = {0: ' ',
1: u'\U0001F593' if _unicode else '-',
5: u'\U0001F592' if _unicode else '+'}
def __init__(self, track):
self.track = track
self.rating = self.RATING_ICONS[track.rating]
self.index = 0
self.state = SongListItem.STATE_IDLE
self.line1_left = urwid.SelectableIcon('', cursor_position=1000)
@ -107,7 +114,6 @@ class SongListItem(urwid.Pile):
"""
return SongListItem.STATE_ICONS[state]
def update_text(self):
"""
Update text of this item from the attached track.
@ -118,13 +124,16 @@ class SongListItem(urwid.Pile):
icon=self.get_state_icon(self.state),
title=self.track.title,
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):
self.line1_right.set_text(u' \u25bc Cached')
else:
self.line1_right.set_text(u'')
self.line1_right.set_text(u'{rating}'.format(rating=self.rating))
self.line2.set_text(
u' {} \u2015 {}'.format(self.track.artist, self.track.album_name)
)
@ -136,9 +145,10 @@ class SongListItem(urwid.Pile):
"""
Return song artist and title.
"""
return u'{} - {}'.format(
return u'{} - {} {}'.format(
self.track.artist,
self.track.title
self.track.title,
self.rating
)
def keypress(self, size, key):
@ -158,27 +168,37 @@ class SongListItem(urwid.Pile):
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))
def thumbs_down(self):
"""
Thumb the currently selected song down.
"""
self.track.rate_song((0 if self.track.rating == 1 else 1))
def _send_signal(self, signal):
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):
"""
Play this song.
"""
self._send_signal("activate")
self._send_signal("play")
def append(self):
"""
Add this song to the queue.
"""
self._send_signal("append-requested")
self.play()
def unappend(self):
"""
@ -466,6 +486,10 @@ class SongListBox(urwid.Frame):
urwid.connect_signal(
songitem, 'activate', self.item_activated
)
urwid.connect_signal(
songitem, 'play', self.item_play_pause
)
urwid.connect_signal(
songitem, 'append-requested', self.item_append_requested
)
@ -481,6 +505,13 @@ class SongListBox(urwid.Frame):
items.append(songitem)
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):
"""
Called when specific song item is activated.