Skip to content

Commit

Permalink
Merge pull request #11 from martinlatrille/master
Browse files Browse the repository at this point in the history
Add font options
  • Loading branch information
Jvanrhijn committed Dec 1, 2018
2 parents 7b3167f + 2e2a0f0 commit 456625b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 18 deletions.
32 changes: 24 additions & 8 deletions README.md
Expand Up @@ -9,15 +9,15 @@ This is a module that shows the current song playing and its primary artist on S
[![sample screenshot](https://i.imgur.com/kEluTSq.png)](https://i.imgur.com/kEluTSq.png)

### Settings
~~~ ini
``` ini
[module/spotify]
type = custom/script
interval = 1
format-prefix = ""
format = <label>
exec = python /path/to/spotify/script -f '{artist}: {song}'
format-underline = #1db954
~~~
```

#### Custom arguments

Expand All @@ -27,19 +27,19 @@ The argument "-t" is optional and sets the `trunlen`. It specifies the maximum l

Override example:

~~~ ini
``` ini
exec = python /path/to/spotify/script -t 42
~~~
```

##### Format

The argument "-f" is optional and sets the format. You can specify how to display the song and the artist's name, as well as where (or whether) to print the play-pause indicator.

Override example:

~~~ ini
``` ini
exec = python /path/to/spotify/script -f '{play_pause} {song} - {artist}'
~~~
```

This would output "Lone Digger - Caravan Palace" in your polybar, instead of what is shown in the screenshot.

Expand All @@ -49,6 +49,22 @@ The argument "-p" is optional, and sets which unicode symbols to use for the sta

Override example:

~~~ ini
``` ini
exec = python /path/to/spotify/script -p '[playing],[paused]'
~~~
```

##### Fonts

The argument "--font" is optional, and allow to specify which font from your Polybar config to use to display the main label.

Override example:
```ini
exec = python /path/to/spotify/script --font=1
```

The argument "--playpause-font" is optional, and allow to specify which font from your Polybar config to use to display the "play/pause" indicator.

Override example:
``` ini
exec = python /path/to/spotify/script -p '[playing],[paused]' --playpause-font=2
```
50 changes: 40 additions & 10 deletions spotify_status.py 100755 → 100644
Expand Up @@ -26,6 +26,19 @@
metavar='play-pause indicator',
dest='play_pause'
)
parser.add_argument(
'--font',
type=str,
metavar='the index of the font to use for the main label',
dest='font'
)
parser.add_argument(
'--playpause-font',
type=str,
metavar='the index of the font to use to display the playpause indicator',
dest='play_pause_font'
)


args = parser.parse_args()

Expand All @@ -41,6 +54,10 @@ def fix_string(string):
trunclen = 25
play_pause = fix_string(u'\u25B6,\u23F8') # first character is play, second is paused

label_with_font = '%{{T{font}}}{label}%{{T-}}'
font = args.font
play_pause_font = args.play_pause_font

# parameters can be overwritten by args
if args.trunclen is not None:
trunclen = args.trunclen
Expand All @@ -64,6 +81,8 @@ def fix_string(string):
metadata = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'Metadata')
status = spotify_properties.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus')

# Handle play/pause label

play_pause = play_pause.split(',')

if status == 'Playing':
Expand All @@ -73,20 +92,31 @@ def fix_string(string):
else:
play_pause = str()

artist = fix_string(metadata['xesam:artist'][0])
song = fix_string(metadata['xesam:title'])
if play_pause_font:
play_pause = label_with_font.format(font=play_pause_font, label=play_pause)

# Handle main label

artist = fix_string(metadata['xesam:artist'][0]) if metadata['xesam:artist'] else ''
song = fix_string(metadata['xesam:title']) if metadata['xesam:title'] else ''

if not artist and not song:
print('')
else:
if len(song) > trunclen:
song = song[0:trunclen]
song += '...'
if ('(' in song) and (')' not in song):
song += ')'

if len(song) > trunclen:
song = song[0:trunclen]
song += '...'
if ('(' in song) and (')' not in song):
song += ')'

print(output.format(artist=artist, song=song, play_pause=play_pause))
if font:
artist = label_with_font.format(font=font, label=artist)
song = label_with_font.format(font=font, label=song)

print(output.format(artist=artist, song=song, play_pause=play_pause))

except Exception as e:
if isinstance(e, dbus.exceptions.DBusException):
print('')
else:
print(e)

0 comments on commit 456625b

Please sign in to comment.