I think there's now decent error detection for posting music.

This commit is contained in:
stormdragon2976 2023-02-01 17:55:28 -05:00
parent 870cf0e4fd
commit 36513b8db6
1 changed files with 8 additions and 3 deletions

View File

@ -103,6 +103,14 @@ scrobble_music() {
# Post music with -M flag requires playerctl.
post_music() {
local text="$(playerctl metadata -f 'Now playing "{{title}}" by "{{artist}}" from "{{album}}" via "{{playerName}}"')"
text="${text//Now playing \"\"/Now Playing}"
text="${text// by \"\"/}"
text="${text// from \"\"/}"
if [[ "${text}" =~ ^"Now playing via" ]]; then
echo "Error, no music was detected. Maybe it is not properly tagged?"
play_sound error
exit 1
fi
local link="$(playerctl metadata -f '{{xesam:url}}')"
if [[ "${link}" =~ ^file:// ]]; then
link="https://www.youtube.com/results?search_query=$(playerctl metadata -f '{{artist}} {{title}}' | urlencode -b)"
@ -230,7 +238,6 @@ done
mkdir -p "${configPath}/soundpacks"
# Keep track of the backgrounded loop
bgLoop=1
# Associative array of command line parameters and short description of what they do.
declare -A command=(
@ -272,8 +279,6 @@ done
# Main loops
# Display timelines and requested information.
# Important, set bgLoop to 0 or this loop will not close with the program
bgLoop=0
while : ; do
show_timeline
sleep "${interval:-300}"