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

136
neofetch
View file

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