The prerequisites:
Amarok. I'm using Version 1.4, largely because a) it came installed and b) there's a different scripting / plugin system for 2.0
A command-line twitter client such as Twidge. This allows you to tweet a text fragment from a bash script.
Next a script that can detect which track you're currently playing, store that information to disk, and then tweet the results courtesy of twidge. After a bit of messing around, and bearing in mind I only want to tweet changes once-in-a-while rather than a note-by-note account, I settle on this:
#!/bin/bash
oldnotification=""
notification=""
while [ 1 ]
do
#
# Use dcop to ask Amarok what it's up to
#
artist=$(dcop amarok player artist)
title=$(dcop amarok player title)
notification="$artist - $title"
#
# This loop runs continuoulsy, so only leap
# into action when there's a change to report.
#
# If there's no change, sleep for 10 secs. This means you may
# miss changes to tracks that are < 10 secs, but also that you
# don't mess around with checking state etc.
#
if [ "$notification" = "$oldnotification" ]; then
sleep 10
continue
fi
#
# Keep a note to suppress duplicates when playing
#
oldnotification="${notification}"
if [ "$artist" != "" ]; then
#
# Store the notification in a file.
# This would allow more than one app. to use it if necessary
# In an attempt at consistency, all tweets from Amarok are prefixed
# with {rok} to allow filtering etc. if needed.
#
echo "{rok} $notification" > ~/.tweetsig
#
# Tweet it to the world.
# In my case I don't want to flood with too many messages
# so I give it 10 minutes before trying again
#
twidge update < ~/.tweetsig
sleep 600
fi
done
Pretty self-explanatory. Change the "sleep 600" or remove it if you want to keep your audience more thoroughly up to date.
To turn this into an Amarok script, all that's necessary is to tar it up according to a naming convention:
tar cvf NowPlayingTweet.amarokscript.tar NowPlayingTweet
Then in Amarok, use the Script Manager to browse to the newly tar'ed script, install it, and run it.
Not perfect, but suited to my purpose. With a bit more time, perhaps an environment variable for the interval I tweet what's playing, and I'd prefer it only to tweet those I've finished listening to, not stuff I decide to skip past, but that'll do for now.
No comments:
Post a Comment