Added OSD notifications, fixed issue with lastRatingChangeTimestamp, fixed README for PyPi.

This commit is contained in:
Andrew Dunai 2018-06-21 17:19:11 +03:00
parent 4240d7fd05
commit 2390a7c1fa
No known key found for this signature in database
GPG key ID: 592B181FC403814E
7 changed files with 65 additions and 2 deletions

View file

@ -417,7 +417,7 @@ class LikedSongs(object):
if self._sorted:
tracks = self._tracks
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)
self._sorted = True
tracks = self._tracks

View file

@ -2,7 +2,7 @@
Predefined values.
"""
APP_NAME = 'Clay Player'
VERSION = '1.0.0'
VERSION = '1.0.2'
AUTHOR = "Andrew Dunai"
DESCRIPTION = "Awesome standalone command line player for Google Play Music"

53
clay/osd.py Normal file
View 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

View file

@ -76,6 +76,7 @@ class PlayBar(urwid.Pile):
ROTATING = u'|' u'/' u'\u2014' u'\\'
RATING_ICONS = {0: ' ',
1: u'\U0001F593' if _unicode else '-',
4: u'\U0001F592' if _unicode else '+',
5: u'\U0001F592' if _unicode else '+'}
def __init__(self, app):

View file

@ -16,6 +16,7 @@ except ImportError: # Python 2.x
from clay import vlc, meta
from clay.eventhook import EventHook
from clay.notifications import notification_area
from clay.osd import osd_manager
from clay.settings import settings
from clay.log import logger
@ -417,6 +418,11 @@ class _Player(object):
self.media_player.play()
osd_manager.notify('Now playing', '{} - {}'.format(
track.artist,
track.title
))
@property
def is_loading(self):
"""

View file

@ -64,6 +64,7 @@ class SongListItem(urwid.Pile):
RATING_ICONS = {
0: ' ',
1: u'\U0001F593' if _unicode else '-',
4: u'\U0001F593' if _unicode else '-',
5: u'\U0001F592' if _unicode else '+'
}

View file

@ -7,6 +7,8 @@ setup(
name='clay-player',
version=VERSION,
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_email='a@dun.ai',
url='https://github.com/and3rson/clay',