Little help needed with tint2 pyradio panel info

Anybody … A little help needed with tint2 pyradio-panel-info.sh

I made a little script that shows the Artist and title of Pyradio in tint2.
It works.

Only if there is a …

&

… character in the Title, there is no output.

How can I adjust the & issue. :slight_smile:

#!/bin/sh

readonly STR="$(awk '// { save=$0 }END{ print save }' ~/.config/pyradio/pyradio-titles.log)"

function PID_ON {
	pidof -x pyradio
}

# Show Pyradio title in tint2


if PID_ON
then
	echo "${STR:21:100}"
fi

if ! PID_ON 
then
	echo ""
fi

Mabox_20230610-10-53-41

:bird:

Note if anyone wants to use it.

Change :100 to shorten the sentence, should it be too long for the panel.

Edit:wrong info

still learning :slight_smile:

& is a special character.
You need to find a way to replace it. In case of tint2 executor probably & could work.

With Bash it will be easier and faster :slight_smile:

#!/bin/bash
shopt -s extglob

if pidof -x pyradio &>/dev/null;then
	TITLE=$(tail -n 1 ~/.config/pyradio/pyradio-titles.log|cut -d'|' -f2)
	TITLE=${TITLE##*( )} # remove leading spaces
	echo "${TITLE/&/&}" # replace 
else
	echo ""
fi
1 Like

Thanks for the lines … :penguin:
Don’t know why i used sh. I mainly use bash.

-s = enable (set) each OPTNAME
Exit Status:
Returns success if OPTNAME is enabled; fails if an invalid option is
given or OPTNAME is disabled.

Can you please explain what is happening here.
Shopt = checks enabled / disabled extglob.
Extglob = mystery

:bird:

Here it is required for removing leading spaces (without need to use external tools like sed for example).

What does the Shopt command do in Linux? – Quick-Advisors.com

1 Like

Now that Pyradio server is working stable :slight_smile: , I modified the script of Pyradio panel title.
It checks Playback/Idle status through the server.

Operation :
Server ON : Title is displayed at PLAYBACK. Title disappears in PAUSE mode.
Server OFF : Title is always displayed.

Remark :

It can happen that the title does not appear, but everything is ok, then there is a & in the title somewhere in the way to display the text.
Check ~/.config/pyradio/pyradio-titles.log to see the & in the title.
It’s already a lot less with @napcok’s adjustments.

#!/bin/bash
shopt -s extglob

pyradio_status="$(curl http://127.0.0.1:9998/html/info | grep 'Status' | grep playback | wc -l)"

if test $pyradio_status -gt 0 
 then
	TITLE=$(tail -n 1 ~/.config/pyradio/pyradio-titles.log|cut -d'|' -f2)
	TITLE=${TITLE##*( )} # remove leading spaces
	echo "${TITLE/&/&}" # replace 
else
	echo ""
fi

Idle

Playback