jan146 / playerctl-scroller

Scroll the currently playing song via playerctl. It can also be used with polybar.
2 stars 1 forks source link

"Successfully wrote "hook:module/spotify-play-pause2" to "/tmp/polybar_mqueue.7493" #1

Closed diogofd8 closed 2 years ago

diogofd8 commented 2 years ago

Hello! I read your comment on the original spotify scroller about the CPU usage and found your repository with a less demanding version. I followed your instructions on the readme but failed in trying to run the script. With the default settings it showed a "Invalid usage of cscroll: invalid delay parameter "0.2", so I changed to an integer (1) and the message instead was "Successfully wrote "hook:module/spotify-play-pause2" to "/tmp/polybar_mqueue.7493". It will show "No player is running" when I have the spotify app closed but whenever it is open, be it paused or playing, it wont show any info, just that message. It blinks each second printing something else but it is instant so I cannot figure out what is printing, possibly the metadata. I tried looking through the script and the C files but I couldn't find a printing message with that content so I'm assuming it is on the bash script echoing the output of some command when it isn't supposed to. Possibly it doesn't reproduce the same way on your machine, but do you have an idea of what I could change to make your script work here too?

jan146 commented 2 years ago

Hello, After reading your post, I believe there are actually two separate problems.

Firstly, given that the result of a "0.2" delay was an error, the problem likely resides within the locale configuration. I'm quite tight on time currently, so the easiest solution would be to either change the system locale or by changing the "0.2" parameter to fit your current locale. To do that, you should check your locale settings by running locale -k LC_NUMERIC, which should be provided by the glibc package.

This should provide you with an output that looks something like this:

decimal_point="."
thousands_sep=","
grouping=3;3
numeric-decimal-point-wc=46
numeric-thousands-sep-wc=44
numeric-codeset="UTF-8"

The important bit is the first line - the decimal point, which should be the character between the 0 and 2 in "0.2". Yours might be a comma (',') or even something else.

(Hopefully, ) you can fix the problem by editing the DELAY variable in the scroller.sh file, specifically the decimal point character to match your locale. Since I've read your post, I've already added a commit, which adds two lines to scroller.sh that should automate this procedure. All you need to do is uncomment the lines:

# DECIMAL_POINT=$(locale -k LC_NUMERIC | grep "decimal_point" | sed 's/.*="//g;s/.$//g')
# DELAY=0"$DECIMAL_POINT"2

Now, the second problem might be a bit deeper. Besides the previous problem, I've also added another commit, which is meant to fix a semi-related bug, so maybe try that.

Besides that, you should check if playerctl and dbus are working properly together: while spotify or any player is running, check if they're registered by playerctl (playerctl -l) and dbus (dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep mpris). The first command should show only spotify, whereas the second one should show spotify and the default playerctld player.

TLDR: reclone (I've updated the main program and the default config) the repository and reinstall

git clone https://github.com/jan146/playerctl-scroller.git
cd playerctl-scroller
sudo make reinstall
sudo make config

After that, uncomment the aforementioned lines in scroller.sh and check playerctl & dbus.

I hope this helps you in fixing your problems. Kind regards, Jan

diogofd8 commented 2 years ago

Hello! playerctl -l returned spotify dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames | grep mpris returns string "org.mpris.MediaPlayer2.spotify" string "org.mpris.MediaPlayer2.playerctld"

Running your updated version I still have the same issue of the title of this thread. Best regards, Diogo

jan146 commented 2 years ago

Firtsly, for easier debugging, try running scroller.sh manually via a terminal. You will see any command output, even if it goes by fast. I hope this can produce some meaningful insight into the problem.

Secondly, the error message you get is the output of a polybar message (a hook). The program works by using polybar-msg to update a polybar module's status - play/pause. The unusual part is that when issuing this command, its output is redirected to /dev/null and therefore should be invisible to the end user. My guess is that the problem might lie somewhere in the polybar configuration. If you wouldn't mind, I'd like to ask you to share yours (specifically the modules that are used with playerctl-scroller).

The configuration part of the readme mentions 4 modules, though only 2 are actually required - one to run scroller.sh (which outputs the scrolling text) and another ipc module, which should support two hook states: play and pause. Additionally, the second module's (the one with play & pause states) name should match the MODULE variable in scroller.sh.

If you feel like it, you could also share your scroller.sh configuration by simply changing the last line from

eval $RUNCOMMAND

to

echo $RUNCOMMAND

and running the script via ./scroller.sh. Or you can also do this automatically via this command:

sed -i 's/eval $RUNCOMMAND/echo $RUNCOMMAND/g' scroller.sh && ./scroller.sh ; sed -i 's/echo $RUNCOMMAND/eval $RUNCOMMAND/g' scroller.sh

Also, has the decimal point problem been solved now or is it still there? Kind regards, Jan

diogofd8 commented 2 years ago

Hi Jan!

The decimal point is solved! Running through the terminal I get a loop of this:

 Our Lady Peace — Starseed
Successfully wrote "hook:module/spotify-play-pause2" to "/tmp/polybar_mqueue.7669"
 Our Lady Peace — Starseed
Successfully wrote "hook:module/spotify-play-pause2" to "/tmp/polybar_mqueue.7669"
 Our Lady Peace — Starseed
Successfully wrote "hook:module/spotify-play-pause2" to "/tmp/polybar_mqueue.7669"
 Our Lady Peace — Starseed
Successfully wrote "hook:module/spotify-play-pause2" to "/tmp/polybar_mqueue.7669"

this is the scroller.sh config:

playerctl-scroller -l 30 -d 0,2 -u 5 -i 7669 -p spotify -m "spotify-play-pause" -r "/home/diogofd8/.config/polybar/scripts/scroller.sh" -s "  " -o

And here's my polybar config: config.ini.zip

jan146 commented 2 years ago

I believe I might have an idea: &> file is a bashism and therefore is not guaranteed to work on all shells. Instead, I believe > file 2>&1 should work on any posix-compliant shell. The command in question is polybar-msg -p $(pidof polybar) hook spotify-play-pause 2 &> /dev/null.

Try changing line 202 in the function updateButton(int playing, int paused) in the file playerctl-scroller.c:

void updateButton(int playing, int paused){

    if (strcmp(module, "") == 0)
        return;

    if (playing == 0 || paused == 0){

        char* message = (char*) malloc(commandLength*sizeof(char));
        strcpy(message, "polybar-msg -p ");
        strcat(message, pid);
        strcat(message, " hook ");
        removeNL(module);
        strcat(message, module);
        strcat(message, (playing == 0) ? " 1" : " 2");
        strcat(message, " &> /dev/null ; exit 0");       // <----- Change this line <-----
        system(message);
        free(message);

    }
}

from

strcat(message, " &> /dev/null ; exit 0");

to

strcat(message, " > /dev/null 2>&1 ; exit 0");

Or you can do it automatically with this command:

sed -i 's/ \&> \/dev\/null/ > \/dev\/null 2>\&1/g' playerctl-scroller.c

After changing that line, simply recompile the project:

sudo make reinstall

Then, restart polybar or check terminal output of scroller.sh to see if anything has changed. If this does fix it, I will have to update the whole repository, since I've used the expression &> a lot because I wasn't aware that it was a bashism.

Hopefully this fixes the problem. Kind regards, Jan

diogofd8 commented 2 years ago

Yep, you got it right! Working perfectly!

Thanks a lot for the script and all the help! Best regards, Diogo

jan146 commented 2 years ago

It looks like all problems have been resolved, therefore I am closing this issue.

Thanks to @diogofd8 for bringing the problems to light. Best regards, Jan