Created
August 30, 2021 00:37
-
-
Save cesalazar/1a138ad983136ce3514f6217c35c5135 to your computer and use it in GitHub Desktop.
Display playerctl's metadata in a notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Display playerctl's metadata in a notification | |
# Debug options | |
# set -euxo pipefail | |
metadata=$(playerctl metadata) | |
notification_icon=${1} | |
get_field() { | |
local field=${1} | |
echo "${metadata}" | grep -E ":${field}" | |
} | |
notify() { | |
local app=$1 | |
local msg=$2 | |
local state=$3 | |
[[ ! ${state} ]] && \ | |
[[ $(playerctl status) == "Playing" ]] && state=▶ || state=⏸ | |
notify-send "${state} playerctl: ${app}" "${msg:0:30}" | |
} | |
urldecode() { | |
local url="${*//+/ }" | |
echo -e "${url//%/\\x}" | |
} | |
# The name of the app | |
trackid=$(get_field trackid | grep -Eo "(firefox|vlc)" | head -n 1) | |
# The name of the stream | |
title=$(get_field "(title|url)") | |
title=$(urldecode "${title##*/}" | awk '{print substr($0,index($0,$3))}') | |
notify "${trackid}" "${title}" "${notification_icon}" | |
# vim: fdm=manual tabstop=4 softtabstop=4 shiftwidth=4 expandtab: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment