Song: Move dbus commands to a function
This commit is contained in:
parent
ca8c45b668
commit
8aef69b77f
1 changed files with 16 additions and 28 deletions
44
neofetch
44
neofetch
|
@ -1139,6 +1139,18 @@ get_song() {
|
|||
# This is absurdly long.
|
||||
player="$(ps x | awk '!(/awk|Helper|Cache/) && /mpd|cmus|mocp|spotify|Google Play|iTunes.app|rhythmbox|banshee|amarok|deadbeef|audacious|gnome-music|lollypop|clementine|pragha/ {printf $5 " " $6; exit}')"
|
||||
|
||||
get_song_dbus() {
|
||||
# Multiple players use an almost identical dbus command to get the information.
|
||||
# This function saves us including the same command throughtout the function.
|
||||
song="$(\
|
||||
dbus-send --print-reply --dest=org.mpris.MediaPlayer2."${1}" /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% - }"
|
||||
}
|
||||
|
||||
case "${player/*\/}" in
|
||||
"mpd"*)
|
||||
song="$(mpc current)"
|
||||
|
@ -1159,18 +1171,7 @@ get_song() {
|
|||
|
||||
"spotify"*)
|
||||
case "$os" in
|
||||
"Linux")
|
||||
# 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' |\
|
||||
awk -F 'string "' '/string|array/ {printf "%s",$2; next}{print ""}' |\
|
||||
awk -F '"' '/artist|title/ {printf $2 " - "}'
|
||||
)"
|
||||
song="${song% - }"
|
||||
song="${song/'('*}"
|
||||
song="${song//'['*}"
|
||||
;;
|
||||
"Linux") get_song_dbus "spotify" ;;
|
||||
|
||||
"Mac OS X")
|
||||
song="$(osascript -e 'tell application "Spotify" to artist of current track as string & " - " & name of current track as string')"
|
||||
|
@ -1219,22 +1220,9 @@ get_song() {
|
|||
song="$(audtool current-song)"
|
||||
;;
|
||||
|
||||
"gnome-music"* | "lollypop"* | "clementine"*)
|
||||
case "$player" in
|
||||
"gnome-music"*) player="GnomeMusic" ;;
|
||||
"lollypop"*) player="Lollypop" ;;
|
||||
"clementine"*) player="clementine" ;;
|
||||
esac
|
||||
|
||||
# Hello dbus my old friend.
|
||||
song="$(\
|
||||
dbus-send --print-reply --dest=org.mpris.MediaPlayer2."${player}" /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% - }"
|
||||
;;
|
||||
"gnome-music"*) get_song_dbus "GnomeMusic" ;;
|
||||
"lollypop"*) get_song_dbus "Lollypop" ;;
|
||||
"clementine"*) get_song_dbus "clementine" ;;
|
||||
|
||||
"pragha"*)
|
||||
artist="$(pragha -c | awk -F':' '/artist/ {print $2}')"
|
||||
|
|
Loading…
Reference in a new issue