Skip to content

Commit 7471977

Browse files
committed
Merge remote-tracking branch 'raffaem/master'
2 parents 9e0e653 + ff5f9ad commit 7471977

File tree

2 files changed

+116
-95
lines changed

2 files changed

+116
-95
lines changed

README.md

Lines changed: 79 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# waybar-mediaplayer
22

3+
## Retirement notice
4+
5+
I don't use this project anymore and therefore I'm archiving it.
6+
7+
Feel free to fork it.
8+
9+
## Introduction
10+
311
This is a mediaplayer for [waybar](https://github.com/Alexays/Waybar).
412

513
Widget with album art and progress bar:
@@ -26,94 +34,98 @@ It features:
2634
5. Optional notification on song change
2735
6. Click to play/pause, scroll up/down to scroll up/down on the playlist
2836

29-
# Requirements
37+
## Requirements
3038

31-
`playerctl` must be installed.
39+
[playerctl](https://github.com/altdesktop/playerctl) must be installed.
3240

3341
The default configuration use Nerd Fonts, so it requires waybar to use a Nerd Font.
3442

35-
The default configuration use `feh` to open the album art image.
43+
The default configuration use [feh](https://github.com/derf/feh) to open the album art image.
3644

37-
# Install
45+
## Install
3846

39-
Create a virtual environment within which to run waybar. For example, using pyenv this would be:
40-
```
41-
pyenv virtualenv 3.12.0 waybar
42-
pyenv activate waybar
43-
```
47+
1. Create a virtual environment within which to run waybar. For example, using pyenv this would be:
4448

45-
You can create a wrapper script to run waybar inside this virtual environment. For example, always using pyenv:
46-
```
47-
#!/usr/bin/env bash
48-
. ~/.pyenv/versions/waybar/bin/activate
49-
waybar
50-
```
49+
```
50+
pyenv virtualenv 3.12.0 waybar
51+
pyenv activate waybar
52+
```
5153
52-
Run:
54+
1. Create a wrapper script to run waybar inside this virtual environment.
5355
54-
```
55-
git clone https://github.com/raffaem/waybar-mediaplayer "$HOME/.config/waybar/waybar-mediaplayer"
56-
cd "$HOME/.config/waybar/waybar-mediaplayer"
57-
```
56+
For example, always using pyenv, create the file `start_waybar` and put it in your PATH:
57+
```
58+
#!/usr/bin/env bash
59+
. ~/.pyenv/versions/waybar/bin/activate
60+
waybar
61+
```
5862
59-
Install the required python packages inside your virtual environment:
60-
```
61-
pip3 install -r requirements.txt
62-
```
63+
1. Clone this repo:
6364
64-
You need to find the name of your player. To do so, run `playerctl --list-all` while your player is running.
65+
```
66+
git clone https://github.com/raffaem/waybar-mediaplayer "$HOME/.config/waybar/waybar-mediaplayer"
67+
cd "$HOME/.config/waybar/waybar-mediaplayer"
68+
```
6569
66-
Open `"$HOME/.config/waybar/waybar-mediaplayer/src/config.json` and change `player_name` with the name of your player.
70+
1. Install the required python packages inside your virtual environment:
6771
68-
Put the following in `$HOME/.config/waybar/config`:
72+
```
73+
pip3 install -r requirements.txt
74+
```
6975
70-
```
71-
"modules-left": ["image", "custom/mediaplayer"],
72-
```
76+
1. You need to find the name of your player. To do so, run `playerctl --list-all` while your player is running.
7377
74-
```
75-
"image": {
76-
"path": "/tmp/waybar-mediaplayer-art",
77-
"size": 32,
78-
"signal": 4,
79-
"on-click": "feh --auto-zoom --borderless --title 'feh-float' /tmp/waybar-mediaplayer-art"
80-
},
81-
82-
"custom/mediaplayer": {
83-
"exec": "$HOME/.config/waybar/waybar-mediaplayer/src/mediaplayer monitor",
84-
"return-type": "json",
85-
"format": "{}",
86-
"on-click": "$HOME/.config/waybar/waybar-mediaplayer/src/mediaplayer play-pause",
87-
"on-scroll-up": "$HOME/.config/waybar/waybar-mediaplayer/src/mediaplayer next",
88-
"on-scroll-down": "$HOME/.config/waybar/waybar-mediaplayer/src/mediaplayer previous",
89-
"min-length": 20,
90-
"max-length": 20
91-
},
92-
```
78+
1. Open `"$HOME/.config/waybar/waybar-mediaplayer/src/config.json` and change `player_name` with the name of your player.
9379
94-
Put the following in `$HOME/.config/waybar/style.css`:
80+
1. Put the following in `$HOME/.config/waybar/config`:
9581
96-
```
97-
#custom-mediaplayer
98-
{
99-
font-size: 16px;
100-
border-radius: 2%;
101-
}
102-
@import "./waybar-mediaplayer/src/style.css";
103-
```
82+
```
83+
"modules-left": ["image", "custom/mediaplayer"],
84+
```
85+
86+
```
87+
"image": {
88+
"path": "/tmp/waybar-mediaplayer-art",
89+
"size": 32,
90+
"signal": 4,
91+
"on-click": "feh --auto-zoom --borderless --title 'feh-float' /tmp/waybar-mediaplayer-art"
92+
},
93+
94+
"custom/mediaplayer": {
95+
"exec": "$HOME/.config/waybar/waybar-mediaplayer/src/mediaplayer monitor",
96+
"return-type": "json",
97+
"format": "{}",
98+
"on-click": "$HOME/.config/waybar/waybar-mediaplayer/src/mediaplayer play-pause",
99+
"on-scroll-up": "$HOME/.config/waybar/waybar-mediaplayer/src/mediaplayer next",
100+
"on-scroll-down": "$HOME/.config/waybar/waybar-mediaplayer/src/mediaplayer previous",
101+
"min-length": 20,
102+
"max-length": 20
103+
},
104+
```
105+
106+
Put the following in `$HOME/.config/waybar/style.css`:
107+
108+
```
109+
#custom-mediaplayer
110+
{
111+
font-size: 16px;
112+
border-radius: 2%;
113+
}
114+
@import "./waybar-mediaplayer/src/style.css";
115+
```
104116
105-
Restart waybar.
117+
1. Start waybar using the wrapper script `start_waybar`.
106118
107119
The mediaplayer should work. Click on the progress bar to start/stop playing, and scroll on it to change song.
108120
109-
# Update
121+
## Update
110122
111123
```
112124
cd "$HOME/.config/waybar/waybar-mediaplayer"
113125
git pull
114126
```
115127
116-
# Personalization
128+
## Personalization
117129
118130
To disable notifications, put `is_notification=false` in `config.json`.
119131
@@ -123,29 +135,29 @@ In order for the album art to automatically update on song change, it's importan
123135
124136
If you change the colors of the bar in `$HOME/.config/waybar/waybar-mediaplayer/src/config.json`, make sure to apply the changes by running `$HOME/.config/waybar/waybar-mediaplayer/src/mkstyle` and restart waybar.
125137
126-
# Troubleshooting
138+
## Troubleshooting
127139
128-
## Firefox users
140+
### Firefox users
129141
130142
Although Firefox reports MPRIS metadata, the metadata it reports is not sufficient, as it doesn't report song's length. Please install the [Plasma Integration](https://addons.mozilla.org/en-US/firefox/addon/plasma-integration) add-on and use `plasma-browser-integration` as `player_name` in `$HOME/.config/waybar/waybar-mediaplayer/src/config.json`.
131143
132144
To have album art, make sure to set `convert_to_jpeg` to `true` in `$HOME/.config/waybar/waybar-mediaplayer/src/config.json` (this option decreases performance, don't use it if not necessary).
133145
134-
## Me progress bar doesn't work
146+
### Me progress bar doesn't work
135147
136148
It's likely cause by the player not reporting song length or position back to us. Run `$HOME/.config/waybar/waybar-mediaplayer/src/mediaplayer -vvv` to debug.
137149
138-
## Player reports its name with instance number
150+
### Player reports its name with instance number
139151
140152
If the player reports an instance after its name, please provide only the player name without the instance number. For example, [kew](https://github.com/ravachol/kew) may report itself as `kew123456`, where `123456` is an instance number which will change with different runs of `kew`. In this case, we report only `kew` without the instance number. This software will check whether the reported player name _starts_ with the name you provide to bind the correct player.
141153
142-
## Me title and tooltip are empty
154+
### Me title and tooltip are empty
143155
144156
It's likely your song file doesn't contain metadata.
145157
146158
Run `exiftool SONG.mp3` and check the `Title`, `Album` and `Artist` fields.
147159
148-
## Me album art doesn't change on song change
160+
### Me album art doesn't change on song change
149161
150162
Make sure that the `signal` in the `image` module in `$HOME/.config/waybar/config` matches the number provided by `image_signal` in `$HOME/.config/waybar/waybar-mediaplayer/src/config.json`.
151163

src/mediaplayer

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -295,24 +295,23 @@ def download_lyrics(artist, title):
295295
lyrlogger.handlers.clear()
296296
lyrlogger.addHandler(logging.StreamHandler(stream))
297297
lyrlogger.setLevel(logging.INFO)
298-
lt = syncedlyrics.search(
299-
f"{artist} {title}",
300-
providers=config["lyrics_providers"],
301-
)
302-
# This is the main logger
303-
# logger.debug("GOT LYRICS")
304-
# logger.debug("-"*10)
305-
# logger.debug(lt)
306-
# logger.debug("-"*10)
298+
try:
299+
lt = syncedlyrics.search(
300+
f"{artist} {title}",
301+
synced_only=True,
302+
providers=config["lyrics_providers"],
303+
)
304+
except Exception:
305+
logger.debug(
306+
"ERROR: syncedlyrics.search threw an exception. Returning None.")
307+
return None
307308
if lt is None:
308-
lt = ""
309+
logger.debug(
310+
"ERROR: syncedlyrics.search returned None. Returning None.")
311+
return None
309312
lt = lt.replace("\n", "")
310313
lt = lt.split("[")
311314
lt = ["["+x for x in lt if x]
312-
# logger.debug("SPLITTING")
313-
# logger.debug("-"*10)
314-
# logger.debug(lt)
315-
# logger.debug("-"*10)
316315
provider = stream.getvalue().split("on ")[1].strip()
317316
stream.close()
318317
SyncedLyrics = namedtuple("SyncedLyrics", ["lt", "provider"])
@@ -329,8 +328,9 @@ def get_new_lyrics(artist, title):
329328
"provider": None,
330329
}
331330
lyr = download_lyrics(artist, title)
332-
if lyr.lt is None:
333-
logger.debug("No lyrics, returning")
331+
if lyr is None:
332+
logger.debug("ERROR: download_lyrics returned None. Returning.")
333+
lyrics = None
334334
return
335335
lyrics["provider"] = lyr.provider
336336
for i, line in enumerate(lyr.lt):
@@ -346,7 +346,8 @@ def get_new_lyrics(artist, title):
346346
try:
347347
secs = int(timing2[0]) * 60.0 + float(timing2[1])
348348
except ValueError:
349-
logger.debug(f"ERROR: ValueError while converting timing2={timing2} to seconds")
349+
logger.debug(f"ERROR: ValueError while converting timing2={
350+
timing2} to seconds")
350351
continue
351352
# get lyrics text
352353
text = m.group(2).strip()
@@ -462,10 +463,10 @@ def update_progressbar(manager, player):
462463
and metadata["length"] == last_metadata["length"]
463464
and lyrics_same
464465
)
465-
# CHeck if we need to update
466+
# Check if we need to update
466467
if same_song and \
467-
not pbar_needs_update and \
468-
not rot_needs_update:
468+
not pbar_needs_update and \
469+
not rot_needs_update:
469470
logger.debug(
470471
"Song is the same and neither the text "
471472
"nor the progressbar nor the lyrics needs an update. Returning"
@@ -478,10 +479,13 @@ def update_progressbar(manager, player):
478479
s = [metadata["title"], metadata["artist"], metadata["album"]]
479480
# -- Lyrics
480481
curr_line = None
482+
text_len = None
481483
if lyrics:
482-
ll = lyrics.get("max_len", 3)
483-
s.append("-" * ll)
484-
provider = lyrics.get("provider","")
484+
cand = [len(x) for x in s]
485+
cand.append(lyrics.get("max_len", 3))
486+
text_len = max(cand)
487+
s.append("-" * text_len)
488+
provider = lyrics.get("provider", "")
485489
if provider is None:
486490
provider = "NO PROVIDER"
487491
s.append("["+provider+"]")
@@ -508,13 +512,18 @@ def update_progressbar(manager, player):
508512
if t == lyrics_ix:
509513
curr_line = len(s) - 1
510514
# -- Tooltip
511-
center_text(s, lyrics.get("max_len", None))
515+
center_text(s, text_len)
512516
if curr_line:
513517
s[curr_line] = "<b>" + s[curr_line] + "</b>"
514-
tooltip = f"<span variant='title-caps' font_weight='bold'>{s[0]}</span>\n"
515-
tooltip += f"{s[1]}\n"
516-
tooltip += f"<i>{s[2]}</i>\n"
517-
tooltip += "\n".join(s[3:])
518+
tooltip = f"<span variant='title-caps' font_weight='bold'>{s[0]}</span>"
519+
tooltip += f"\n{s[1]}"
520+
# Skip album in tooltip if we don't have it
521+
s[2] = s[2].strip()
522+
if s[2]:
523+
tooltip += f"\n<i>{s[2]}</i>"
524+
if len(s) >= 4 and s[3].strip():
525+
tooltip += "\n"
526+
tooltip += "\n".join(s[3:])
518527
write_output(widget_text, gen_class(perc), tooltip)
519528
# It's important to return True to keep the handler going
520529
last_metadata = metadata

0 commit comments

Comments
 (0)