Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Journal of LTjake (4001)

Friday April 25, 2008
09:00 PM

Import Amarok stats into Rhythmbox

[ #36246 ]

I've been using Ubuntu since Dapper was released. As Hardy is the next LTS release, I decided now would be a good time to blow the whole thing away and start fresh. At the same time, I thought I could give rid of some KDE-based software I've been using and stick to a strictly Gnome environment.

I've been using Amarok as my media player, but, as stated above, that doesn't jive with a pure Gnome setup. By default Rhythmbox is installed. I can import all of my tunes in no problem, but I'm missing some play stats.

Given my old Amarok database, which is just an SQLite database, and a Rhythmbox database, which is a simple XML file, with freshly imported tunes I was able to write a script to pull out some of my old data including: rating, import date, last play date and play count. NB: Rhythmbox ratings don't understand half-star ratings, though it doesn't complain.

Usage: rhythmdb.xml collection.db

use strict;
use warnings;

use XML::Simple;
use DBI;
use URI;

my $xml = shift;
my $data = XMLin( $xml, KeepRoot => 1, ForceContent => 1 );

my $dbh = DBI->connect( 'dbi:SQLite:dbname=' . shift, undef, undef );
my $sth = $dbh->prepare( 'select rating, playcounter, createdate, accessdate from statistics where url = ?;' );

for my $row ( @{ $data->{ rhythmdb }->{ entry } } ) {
    my $mp3 = URI->new( $row->{ location }->{ content } );

    next unless $mp3->scheme eq 'file';

    $sth->execute( '.' . $mp3->file );

    my $dbrow = $sth->fetchrow_hashref;
    $row->{ rating }->{ content } = $dbrow->{ rating } / 2;
    $row->{ 'play-count'}->{ content } =  ( $row->{ 'play-count'}->{ content } || 0 ) + $dbrow->{ 'playcounter' };
    $row->{ 'first-seen' }->{ content } = $dbrow->{ 'createdate' };
    $row->{ 'last-seen' }->{ content } = $dbrow->{ 'accessdate' };

XMLout( $data, KeepRoot => 1, XMLDecl => 1, OutputFile => $xml );

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.