Merge pull request #396 from dylanaraps/song

Song: Rewrite song function
This commit is contained in:
Dylan Araps 2016-10-26 21:20:05 +11:00 committed by GitHub
commit eee8ac7f8e
1 changed files with 75 additions and 61 deletions

View File

@ -1120,26 +1120,33 @@ getmemory() {
# Song {{{
getsong() {
if mpc version >/dev/null 2>&1; then
# This is absurdly long.
player="$(ps x | awk '!(/awk|Helper|Cache/) && /mpd|cmus|mocp|spotify|Google Play|iTunes.app|rhythmbox|banshee|amarok|deadbeef|audacious/ {printf $5 " " $6; exit}')"
case "${player/*\/}" in
"mpd"*)
song="$(mpc current 2>/dev/null)"
state="$(mpc | awk -F '\\[|\\]' '/\[/ {printf $2}' 2>/dev/null)"
;;
elif [ -n "$(ps x | awk '!(/awk/) && /cmus/')" ]; then
"cmus"*)
IFS=$'\n'
song=($(cmus-remote -Q | grep "tag artist \|tag title \|status" 2>/dev/null | sort))
state="${song[0]/status }"
artist="${song[1]/tag artist }"
title="${song[2]/tag title }"
song="${artist/tag title } - ${title/tag artist }"
;;
elif pgrep "mocp" >/dev/null 2>&1; then
"mocp"*)
song="$(mocp -Q "%artist - %song" 2>/dev/null)"
state="$(mocp -Q "%state" 2>/dev/null)"
;;
elif [ -n "$(ps x | awk '!(/awk/) && /spotify/')" ]; then
"spotify"*)
case "$os" in
"Linux")
# This command is way too long
# Thanks dbus
song="$(\
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 \
org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' |\
@ -1156,43 +1163,50 @@ getsong() {
state="$(osascript -e 'tell application "Spotify" to player state as string')"
;;
esac
;;
elif [ -n "$(ps x | awk '!(/awk/ || /Helper/) && /Google Play Music Desktop Player/')" ] && type -p gpmdp-remote >/dev/null 2>&1; then
song="$(gpmdp-remote current)"
state="$(gpmdp-remote status)"
"google play"*)
song="$(gpmdp-remote current 2>/dev/null)"
state="$(gpmdp-remote status 2>/dev/null)"
;;
elif [ -n "$(ps x | awk '!(/awk/ || /Helper/ || /Cache/) && /iTunes.app/')" ]; then
"itunes"*)
song="$(osascript -e 'tell application "iTunes" to artist of current track as string & " - " & name of current track as string')"
state="$(osascript -e 'tell application "iTunes" to player state as string')"
;;
elif [ -n "$(ps x | awk '!(/awk/) && /rhythmbox/')" ]; then
"rhythmbox"*)
song="$(rhythmbox-client --print-playing)"
# Well, what can you expect? It's dbus after all.
# Thanks dbus
state="$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 \
org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string: 'PlayBackStatus' |\
awk -F 'string "' '{printf $2}')"
state="${state//\"}"
;;
elif [ -n "$(ps x | awk '!(/awk/) && /banshee/')" ]; then
"banshee"*)
artist="$(banshee --query-artist | awk -F':' '{print $2}')"
title="$(banshee --query-title | awk -F':' '{print $2}')"
song="$artist - $title"
state="$(banshee --query-current-state | awk -F':' '{print $2}')"
;;
elif [ -n "$(ps x | awk '!(/awk/) && /amarok/')" ]; then
"amarok"*)
artist="$(qdbus org.kde.amarok /Player GetMetadata | awk -F':' '/^artist/ {print $2}')"
title="$(qdbus org.kde.amarok /Player GetMetadata | awk -F':' '/title/ {print $2}')"
song="$artist - $title"
;;
elif [ -n "$(ps x | awk '!(/awk/) && /deadbeef/')" ]; then
"deadbeef"*)
song="$(deadbeef --nowplaying '%a - %t')"
;;
elif [ -n "$(ps x | awk '!(/awk/) && /audacious/')" ]; then
"audacious"*)
song="$(audtool current-song)"
;;
else
song="Not Playing"
fi
*) song="Not Playing" ;;
esac
case "$state" in
"paused" | "PAUSE" | "Paused")