65 lines
2.1 KiB
Bash
Executable File
65 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# __ __ _____
|
|
# / \ / \ / __ \
|
|
# / /\ \ / /\ \ | |__| | Manuel Prinz (MP)
|
|
# / / \ \/ / \ \ | ___/
|
|
# / / \__/ \ \| |
|
|
# /_/ \_\_|
|
|
#
|
|
# description: Script webradio for Polybar
|
|
# last change: 25.12.2025
|
|
|
|
## variables ##
|
|
msgID="11111"
|
|
mpvsocket="/tmp/mpv"
|
|
path_logo="/home/$USER/Nextcloud/webradio"
|
|
file_title="/tmp/webradio_title"
|
|
|
|
## function displaytime: displays the time in human readable format
|
|
displaytime() {
|
|
local T=$1
|
|
#local D=$((T/60/60/24))
|
|
local H=$((T/60/60%24))
|
|
local M=$((T/60%60))
|
|
local S=$((T%60))
|
|
#(( $D > 0 )) && printf '%d:' $D
|
|
(( $H > 0 )) && printf '%02d:' $H
|
|
(( $M > 0 )) && printf '%02d:' $M
|
|
#(( $D > 0 || $H > 0 || $M > 0 ))
|
|
printf '%02d\n' $S
|
|
}
|
|
|
|
# is mpv running?
|
|
if test -e "$mpvsocket"; then
|
|
# read actual title
|
|
act_title=`echo '{ "command": ["get_property", "media-title"] }' | socat - /tmp/mpv | awk -F\" '{print $4}'`
|
|
|
|
# read playtime and convert to human readable format
|
|
playtime=`echo '{ "command": ["get_property", "playback-time"] }' | socat - /tmp/mpv | awk -F: '{print $2}' | awk -F, '{print $1}' | awk -F. '{print $1}'`
|
|
playtime_act=$(displaytime $playtime)
|
|
|
|
# read station name and logo
|
|
radiostation=`cat /tmp/radiostation | awk '{print $1}'`
|
|
radiostation_logo=`cat /tmp/radiostation | awk '{print $2}'`
|
|
|
|
# title file exist?
|
|
if test -e "$file_title"; then
|
|
title_check=`cat /tmp/webradio_title`
|
|
# actual title equals NOT the name in the title file?
|
|
if [[ "$title_check" != "$act_title" ]]; then
|
|
echo $act_title > $file_title
|
|
dunstify -t 5000 -a "Webradio: $radiostation" -r $msgID -I "$path_logo/$radiostation_logo" "$act_title"
|
|
fi
|
|
else
|
|
# if title file not exists
|
|
echo $act_title > $file_title
|
|
dunstify -t 5000 -a "Webradio: $radiostation" -r $msgID -I "$path_logo/$radiostation_logo" "$act_title"
|
|
fi
|
|
|
|
# echo play symbol and playtime to polybar
|
|
echo " $playtime_act"
|
|
else
|
|
# Webradio is not running
|
|
echo ""
|
|
fi
|