Totally Stealing Your Music at OSCON
OK, I am not stealing music, just recording what's in your shared playlist. I load your shared playlist in iTunes, and then Mac::Glue iterates over it and stuffs the data in MySQL. Then later I can do something interesting with the data.
Slash::Test provides my DB API. So if you don't have Slash installed on your Mac, you're kinda hosed. But you can drop in your own data store code.
Of course, as many people at OSCON know, the network has issues. I can't load up most of the iTunes playlists out there. Sucks. So far I've seen maybe 40 or more, but I've only been able to get about a dozen. Sucks, I say!
Slash::Test provides my DB API. So if you don't have Slash installed on your Mac, you're kinda hosed. But you can drop in your own data store code.
Of course, as many people at OSCON know, the network has issues. I can't load up most of the iTunes playlists out there. Sucks. So far I've seen maybe 40 or more, but I've only been able to get about a dozen. Sucks, I say!
#!/usr/local/bin/perl
use warnings;
use strict;
use Mac::Glue ':all';
use Slash::Test;
my $itunes = new Mac::Glue 'iTunes';
my $slashdb = getCurrentDB();
my $shares = $itunes->obj(sources => whose(kind => equals => enum('shared library')));
for my $share ($shares->get) {
my $sharename = $share->prop('name')->get;
print $sharename, "\n";
my $tracks = $share->obj(tracks => playlist => 1);
my $i = 0;
for my $track ($tracks->get) {
my($artist, $album, $name) =
map { $track->prop($_)->get || '' }
qw(artist album name);
$slashdb->sqlInsert('oscontunes', {
sharename => $sharename,
artist => $artist,
album => $album,
name => $name
}, { ignore => 1 });
unless (++$i % 100) {
print $i, "\n";
}
}
}
__END__
CREATE TABLE oscontunes (
id mediumint UNSIGNED NOT NULL auto_increment,
sharename VARCHAR(255) NOT NULL,
artist VARCHAR(255) DEFAULT '' NOT NULL,
album VARCHAR(255) DEFAULT '' NOT NULL,
name VARCHAR(255) DEFAULT '' NOT NULL,
PRIMARY KEY (id),
KEY stuff (sharename, artist, album, name)
) TYPE=InnoDB;
Leave a comment