polybar/polybar-scripts

How to output filename instead of tags from cmus.sh to the cmus module?

Kabouik opened this issue · 3 comments

While keeping the capability to export tags if wanted, how would one need to alter the script to also allow exporting only currently played file names? I have no coding skills and am struggling with this issue.

For reference, here is cmus.sh:

#!/bin/bash

prepend_zero () {
        seq -f "%02g" $1 $1
}

artist=$(echo -n $(cmus-remote -C status | grep "tag artist" | cut -c 12-))

if [[ $artist = *[!\ ]* ]]; then
        song=$(echo -n $(cmus-remote -C status | grep title | cut -c 11-))
        position=$(cmus-remote -C status | grep position | cut -c 10-)
        minutes1=$(prepend_zero $(($position / 60)))
        seconds1=$(prepend_zero $(($position % 60)))
        duration=$(cmus-remote -C status | grep duration | cut -c 10-)
        minutes2=$(prepend_zero $(($duration / 60)))
        seconds2=$(prepend_zero $(($duration % 60)))
        echo -n "$artist - $song [$minutes1:$seconds1/$minutes2:$seconds2]"
else
        echo
fi
x70b1 commented

It is perhaps possible. But more depends on the possibilities of cmus not on coding skills.

As this is not an issue I would close this case.
But we can check it out, just ping me at the #polybar channel on freenode if you want.

Thank you, I'll ping you on Freenode in the coming days!

dirdi commented

The currently played track's filename can be fetched with cmus-remote -C 'format_print %f'
or for the filename without the path: cmus-remote -C 'format_print %F'