Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

interface to Philips GoGear mp3 player

by domm (Chaplain)
on Dec 16, 2005 at 22:18 UTC ( [id://517384]=CUFP: print w/replies, xml ) Need Help??

(Crossposted from use.perl.)

Two days ago I bought a Philips GoGear mp3 player. It's coming with 526MB flash which can be extended by a gig if you insert the right memory card. It has line-in with direct encoding and is using regular batteries (as opposed to built in custom ones, which all harddisk based player seem to use)

(side note: I ditched my old Sony MiniDisc recored in favour of mp3 because it's read/write head broke one week after the warranty ended and Sony wanted 89 euros for a repair. Suckers. (side side note: so my next notebook isn't going to be a Sony Vaio Subnotebook))

Anyway, this GoGear thing is quite decent, but it has one major drawback (as most players seem to have). It needs special software to load mp3s onto it. In this case, Windows Media Player. Yuck!

But some googling revelead that the player uses an SQLite DB to store metadata, and that one can fill this DB with other tools than WMP. Yay!

So after some looking at horrendous DB schemas like "CREATE TABLE artistTable (iArtistId INTEGER PRIMARY KEY,cArtistName VARCHAR(100))" I managed (instead of working in CPANTS) to hack together a small script that generates a nice and working database:

#!/usr/bin/perl use strict; use warnings; use MP3::Info (); use DBI; use File::Spec::Functions; use File::Copy; # setup my $gogear_mount=$ARGV[0] || '/mnt/gogear'; my $gogear_base=catdir($gogear_mount,qw(_system media audio)); my $gogear_db=catfile($gogear_base,'MyDb'); my $local_db='./MyDb'; copy($gogear_db,$local_db) || die "Cannot copy $gogear_db to $local_db +"; # working with a file on harddisk (as opposed to via usb) is /so/ +much faster my $dbh=DBI->connect("dbi:SQLite:$local_db",{RaiseError=>1}); # delete old entries $dbh->do("delete from artistTable"); $dbh->do("delete from albumTable"); $dbh->do("delete from songTable"); # store info on all mp3s into sqlite db opendir(DIR,$gogear_base) || die "Cannot read $gogear_base: $!"; while (my $f=readdir DIR) { next unless $f=~/\.mp3$/; my $info=MP3::Info->new(catfile($gogear_base,$f)); print '+'.$info->title.' ('.$info->artist.")\n"; $dbh->do("insert into songTable (cSongTitle,iArtistId,iAlbumId,ITr +ackNr,iTrackLength,cFileName,iDirId,iGenreId,iBitRate,iFileSize,iMedi +aType) values (?,?,?,?,?,?,?,?,?,?,?)",undef, $info->title,find_or_create('artist','name',$info->artist),fin +d_or_create('album','title',$info->album),$info->tracknum,int($info-> +secs),$f,4,12,$info->bitrate,$info->size,4); } # move local copy back to GoGear move($local_db,$gogear_db) || die "Cannot move local copy $local_db ba +ck to GoGear ($gogear_db)"; # find or create an artist or album sub find_or_create { my ($table,$fld,$value)=@_; my $TableId='i'.ucfirst($table).'Id'; my $TableFld='c'.ucfirst($table).ucfirst($fld); $table.='Table'; if (my $id=$dbh->selectrow_array("select $TableId from $table wher +e $TableFld=?",undef,$value)) { return $id; } else { $dbh->do("insert into $table ($TableFld) values (?)",undef,$va +lue); return $dbh->func('last_insert_rowid'); } }
svn repository

It's lacking docs and tests, but is quite understandable, I hope. BTW, there's a python 'script' here that does the same (and a bit more, namely playlist handling) in 459 lines (instead of my 54 lines).

I might turn this into a Catalyst/DBIc::Class-based app to manage my soon-to-be-existing collection of mp3s (to bad that there isn't a ripper for vinyl...). In my copious free time. Haha..

-- #!/usr/bin/perl for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://517384]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-24 22:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found