summaryrefslogtreecommitdiffstats
path: root/.config
diff options
context:
space:
mode:
Diffstat (limited to '.config')
-rw-r--r--.config/polybar/spotify_status.py123
1 files changed, 0 insertions, 123 deletions
diff --git a/.config/polybar/spotify_status.py b/.config/polybar/spotify_status.py
deleted file mode 100644
index 3a56096..0000000
--- a/.config/polybar/spotify_status.py
+++ /dev/null
@@ -1,123 +0,0 @@
1#!/bin/python
2
3import sys
4import dbus
5import argparse
6
7parser = argparse.ArgumentParser()
8parser.add_argument(
9 '-t',
10 '--trunclen',
11 type=int,
12 metavar='trunclen'
13)
14parser.add_argument(
15 '-f',
16 '--format',
17 type=str,
18 metavar='custom format',
19 dest='custom_format'
20)
21parser.add_argument(
22 '-p',
23 '--playpause',
24 type=str,
25 metavar='play-pause indicator',
26 dest='play_pause'
27)
28parser.add_argument(
29 '--font',
30 type=str,
31 metavar='the index of the font to use for the main label',
32 dest='font'
33)
34parser.add_argument(
35 '--playpause-font',
36 type=str,
37 metavar='the index of the font to use to display the playpause indicator',
38 dest='play_pause_font'
39)
40
41
42args = parser.parse_args()
43
44def fix_string(string):
45 # corrects encoding for the python version used
46 if sys.version_info.major == 3:
47 return string
48 else:
49 return string.encode('utf-8')
50
51# Default parameters
52output = fix_string(u'{play_pause} {artist}: {song}')
53trunclen = 25
54play_pause = fix_string(u'\u25B6,\u23F8') # first character is play, second is paused
55
56label_with_font = '%{{T{font}}}{label}%{{T-}}'
57font = args.font
58play_pause_font = args.play_pause_font
59
60# parameters can be overwritten by args
61if args.trunclen is not None:
62 trunclen = args.trunclen
63if args.custom_format is not None:
64 output = args.custom_format
65if args.play_pause is not None:
66 play_pause = args.play_pause
67
68try:
69 session_bus = dbus.SessionBus()
70 spotify_bus = session_bus.get_object(
71 'org.mpris.MediaPlayer2.spotify',
72 '/org/mpris/MediaPlayer2'
73 )
74
75 spotify_properties = dbus.Interface(
76 spotify_bus,
77 'org.freedesktop.DBus.Properties'
78 )
79
80 metadata = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'Metadata')
81 status = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus')
82
83 # Handle play/pause label
84
85 play_pause = play_pause.split(',')
86
87 if status == 'Playing':
88 play_pause = play_pause[0]
89 elif status == 'Paused':
90 play_pause = play_pause[1]
91 else:
92 play_pause = str()
93
94 if play_pause_font:
95 play_pause = label_with_font.format(font=play_pause_font, label=play_pause)
96
97 # Handle main label
98
99 artist = fix_string(metadata['xesam:artist'][0]) if metadata['xesam:artist'] else ''
100 song = fix_string(metadata['xesam:title']) if metadata['xesam:title'] else ''
101 album = fix_string(metadata['xesam:album']) if metadata['xesam:album'] else ''
102
103 if not artist and not song and not album:
104 print('')
105 else:
106 if len(song) > trunclen:
107 song = song[0:trunclen]
108 song += '...'
109 if ('(' in song) and (')' not in song):
110 song += ')'
111
112 if font:
113 artist = label_with_font.format(font=font, label=artist)
114 song = label_with_font.format(font=font, label=song)
115 album = label_with_font.format(font=font, label=album)
116
117 print(output.format(artist=artist, song=song, play_pause=play_pause, album=album))
118
119except Exception as e:
120 if isinstance(e, dbus.exceptions.DBusException):
121 print('')
122 else:
123 print(e)