altdesktop / playerctl

🎧 mpris media player command-line controller for vlc, mpv, RhythmBox, web browsers, cmus, mpd, spotify and others.
GNU Lesser General Public License v3.0
2.42k stars 79 forks source link

playerctl --follow in scripts #218

Open Barbaross93 opened 3 years ago

Barbaross93 commented 3 years ago

I'm trying to write a script that monitors the output of playerctl --follow metadata mpris:artUrl to execute some command whenever the artUrl changes. An abbreviated version of what I have so far is:

playerctl --follow metadata mpris:artUrl 2>/dev/null |
    while read arturl; do
        curl -s $arturl -o $tmp_path
    done

The problem with this is that $arturl doesn't update until I kill playerctl; that is, even though playerctl knows about the changes, it doesn't feed them into the while loop until the process is killed. I figured this must be because playerctl --follow's output must be buffered. So i tried

stdbuf -o0 playerctl --follow metadata mpris:artUrl 2>/dev/null |
    while read arturl; do
        curl -s $arturl -o $tmp_path
    done

to disable buffering. Unfortunately that doesn't seem to work. Is there some way around this problem?

acrisci commented 3 years ago

What player are you using?

Barbaross93 commented 3 years ago

The spotify official client

acrisci commented 3 years ago

This is very likely a bug in playerctl introduced in the last release. I'm looking into it now.

Barbaross93 commented 3 years ago

Indeed, downgrading to 2.2.1 seems to work fine

SimplyNaOH commented 3 years ago

In case someone lands here looking for similar problems with spotifyd: they lie in spotifyd itself. Check this PR to spotifyd for solution.

Sorry for the spam but I thought this issue applied to me; I hope by posting this the next person finds the right solution.

acrisci commented 3 years ago

I just tested this again on current master branch and it works correctly. I think the way I was reproducing this before was wrong.

Barbaross93 commented 3 years ago

Looks like the current master branch does indeed work. Did you make any changes? It's strange it wasn't working with 2.3.1 if there weren't any direct changes to address this