Merge branch 'master' into taskwarrior-reset-next-task

This commit is contained in:
Robin McCorkell 2017-01-15 16:06:50 +00:00 committed by GitHub
commit 2b56c6cd03
4 changed files with 6 additions and 108 deletions

View File

@ -11,7 +11,7 @@ Module reference
:Audio: `alsa`_ - `pulseaudio`_
:Hardware: `backlight`_ - `battery`_ - `temp`_
:Network: `net_speed`_ - `network`_ - `online`_ - `openstack_vms`_ - `openvpn`_
:Music: `cmus`_ - `moc`_ - `mpd`_ - `now_playing`_ - `pianobar`_ - `playerctl`_ - `spotify`_
:Music: `cmus`_ - `moc`_ - `mpd`_ - `now_playing`_ - `pianobar`_ - `spotify`_
:Websites: `bitcoin`_ - `dota2wins`_ - `github`_ - `modsde`_ - `parcel`_ - `reddit`_ - `weather`_ -
`whosonlocation`_
:Other: `anybar`_ - `mail`_ - `pomodoro`_ - `pyload`_ - `text`_ - `updates`_

View File

@ -1,104 +0,0 @@
from i3pystatus import formatp
from i3pystatus import IntervalModule
from i3pystatus.core.util import TimeWrapper
import gi
gi.require_version('Playerctl', '1.0') # nopep8
from gi.repository import Playerctl as pctl
class Playerctl(IntervalModule):
"""
Gets current music information from a playerctl supported player.
.. rubric:: Available formatters
* `{status}` current status icon (paused/playing/stopped)
* `{length}` total song duration, uses TimeWrapper formatting, default format is `%E%l:%M:%S`
* `{artist}` artist
* `{title}` title
* `{album}` album
"""
settings = (
('format', 'formatp string'),
('format_not_running', 'Text to show if player is not running'),
('color', 'The color of the text'),
('color_not_running', 'The color of the text, when player is not running'),
('status', 'Dictionary mapping status to output'),
('player_name',
'Name of music player, use `playerctl -l` with player running to get. If None, tries to autodetect.'),
)
# default settings
color = '#ffffff'
color_not_running = '#ffffff'
format = '{status} {length} {artist} - {title}'
format_not_running = 'Not running'
status = {
'paused': '',
'playing': '',
'stopped': '',
}
player_name = None
on_leftclick = 'playpause'
on_rightclick = 'next_song'
on_upscroll = 'next_song'
on_downscroll = 'previous_song'
def _get_length_in_secs(self, metadata):
if not metadata:
return 0
try:
time = metadata["mpris:length"] / 1.0e6
seconds = round(time)
return seconds
except KeyError:
return 0
def get_formatted_info(self, player):
"""Get player track info from playerctl"""
result = {
"status": "",
"artist": "",
"title": "",
"album": "",
"length": "",
}
status = player.props.status
if status:
result["status"] = self.status.get(status.lower(), "")
result["artist"] = player.get_artist()
result["title"] = player.get_title()
result["album"] = player.get_album()
length_in_secs = self._get_length_in_secs(player.props.metadata)
result["length"] = TimeWrapper(length_in_secs, "%E%l%M:%S")
return result
def run(self):
"""Main statement, executes all code every interval"""
self.player = pctl.Player(player_name=self.player_name)
fdict = self.get_formatted_info(self.player)
if fdict.get("status", ""):
self.output = {"full_text": formatp(self.format, **fdict),
"color": self.color}
else:
self.output = {"full_text": self.format_not_running,
"color": self.color_not_running}
def playpause(self):
"""Pauses and plays player"""
self.player.play_pause()
def next_song(self):
"""skips to the next song"""
self.player.next()
def previous_song(self):
"""Plays the previous song"""
self.player.previous()

View File

@ -1,8 +1,8 @@
from i3pystatus.playerctl import Playerctl
from i3pystatus.now_playing import NowPlaying
class Spotify(Playerctl):
class Spotify(NowPlaying):
"""
Get Spotify info using playerctl. Based on `Playerctl`_ module.
Get Spotify info using dbus interface. Based on `now_playing`_ module.
"""
player_name = "spotify"

View File

@ -13,6 +13,7 @@ class Taskwarrior(IntervalModule):
* `{ready}` contains number of tasks returned by `ready_filter`
* `{urgent}` contains number of tasks returned by `urgent_filter`
* `{next}` contains the description of next task
* `{project}` contains the projects the next task belongs to
.. rubric:: Available callbacks
@ -91,6 +92,7 @@ class Taskwarrior(IntervalModule):
if self.next_task is not None:
format_values['next'] = self.next_task['description']
format_values['project'] = self.next_task['project']
self.output = {
'full_text': self.format.format(**format_values),