Gajim Amarok Now Playing Script
Inspired by plugins for another players, here's a plugin for my player of choice, Amarok, to update your status with the current playing song.
Requirements:
- Gajim with D-Bus working (see GajimDBus)
- Amarok (Tested with 1.3.8)
Below is the script in 'plain text', and you can get a prepackaged (ready to be installed using amarok's script manager) here gajim-amaroknowplaying.amarokscript.tar.gz, or see below for an attached version.
#!/bin/bash
#
# Gajim-amarokNowPlaying
# by [Knuckles] xmpp:knuckles@jabber.3gnt.org
#
# License: GPL (GNU Public License)
#
# This script sets online status on gajim with currently playing track.
# Modified from amarokNowPlaying copyright 2005 by Daniel Dormann (daniel@invision-team.de).
#
currentPath=$(pwd)
state=$(dcop amarok player status)
if [ "$state" = 1 ]; then
state="paused"
elif [ "$state" = 2 ]; then
state="playing"
else
state="empty"
fi
input=trackChange
while [ 1 ]
do
if [ ${input:0:17} = engineStateChange ]; then
state=${input:18}
input=trackChange
fi
if [ "$input" = trackChange ] || [ ${#state} > 0 ]; then
artist=$(dcop amarok player artist)
title=$(dcop amarok player title)
nowPlaying=$(dcop amarok player nowPlaying)
#isPlaying=$(dcop amarok player isPlaying)
#status=$(dcop amarok player status)
#repeatTrack=$(dcop amarok player repeatTrackStatus)
#repeatPlaylist=$(dcop amarok player repeatPlaylistStatus)
#randomMode=$(dcop amarok player randomModeStatus)
#artist=$(dcop amarok player artist)
#title=$(dcop amarok player title)
#track=$(dcop amarok player track)
#album=$(dcop amarok player album)
#length=$(dcop amarok player totalTime)
#genre=$(dcop amarok player genre)
#year=$(dcop amarok player year)
#comment=$(dcop amarok player comment)
#bitrate=$(dcop amarok player bitrate)
#samplerate=$(dcop amarok player sampleRate)
#cover=$(dcop amarok player coverImage)
#score=$(dcop amarok player score)
gajim-remote change_status online "♫ Amarok: $nowPlaying"
# for testing
#kdialog --msgbox "gajim-remote change_status online ♫ $artist - $title"
fi
read input
done
And here's a variant which doesn't reset your status to "online" on every track change, and also preserves your existing status message and just appends the track name onto it:
#!/bin/bash
#
# Gajim-amarokNowPlaying
# by [Knuckles] xmpp:knuckles@jabber.3gnt.org
# with additions by Mrinal Kalakrishnan <mail at mrinal dot net>
#
# License: GPL (GNU Public License)
#
# This script sets online status on gajim with currently playing track.
# Modified from amarokNowPlaying copyright 2005 by Daniel Dormann (daniel@invision-team.de).
#
currentPath=$(pwd)
state=$(dcop amarok player status)
if [ "$state" = 1 ]; then
state="paused"
elif [ "$state" = 2 ]; then
state="playing"
else
state="empty"
fi
input=trackChange
while [ 1 ]
do
if [ ${input:0:17} = engineStateChange ]; then
state=${input:18}
input=trackChange
fi
if [ "$input" = trackChange ] || [ ${#state} > 0 ]; then
artist=$(dcop amarok player artist)
title=$(dcop amarok player title)
nowPlaying=$(dcop amarok player nowPlaying)
#isPlaying=$(dcop amarok player isPlaying)
#status=$(dcop amarok player status)
#repeatTrack=$(dcop amarok player repeatTrackStatus)
#repeatPlaylist=$(dcop amarok player repeatPlaylistStatus)
#randomMode=$(dcop amarok player randomModeStatus)
#artist=$(dcop amarok player artist)
#title=$(dcop amarok player title)
#track=$(dcop amarok player track)
#album=$(dcop amarok player album)
#length=$(dcop amarok player totalTime)
#genre=$(dcop amarok player genre)
#year=$(dcop amarok player year)
#comment=$(dcop amarok player comment)
#bitrate=$(dcop amarok player bitrate)
#samplerate=$(dcop amarok player sampleRate)
#cover=$(dcop amarok player coverImage)
#score=$(dcop amarok player score)
oldStatus=$(gajim-remote get_status)
oldStatusMessage=$(gajim-remote get_status_message | sed 's/ ♫.*//')
gajim-remote change_status $oldStatus "$oldStatusMessage ♫ $nowPlaying"
# for testing
#kdialog --msgbox "gajim-remote change_status online ♫ $artist - $title"
fi
read input
done
Here is my version. It reflects the listening status (playing, paused, stopped) and cleans up (removes track's informations from the status message) when exiting amaroK. Package can be found here. Should work with gaim too (not tested). -- Alan71 (20/08/2007 - 14:35)
#!/bin/bash
# Authors: Silian Della Ragione
# Andres Gomez Garcia <agomez@igalia.com>
# Antoine <Alan71> Gassot <antoine_dot_gassot_at_gmail_dot_com>
# Version: 0.0.3
# License GNU/GPL
############################################################################
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
############################################################################
GAJIM_REMOTE=/usr/bin/gajim-remote
GAIM_REMOTE=/usr/bin/gaim-remote
changeStatus () {
if [ -z "$1" ]; then
MESSAGE=""
else
MESSAGE=" ♫ $1"
fi
if [ -x "${GAJIM_REMOTE}" ]; then
ACCOUNTS=`${GAJIM_REMOTE} list_accounts`
if [ "${?}" = "0" ]; then
for ACCOUNT in ${ACCOUNTS}; do
STATUS=`${GAJIM_REMOTE} get_status ${ACCOUNT}`
if [ ! "${STATUS}" = "offline" ]; then
OLDMESSAGE=`gajim-remote get_status_message | sed 's/ ♫.*//'`
${GAJIM_REMOTE} change_status "${STATUS}" "${OLDMESSAGE}${MESSAGE}" "${ACCOUNT}"
fi
done
fi
fi
if [ -x "${GAIM_REMOTE}" ]; then
${GAIM_REMOTE} "setstatus?message=${MESSAGE}"
fi
}
cleanup () {
changeStatus ""
}
trap cleanup SIGTERM
while [ 1 ]; do
read NOTIFICATION || exit
if [ "${NOTIFICATION}" == "trackChange" ] || [ "${NOTIFICATION}" == "engineStateChange: playing" ]; then
ARTIST=`dcop amarok player artist`
ALBUM=`dcop amarok player album`
TITLE=`dcop amarok player title`
MESSAGE="[▶] ${ARTIST} - ${TITLE} (${ALBUM})"
changeStatus "${MESSAGE}"
elif [ "${NOTIFICATION}" == "engineStateChange: paused" ]; then
MESSAGE="[Ⅱ] ${ARTIST} - ${TITLE} (${ALBUM})"
changeStatus "${MESSAGE}"
elif [ "${NOTIFICATION}" == "engineStateChange: empty" ]; then
MESSAGE="[■] ${ARTIST} - ${TITLE} (${ALBUM})"
changeStatus "${MESSAGE}"
fi
done
Else one version, that send your music info as xml. It is using PEP (XEP-0163) for publishing your music. Script based on previous script, writen by Silian Della Ragione. There are some bug present: before music title appears double quote in the tip window. Xml-code is clear (as I can see). If anybody knows wtf, please contact me. File - http://0:0@disk.jabbus.org/public/der_fenix@jabbus.org/amarok_to_gajim_pep.sh
This script reads the currently playing song out of Amarok and updates the Gajim Tune message when the song has changed:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# amarok_to_gajim_pep.py
#
# by Dicson fominde@gmail.com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
import os, time, dbus.service
from dbus.mainloop.glib import DBusGMainLoop
class mpdtune(dbus.service.Object):
def __init__(self):
dbus.service.Object.__init__(self, dbus.SessionBus(), '/Player')
@dbus.service.signal(dbus_interface = 'org.freedesktop.MediaPlayer')
def TrackChange(self, trackinfo):
print (trackinfo['title'] + trackinfo['album'] + trackinfo['artist'])
def get_status():
f = os.popen("dcop amarok player isPlaying")
status = f.read()
return status
def get_data():
artist = album = title = ''
f = os.popen("dcop amarok player artist")
artist = f.read()
f = os.popen("dcop amarok player album")
album = f.read()
f = os.popen("dcop amarok player title")
title = f.read()
return title, artist, album
def set_status(title = '', artist = '', album = ''):
global lasttune
if lasttune == title + ' - ' + artist + ' - ' + album:
return
lasttune = title + ' - ' + artist + ' - '+ album
tune.TrackChange(dbus.Dictionary({'title' : title, 'artist' : artist, 'album' : album}))
dbus.SessionBus(mainloop = DBusGMainLoop())
lasttune = ''
tune = mpdtune()
try:
while 1:
status = get_status()
if 'true' in status:
data = get_data()
set_status(data[0], data[1], data[2])
else:
set_status()
time.sleep(3)
except KeyboardInterrupt:
set_status()
Attachments
-
Gajim-amarokNowPlaying.amarokscript.tar.gz
(7.5 KB) - added by knuckles@…
4 years ago.
Script prepackaged for amarok's script manager
- gajim_pep_amarok_now_playing.amarokscript.tar.bz2 (1.0 KB) - added by dimanish 2 years ago.
