From 7857d6637602d18c83039b9734f0e24f8c7b6f16 Mon Sep 17 00:00:00 2001 From: stormdragon2976 Date: Mon, 30 Jan 2023 11:45:29 -0500 Subject: [PATCH] Try to use provided link for music, use youtube if it is a file:// link. --- ratatoskr.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ratatoskr.sh b/ratatoskr.sh index 9f79223..ec463b9 100755 --- a/ratatoskr.sh +++ b/ratatoskr.sh @@ -96,9 +96,12 @@ scrobble_music() { # Post music with -M flag requires playerctl. post_music() { - local text="[$(playerctl metadata -f 'Now playing "{{title}}" by "{{artist}}" from "{{album}}"')]" - local link="(https://www.youtube.com/results?search_query=$(playerctl metadata -f '{{artist}} {{title}}' | urlencode -b))" - local json=$(jq -n --arg status "$text$link" --arg spoiler_text "Music" --arg content_type "text/markdown" '{status: $status, spoiler_text: $spoiler_text, content_type: $content_type}') + local text="$(playerctl metadata -f 'Now playing "{{title}}" by "{{artist}}" from "{{album}}"')" + 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)" + fi + local json=$(jq -n --arg status "[${text}](${link})" --arg spoiler_text "Music" --arg content_type "text/markdown" '{status: $status, spoiler_text: $spoiler_text, content_type: $content_type}') local result result="$(curl -sS --oauth2-bearer "${oauth_token}" -H "Content-Type: application/json" \ -d "$json" \