mirror of
https://github.com/vale981/clay
synced 2025-03-04 17:11:41 -05:00
Added OSD notifications, fixed issue with lastRatingChangeTimestamp, fixed README for PyPi.
This commit is contained in:
parent
4240d7fd05
commit
2390a7c1fa
7 changed files with 65 additions and 2 deletions
|
@ -417,7 +417,7 @@ class LikedSongs(object):
|
||||||
if self._sorted:
|
if self._sorted:
|
||||||
tracks = self._tracks
|
tracks = self._tracks
|
||||||
else:
|
else:
|
||||||
self._tracks.sort(key=lambda k: k.original_data['lastRatingChangeTimestamp'],
|
self._tracks.sort(key=lambda k: k.original_data.get('lastRatingChangeTimestamp', '0'),
|
||||||
reverse=True)
|
reverse=True)
|
||||||
self._sorted = True
|
self._sorted = True
|
||||||
tracks = self._tracks
|
tracks = self._tracks
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Predefined values.
|
Predefined values.
|
||||||
"""
|
"""
|
||||||
APP_NAME = 'Clay Player'
|
APP_NAME = 'Clay Player'
|
||||||
VERSION = '1.0.0'
|
VERSION = '1.0.2'
|
||||||
AUTHOR = "Andrew Dunai"
|
AUTHOR = "Andrew Dunai"
|
||||||
DESCRIPTION = "Awesome standalone command line player for Google Play Music"
|
DESCRIPTION = "Awesome standalone command line player for Google Play Music"
|
||||||
|
|
||||||
|
|
53
clay/osd.py
Normal file
53
clay/osd.py
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
"""
|
||||||
|
On-screen display stuff.
|
||||||
|
"""
|
||||||
|
from clay.notifications import notification_area
|
||||||
|
from clay import meta
|
||||||
|
|
||||||
|
IS_INIT = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
from dbus import SessionBus, Interface
|
||||||
|
IS_INIT = True
|
||||||
|
except ImportError:
|
||||||
|
ERROR_MESSAGE = 'Could not import dbus. OSD notifications will be disabled.'
|
||||||
|
except Exception as exception:
|
||||||
|
ERROR_MESSAGE = 'Error while importing dbus: \'{}\''.format(str(exception))
|
||||||
|
|
||||||
|
if not IS_INIT:
|
||||||
|
notification_area.notify(ERROR_MESSAGE)
|
||||||
|
|
||||||
|
|
||||||
|
class _OSDManager(object):
|
||||||
|
"""
|
||||||
|
Manages OSD notifications via DBus.
|
||||||
|
"""
|
||||||
|
def __init__(self):
|
||||||
|
self._last_id = 0
|
||||||
|
|
||||||
|
if IS_INIT:
|
||||||
|
self.bus = SessionBus()
|
||||||
|
self.notifcations = self.bus.get_object(
|
||||||
|
"org.freedesktop.Notifications",
|
||||||
|
"/org/freedesktop/Notifications"
|
||||||
|
)
|
||||||
|
self.notify_interface = Interface(self.notifcations, "org.freedesktop.Notifications")
|
||||||
|
|
||||||
|
def notify(self, title, message):
|
||||||
|
"""
|
||||||
|
Create new or update existing notification.
|
||||||
|
"""
|
||||||
|
if IS_INIT:
|
||||||
|
self._last_id = self.notify_interface.Notify(
|
||||||
|
meta.APP_NAME,
|
||||||
|
self._last_id,
|
||||||
|
'audio-headphones',
|
||||||
|
title,
|
||||||
|
message,
|
||||||
|
[],
|
||||||
|
dict(),
|
||||||
|
5000
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
osd_manager = _OSDManager() # pylint: disable=invalid-name
|
|
@ -76,6 +76,7 @@ class PlayBar(urwid.Pile):
|
||||||
ROTATING = u'|' u'/' u'\u2014' u'\\'
|
ROTATING = u'|' u'/' u'\u2014' u'\\'
|
||||||
RATING_ICONS = {0: ' ',
|
RATING_ICONS = {0: ' ',
|
||||||
1: u'\U0001F593' if _unicode else '-',
|
1: u'\U0001F593' if _unicode else '-',
|
||||||
|
4: u'\U0001F592' if _unicode else '+',
|
||||||
5: u'\U0001F592' if _unicode else '+'}
|
5: u'\U0001F592' if _unicode else '+'}
|
||||||
|
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
|
|
|
@ -16,6 +16,7 @@ except ImportError: # Python 2.x
|
||||||
from clay import vlc, meta
|
from clay import vlc, meta
|
||||||
from clay.eventhook import EventHook
|
from clay.eventhook import EventHook
|
||||||
from clay.notifications import notification_area
|
from clay.notifications import notification_area
|
||||||
|
from clay.osd import osd_manager
|
||||||
from clay.settings import settings
|
from clay.settings import settings
|
||||||
from clay.log import logger
|
from clay.log import logger
|
||||||
|
|
||||||
|
@ -417,6 +418,11 @@ class _Player(object):
|
||||||
|
|
||||||
self.media_player.play()
|
self.media_player.play()
|
||||||
|
|
||||||
|
osd_manager.notify('Now playing', '{} - {}'.format(
|
||||||
|
track.artist,
|
||||||
|
track.title
|
||||||
|
))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_loading(self):
|
def is_loading(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -64,6 +64,7 @@ class SongListItem(urwid.Pile):
|
||||||
RATING_ICONS = {
|
RATING_ICONS = {
|
||||||
0: ' ',
|
0: ' ',
|
||||||
1: u'\U0001F593' if _unicode else '-',
|
1: u'\U0001F593' if _unicode else '-',
|
||||||
|
4: u'\U0001F593' if _unicode else '-',
|
||||||
5: u'\U0001F592' if _unicode else '+'
|
5: u'\U0001F592' if _unicode else '+'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -7,6 +7,8 @@ setup(
|
||||||
name='clay-player',
|
name='clay-player',
|
||||||
version=VERSION,
|
version=VERSION,
|
||||||
description='Command Line Player for Google Play Music',
|
description='Command Line Player for Google Play Music',
|
||||||
|
long_description=open('README.md', 'r').read(),
|
||||||
|
long_description_content_type='text/markdown',
|
||||||
author='Andrew Dunai',
|
author='Andrew Dunai',
|
||||||
author_email='a@dun.ai',
|
author_email='a@dun.ai',
|
||||||
url='https://github.com/and3rson/clay',
|
url='https://github.com/and3rson/clay',
|
||||||
|
|
Loading…
Add table
Reference in a new issue