Computers: July 2004 Archives
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;
The iPod has a Name That Tune game in it, where it shows you a list of five songs, and it plays a song from your iPod, and you guess which one it is. Here's a perl/iTunes version. It has a crummy UI, and it doesn't keep score, but the guts all seem to work. Just type the number of the song you think is playing.
One slightly dangerous part is that it sets the "start" time of the file, so that it begins playing in the middle of the song, then it sets it back. It could, of course, fail to set it back if there's a crash of some kind. Oh, the risks we take in life!
One slightly dangerous part is that it sets the "start" time of the file, so that it begins playing in the middle of the song, then it sets it back. It could, of course, fail to set it back if there's a crash of some kind. Oh, the risks we take in life!
#!/usr/local/bin/perl
use strict;
use warnings;
use Mac::Glue ':all';
use Term::ReadKey;
my $itunes = new Mac::Glue 'iTunes';
# interval between guesses
my $guess_sleep = 3;
# tracks to guess
my $guesses = 5;
# define the songs you want to get
my $any = $itunes->obj(track => gAny, tracks => whose(bit_rate => g_e => 128), playlist => 1);
play_game() for 0..2;
exit;
sub play_game {
my(@tracks, %tracks);
until (@tracks == $guesses) {
my $track = $any->get;
my($artist, $name, $duration, $start) = map { $track->prop($_)->get || '' }
qw(artist name duration start);
next unless $artist && $name;
next if $tracks{$artist, $name}++;
push @tracks, [$track, @tracks + 1, $artist, $name, $duration, $start];
}
my $selected = my $winner = int rand(@tracks);
$winner += 1;
my $playing = $tracks[$selected];
my $newstart = int($playing->[4]/3 + rand($playing->[4]/10) - rand($playing->[4]/10));
if ($newstart > $playing->[4]) {
$newstart = int($playing->[4] - $guesses*$guess_sleep);
$newstart = 0 if $newstart < 0;
}
$playing->[0]->prop('start')->set(to => $newstart);
$playing->[0]->play;
print_tracks(\@tracks);
ReadMode(4);
OUTER: while (@tracks > 1) {
my $now = time();
INNER: while (($now + $guess_sleep) > time()) {
my $c = ReadKey(-1);
next unless $c && $c =~/\d/;
if ($c == $winner) {
print "Right-o!\n\n\n";
last OUTER;
} else {
last INNER;
}
}
my $remove = int rand(@tracks);
next if $remove == $selected;
$selected-- if $remove < $selected;
splice(@tracks, $remove, 1);
print_tracks(\@tracks);
}
ReadMode(0);
$itunes->stop;
$playing->[0]->prop('start')->set(to => $playing->[5]);
}
sub print_tracks {
my($tracks) = @_;
for (@$tracks) {
print "$$_[1]. $$_[2], '$$_[3]'\n";
}
print "\n\n";
}
I've done something like this before, but I figured others might find this to be especially useful.
iTunes Music Store has some of the 9/11 Commission stuff available for free. But the artist is "Unknown", the Genre is "Classical", and the album name and track name are both of the form "9-11 Commission Hearings: $foo", where $foo is something like "NYC Panel Three (5/18/04)". Also, it has the spurious "Track 1 of 1" and "Disc 1 of 1". At least the year (2004) was correct.
So I selected all the tracks in iTunes and changed the genre to "Audiobooks" and the artist and album to "9-11 Commission Hearings", and removed the track and disc information.
Then I wanted to remove the "9-11 Commission Hearings: " from the beginning of the track name, but by hand that's a pain, since there's 38 tracks. Perl and Mac::Glue to the rescue. Remember, change the info in iTunes first, or else modify the script to match the proper "album" value, perhaps by "contains" or "begins_with" instead of "equals".
(For bonus points: rewrite the script below to order the tracks by date information. Also, consider making the artist the name of the speaker or panel. Also, consider doing everything I did by hand in iTunes with this script.)
iTunes Music Store has some of the 9/11 Commission stuff available for free. But the artist is "Unknown", the Genre is "Classical", and the album name and track name are both of the form "9-11 Commission Hearings: $foo", where $foo is something like "NYC Panel Three (5/18/04)". Also, it has the spurious "Track 1 of 1" and "Disc 1 of 1". At least the year (2004) was correct.
So I selected all the tracks in iTunes and changed the genre to "Audiobooks" and the artist and album to "9-11 Commission Hearings", and removed the track and disc information.
Then I wanted to remove the "9-11 Commission Hearings: " from the beginning of the track name, but by hand that's a pain, since there's 38 tracks. Perl and Mac::Glue to the rescue. Remember, change the info in iTunes first, or else modify the script to match the proper "album" value, perhaps by "contains" or "begins_with" instead of "equals".
(For bonus points: rewrite the script below to order the tracks by date information. Also, consider making the artist the name of the speaker or panel. Also, consider doing everything I did by hand in iTunes with this script.)
#!/usr/local/bin/perl
use strict;
use warnings;
use Mac::Glue ':all';
my $itunes = new Mac::Glue 'iTunes';
my $tracks = $itunes->obj(
tracks => whose(album => equals => '9-11 Commission Hearings'),
playlist => 1
);
for my $track ($tracks->get) {
my $name = $track->prop('name');
my $value = $name->get;
(my $new = $value) =~ s/^9-11 Commission Hearings://;
$name->set(to => $new) unless $new eq $value;
}
I get weird submissions to use.perl.org sometimes. By "weird" I mean submissions devoid of context and unrelated to any topic on the site. Here's one I got tonight (only the name has been changed). It has all the standard elements of such submissions, including the common horrible grammar and spelling. Practical joke, moron, or e-mail address harvester? You be the judge!
Athesist the truth
[redacted] writes "Athesist people are not scared of faith we just dont believe in 'god' as you say I mean how do you believe in somethning you cant see and dont tel me that faith bul shit I dont care maybe you need to get to know a real athesist person before you judge ok? bc you are not explaing shit thats right you have no right to judge us it even says so in the book of lies that you cal the 'bible' wel when you have a clue what it realy is e mail me bc it will be a joy to read your e mail."
Athesist the truth
[redacted] writes "Athesist people are not scared of faith we just dont believe in 'god' as you say I mean how do you believe in somethning you cant see and dont tel me that faith bul shit I dont care maybe you need to get to know a real athesist person before you judge ok? bc you are not explaing shit thats right you have no right to judge us it even says so in the book of lies that you cal the 'bible' wel when you have a clue what it realy is e mail me bc it will be a joy to read your e mail."
I got a copy of Hackers and Painters from gnat/O'Reilly at WWDC, and starting reading it. The whole first chapter was basically, for me, "The Top Reason Why We Are Going to Homeschool Our Children." It describes very well some of the main reasons why we won't subject our children to the public school system: it's a gigantic waste of time where children are thrown together for the main purpose of keeping them out of the adults' hair, where you learn little and are challenged less, and where only the rare person can not fit in socially and come out of it without scarring.
Some people say public school teaches kids about the real world; I don't know what kind of fantasy school they went to, or what kind of miserable life they have led since school, but for me, jr. high and high school were the lowllights of my entire life.
And it's not merely that I was an outcast, like many of us nerds. I was, but I was one of the seemingly rare kids who got over it by seventh grade, and decided to not give a damn what anyone else thought. It's not that the experience was exceptionally negative (though it was), it's that it wasn't positive. I could have skipped 95% of what happened in high school and I'd not only not have missed anything, but I'd have been able to fill my life with more good things: more learning, more experiences, more friends, more whatever.
Bottom line: school sucks. I'll help the overcrowding problem by keeping my kids out of it.
Some people say public school teaches kids about the real world; I don't know what kind of fantasy school they went to, or what kind of miserable life they have led since school, but for me, jr. high and high school were the lowllights of my entire life.
And it's not merely that I was an outcast, like many of us nerds. I was, but I was one of the seemingly rare kids who got over it by seventh grade, and decided to not give a damn what anyone else thought. It's not that the experience was exceptionally negative (though it was), it's that it wasn't positive. I could have skipped 95% of what happened in high school and I'd not only not have missed anything, but I'd have been able to fill my life with more good things: more learning, more experiences, more friends, more whatever.
Bottom line: school sucks. I'll help the overcrowding problem by keeping my kids out of it.
In a fit of blind rage last night, I recorded Johnny Got Suspended, an update to the original by The Zambonis, wherein a young lad is suspended for wearing an Islander Suck t-shirt; the new version features more appropriate team names.
I thought it would be funny (if I made the music a little better) to release the GarageBand package so other people could make their own versions, perhaps with a license that says you may use it for any purpose so long as it is not for commercial gain and you don't make any Boston teams the target of the suckage.
I thought it would be funny (if I made the music a little better) to release the GarageBand package so other people could make their own versions, perhaps with a license that says you may use it for any purpose so long as it is not for commercial gain and you don't make any Boston teams the target of the suckage.
I am a fan of the TV shows Oz, Homicide, and Law and Order (all three). Homicide and Oz -- both off the air now -- featured the team of Tom Fontana and Barry Levison for writing and producing. I don't know what Law and Order had in common on that level, but many cast members of Oz are also on Law and Order (the female cop on Criminal Intent, the male cop on Special Victims Unit, the psychiatrists on both SVU and the original L&O, as well as many guests). And of course Richard Belzer's character, Detective John Munch, was on both Homicide and is now on SVU.
So Levinson/Fontana have a new series out, The Jury, where instead of looking behind the scenes at the cops, or the lawyers, or the criminals, you look behind the scenes at the juries. The evidence unveils to the audience as the jurors discuss it, and flashbacks show us some of what happened. It's a pretty good show, if you like the ones I mentioned above. Not as engaging as Oz, maybe, but this is network TV, not HBO.
On this week's episode, "Last Rites" -- because the case involved a murder of a priest during a prison riot -- Oz was well-represented, with thirteen regulars/recurring guests.
One of the witnesses was from Oz, a cop (inmate James Robson), as well as all of the jurors (inmates Dino Ortolani, Bob Rebadow, Poet Jackson, Cyril O'Reily, Kareem Said, and Vern Schillinger; inmate Ryan O'Reily's mother Suzanne Fitzgerald [also Abby from Eight is Enough]; Vern Schillinger's daughter-in-law Carrie Schillinger; the brother and sister of an inmate, Carlos and Margarita Ricardo; Detective Nancy Mears; and the mother of officer Clayton Hughes, Lenore Hughes).
That's a whole lotta Oz.
So Levinson/Fontana have a new series out, The Jury, where instead of looking behind the scenes at the cops, or the lawyers, or the criminals, you look behind the scenes at the juries. The evidence unveils to the audience as the jurors discuss it, and flashbacks show us some of what happened. It's a pretty good show, if you like the ones I mentioned above. Not as engaging as Oz, maybe, but this is network TV, not HBO.
On this week's episode, "Last Rites" -- because the case involved a murder of a priest during a prison riot -- Oz was well-represented, with thirteen regulars/recurring guests.
One of the witnesses was from Oz, a cop (inmate James Robson), as well as all of the jurors (inmates Dino Ortolani, Bob Rebadow, Poet Jackson, Cyril O'Reily, Kareem Said, and Vern Schillinger; inmate Ryan O'Reily's mother Suzanne Fitzgerald [also Abby from Eight is Enough]; Vern Schillinger's daughter-in-law Carrie Schillinger; the brother and sister of an inmate, Carlos and Margarita Ricardo; Detective Nancy Mears; and the mother of officer Clayton Hughes, Lenore Hughes).
That's a whole lotta Oz.