Created
August 22, 2012 04:33
-
-
Save mamemomonga/3422289 to your computer and use it in GitHub Desktop.
library.ymlからArtist Album Name TrackNumberをキーにしてiTunesLibraryを設定する
This file contains 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 | |
# library.ymlからArtist Album Name TrackNumberをキーにしてiTunesLibraryの | |
# Rating PlayedCount DateAdded DateAdded PlayedDate を設定する。 | |
# 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=YAML::XS::LoadFile('library.yml'); | |
my %mf; | |
foreach my $dat(@{$data}) { | |
my $ms=makehash($dat); | |
$mf{$ms}=$dat; | |
} | |
my $mainLibrary = $iTunesApp->LibraryPlaylist; | |
my $tracks = $mainLibrary->Tracks; | |
my $numTracks = $tracks->Count; | |
for(my $i=1;$i<=$numTracks;$i++) { | |
printf("Processing 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->{$_}"; | |
} | |
my $ms=makehash(\%data); | |
if(my $md=$mf{$ms}) { | |
# say "$ms"; | |
foreach(qw( Rating PlayedCount DateAdded DateAdded PlayedDate )) { | |
$trackItem->{$_}=$md->{$_}; | |
# say "$_: $md->{$_}"; | |
} | |
# say ""; | |
} else { | |
# say "unmatch"; | |
} | |
} | |
print "\n\n"; | |
sub makehash { | |
my $d=shift; | |
return "$d->{Artist}#$d->{Album}#$d->{Name}#$d->{TrackNumber}"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment