Skip to content

Instantly share code, notes, and snippets.

@cesalazar
Created August 30, 2021 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cesalazar/1a138ad983136ce3514f6217c35c5135 to your computer and use it in GitHub Desktop.
Save cesalazar/1a138ad983136ce3514f6217c35c5135 to your computer and use it in GitHub Desktop.
Display playerctl's metadata in a notification
#!/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