-
Notifications
You must be signed in to change notification settings - Fork 8
/
current-song
executable file
·71 lines (62 loc) · 2.16 KB
/
current-song
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#! /bin/sh
# current-song (Bourne shell script) -- scrobbles to STDOUT
#
# Note: in some cases, requires package 'libqt4-dbus' for qdbus tool
#
# Keywords: scrobble rhythmbox banshee audacious amarok
#
# TO-DO:
# + snaffle more from https://github.com/vkolev/playCopy
# + if MUSIC_PLAYER isn't set:
# - read from ~/.config/current-song/config.sh if present
# - otherwise, read from ~/.config/current-song/_detected.sh if present
# - otherwise, detect player
# - ...and save to ~/.config/current-song/_detected.sh
# + option to override player
# + option to force detection (don't save)
self=current-song
AWK_FN_getvalue='function getvalue(key) { return substr($0, length(key) + 3); }'
# Options:
# -c Use the command-line interface instead of DBus
banshee_song()
{
if [ "x$1" = x-c ] ; then
shift
{ banshee --query-artist ; banshee --query-title ; } |
awk '$1 == "artist:" { artist = getvalue("artist"); }
$1 == "title:" { track = getvalue("title"); }
END { print artist " - " track; }'"
$AWK_FN_getvalue"
else
qdbus org.bansheeproject.Banshee /PlayerEngine GetCurrentTrack |
awk '$1 == "album-artist:" { artist = getvalue("album-artist"); }
$1 == "name:" { track = getvalue("name"); }
END { print artist " - " track; }'"
$AWK_FN_getvalue"
fi
}
amarok_song()
{
qdbus org.kde.amarok /Player org.freedesktop.MediaPlayer.GetMetadata |
awk '$1 == "artist:" { artist = getvalue("artist"); }
$1 == "title:" { track = getvalue("title"); }
END { print artist " - " track; }'"
$AWK_FN_getvalue"
}
playerctl_song()
{
playerctl metadata | sed -n 's/^[^ ]\+ xesam:title \+//p'
}
# *** MAINLINE ***
case "$MUSIC_PLAYER" in
_detect) playerctl_song ;;
audacious) audtool current-song ;;
rhythmbox) rhythmbox-client --print-playing ;;
amarok) amarok_song ;;
banshee) banshee_song ;;
*)
echo 'current-song: please set MUSIC_PLAYER environment variable' >&2
exit 3
;;
esac |
sed -e 's/\([^~]*\)~\([^~]*\)~ABSOLUTERADIOIR.*/\1 - \2/'