Scrobbling from RadioDJ (redux)

A couple days ago, I wrote a post about a quick and dirty–and half-working–solution to scrobbling tracks from RadioDJ… After further experimentation, I’ve found a cleaner automated way to do so. The method I’m employing scrobbles every hour, and reports the previous hour’s worth of tracks.

Additional software needed:

QTscrobbler–Command Line version available at Sourceforge

First, we need to build a compatible log-file–we’ll start to do this using the mySQL command line (assuming you’re using mySQL for your RadioDJ database–mine came packaged with all the other goodies in XAMPP). Immediately following is just the query, full-blown command line operation will be in the example batch file [scroll down for that hot goodness].

SELECT `artist`, `album`, `title`, `track_no`, cast(duration as decimal(10,0)), 'L' AS `listened_dummy_field`, UNIX_TIMESTAMP(date_played) FROM `history` WHERE `song_type`='0' AND `date_played` > DATE_ADD( NOW(), INTERVAL -1 HOUR ) ORDER BY `date_played` DESC INTO OUTFILE 'C:/RadioDJ/Media/last.fm/part.scrobbler.log' FIELDS TERMINATED BY '\t';

…as you can see, the query is dumping the info into a [tab-delimited] file; you’ll also see that for my own sanity, I’ve got it dumping into a directory created just for this, under the RadioDJ folder. Adjust for your own setup, of course. 😉

…also, you’ll see that the query is creating a dummy column–this is to satisfy QTscrobbler’s needs–it’s picky, whereas other scrobbling clients aren’t… and, yes, I’m going ahead and making mySQL do the UNIX time conversion–I had some issues when I tried to let other clients do the conversion for me.

Next, we need to put the audioscrobbler log file headers into the final part of the log file. (I did mention that QTscrobbler is a little picky, didn’t I?) For that, I created a static file in the aforementioned directory. Contents of that file–which I named “head.scrobbler.log”–is as follows:

#AUDIOSCROBBLER/1.0
#TZ/UTC
#CLIENT/RadioDJ

Now, we have to put the two *.scrobbler.log files together–I do this by dumping the head- file and then the part- file into the final .scrobbler.log file. [See the batch, further down this post.] With all that done, we can now–finally–scrobble the log file:

scrobbler-0.11.exe -c qtscrob.ini -f -l c:\radiodj\media\last.fm

NOTE: you’ll need a config file for QTscrobbler to use. I’m not entirely sure of what you can use or include in the config file–I ended up toying with the GUI version in order to create one that works. As an example, here’s my config file–minus the username and pass-hash:

[application]
version=0.11
utc_offset=0
tz_override=false
auto_open=true
del_apple_playlist=false
display_utc=false
mru=@Invalid()

[Last.fm]
enabled=true
username=YOUR_USERNAME_HERE
password_hash=MD5_HASH_OF_YOUR_PASSWORD

…ready to see the batch pulling all this off? I hope so, ’cause here it is:

@ECHO OFF
CD c:\radiodj\media\last.fm

::get_log
c:\xampp\mysql\bin\mysql.exe -e "SELECT `artist`, `album`, `title`, `track_no`, cast(duration as decimal(10,0)), 'L' AS `listened_dummy_field`, UNIX_TIMESTAMP(date_played) FROM `history` WHERE `song_type`='0' AND `date_played` > DATE_ADD( NOW(), INTERVAL -1 HOUR ) ORDER BY `date_played` DESC INTO OUTFILE 'C:/RadioDJ/Media/last.fm/part.scrobbler.log' FIELDS TERMINATED BY '\t';" --user=MYSQL_USERNAME_HERE --password=MYSQL_PASSWORD_HERE radiodj161

::build_log
type head.scrobbler.log>>.scrobbler.log
type part.scrobbler.log>>.scrobbler.log
del part.scrobbler.log

::scrobble
scrobbler-0.11.exe -c qtscrob.ini -f -l c:\radiodj\media\last.fm

::end
exit

To automate all this, I’m attempting to take advantage of RadioDJ’s ability to run commands as events. Currently, I’ve got an event set to run the batch hourly at xx:05:00. A tip to doing this–after you select RadioDJ to run cmd.exe, format the execution of the batch file [in the arguments field] like this:

cmd.exe /c start "scrobble" /min C:\RadioDJ\Media\last.fm\scrobble.bat ^& exit

…and you’ll be rewarded with a window that pops minimized, runs the batch, and exits when it’s finished!

One thought on “Scrobbling from RadioDJ (redux)”

Leave a Reply

Your email address will not be published. Required fields are marked *