Skip to content

Instantly share code, notes, and snippets.

@emanchado
Created September 7, 2014 18:08
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 emanchado/40918ae4e6ec4b3fa2c8 to your computer and use it in GitHub Desktop.
Save emanchado/40918ae4e6ec4b3fa2c8 to your computer and use it in GitHub Desktop.
Sets the playlist in Amarok to a given list of files, set loop mode, and play (using DBUS)
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "ERROR: Need one parameter" 2>&1
echo "SYNTAX: amarok-set-playlist [some.playlist]" 2>&1
echo "Where some.playlist is a file with one absolute path per line" 2>&1
exit 1
fi
PLAYLIST=$1
if [ ! -r "$PLAYLIST" ]; then
echo "ERROR: Can't read playlist $PLAYLIST" 2>&1
exit 1
fi
listLength=$(dbus-send --session --print-reply --dest=org.kde.amarok --type="method_call" /TrackList org.freedesktop.MediaPlayer.GetLength 2>/dev/null | grep int32 | sed -e 's/ //' | cut -d ' ' -f 2)
for (( i=0; i<$listLength; i++ )); do
dbus-send --session --dest=org.kde.amarok --type="method_call" /TrackList org.freedesktop.MediaPlayer.DelTrack int32:0
done
dbus-send --session --dest=org.kde.amarok --type="method_call" /TrackList org.freedesktop.MediaPlayer.SetLoop boolean:true
while read filepath; do
dbus-send --session --dest=org.kde.amarok --type="method_call" /TrackList org.freedesktop.MediaPlayer.AddTrack string:"$filepath" boolean:false &>/dev/null
done <$PLAYLIST
dbus-send --session --dest=org.kde.amarok --type="method_call" /Player org.freedesktop.MediaPlayer.Stop &>/dev/null
dbus-send --session --dest=org.kde.amarok --type="method_call" /Player org.freedesktop.MediaPlayer.Play &>/dev/null
@emanchado
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment