Created
August 22, 2012 04:32
-
-
Save mamemomonga/3422285 to your computer and use it in GitHub Desktop.
iTunesLibraryからRatingなどを一括抽出し、library.ymlに保存
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# iTunesLibraryからRatingなどを一括抽出し、library.ymlに保存。 | |
# Windows用 Perl 5.10.1 cygwin | |
use 5.10.0; | |
use strict; | |
use warnings; | |
use utf8; | |
use Win32::OLE; | |
use Win32::OLE::Variant; | |
use Encode; | |
use YAML::XS; | |
binmode(STDOUT,":utf8"); | |
$|=1; | |
my $iTunesApp = Win32::OLE->new("iTunes.Application"); | |
my @data; | |
my $mainLibrary = $iTunesApp->LibraryPlaylist; | |
my $tracks = $mainLibrary->Tracks; | |
my $numTracks = $tracks->Count; | |
for(my $i=1;$i<=$numTracks;$i++) { | |
printf("Reading List: %8d (%2.2f%%) \r",$i,($i/$numTracks)*100) if ($i % 10 == 0); | |
my $trackItem=$tracks->Item($i); | |
my %data; | |
foreach(qw( Name Artist Album Genre TrackNumber Location )) { | |
$data{$_}=decode('Shift_JIS',$trackItem->{$_} || ''); | |
} | |
foreach(qw( TrackID Rating PlayedCount )) { | |
$data{$_}=$trackItem->{$_}; | |
} | |
foreach(qw( DateAdded DateAdded PlayedDate )) { | |
$data{$_}="$trackItem->{$_}"; | |
} | |
# say YAML::XS::Dump(\%data); | |
push @data,\%data; | |
} | |
print "\n\n"; | |
YAML::XS::DumpFile('library.yml',\@data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment