Showing posts with label twidge. Show all posts
Showing posts with label twidge. Show all posts

Friday, 20 February 2009

Bashcasting Your Playlist

After some reflection, a bit of swearing at the Bash reference, which may be canonical but is relatively unhelpful, an easy solution for Ubuntu users to tweet their tune of choice. None-Linux users are out of luck, sorry but you asked for it.

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.

Wednesday, 18 February 2009

Who cares what music I listen to anyway?

Or: How To Stop Spamming Twitter With Your Playlist.

Although the NowPlayingTweet script / Twidge / Amarok combo basically works well enough, there are a couple of issues that mean I'm leaving it off just now, namely the...

Easy Technical Issue

There are a couple of glitches that mean the odd tweet is duplicated, appears blank etc. Scanning the code snippet I pinched, this just looks like the way a change in status (i.e. track changing) is detected fires too often. This manifests itself as duplicate tweets, the occasional contentless tweet etc.

This is readily addressed by brushing up on me Bash scripting and sorting it out and is of no further concern here.

However that still leaves the...


Slightly Harder Social Issue

If I sit and listen to music all day (which I often do) that's around 15 songs an hour, for a total of around 120 tweets per day.

This seems like a lot to me, in fact a potentially very irritating number for anyone following. Hard to know. So I want to strike a balance between spamming twitter with junk and tweeting the odd message that might have someone say "Ah! I could stand a bit of Burt Bacharach myself" or "He'll be cutting his wrists if he's not careful"


The two ways I thought this could be achieved are:

Tweet on change of Album or Artist (or either or both)

I listen to a lot of complete albums, particularly as an aid to concentration when I work. This would mean one tweet every 30 mins or so which seems reasonable.

The downsides to this are that it squashes a bit of the serendipity of seeing a song-title you've long forgotten or are intrigued by and, if you change on Artist, compilation albums still produce a flurry of tweets (a chorus?)

Tweet every N minutes

So take an interval of, say, 10 / 15 minutes and tweet all of the Artist / Album / Track info. This seems like a better option, if a bit more complicated to script. The number of tweets comes down to something passable, but you still get the serendipitous effect that tweeting on change of Album lacks.



The second gets my vote - and my time when it's available - unless any other inspiration strikes.

Tuesday, 17 February 2009

Twitter and Amarok

Against my better judgement I'm playing around with twitter (mrsean2k, 1 (spam) follower) ETA: some non-spam followers, woohoo, electronic chums!

Although I haven't "got" it yet, it's got me dipping my toe in the water with a few things I've meant to get round to, and this is as a result of wanting to have Amarok post my "Now Playing" information as a tweet.

To cut a long story short, the sequence of events is:

  • Install the command line twitter client twidge essentially this will let you tweet from a batch file
  • Get a copy of the Now Playing Signature script
  • Amend the script so that the generated signature is a single line, and so that after the sig is generated, twidge will tweet it automatically
  • Install and run the script in Amarok

I'll write these up in a bit more (or at least some) detail shortly, but the upshot is that my song choices are automatically posted as tweets. Some tidying to do, and I think I'd be tempted to alter it so that it only tweets on a change of artist / album as opposed to every track, but it was surprisingly easy to do.