############################################################################### # # itunes_vidkind.pl # # This script will let you change the video type of multiple files # (in a playlist you select) # # Copyright (C) 2007 Robert Jacobson # written by: Robert Jacobson (http://mysite.verizon.net/teridon/itunesscripts) # Last Updated: 23 Jan 2007 # Version 1.0 # # This script is GPL v2. see http://www.gnu.org/copyleft/gpl.html # ############################################################################### use File::Basename; my $PROGNAME = basename($0); my $VERSION = "1.0"; my $AUTHOR = "Robert Jacobson"; my $HOMEPAGE = "http://mysite.verizon.net/teridon/"; my $YEAR = 2007; my $GNU_URL = "http://www.gnu.org/copyleft/gpl.html"; { print "**************************************************************\n" . "$PROGNAME version $VERSION, Copyright (C) $YEAR $AUTHOR\n" . "Visit $HOMEPAGE for updates\n" . "$PROGNAME comes with ABSOLUTELY NO WARRANTY;\n". "This is free software, and you are welcome\n" . "to redistribute it under certain conditions\n" . "for details see $GNU_URL.\n" . "**************************************************************\n" . "\n" ; } use strict; use Win32::OLE; use Data::Dumper; # Create a signal handler to destroy the iTunes object # in case our program quits before the end use sigtrap 'handler', \&quit, 'normal-signals'; ## Create the OLE Object my $iTunes = Win32::OLE->new('iTunes.Application') or die Win32::OLE->LastError(); # Check version first! my $version = $iTunes->Version; if ($version !~ /^(7|8)/) { print "Sorry, this script requires iTunes 7 or 8\n"; print "Hit Enter to exit "; my $trash = ; quit(); } # Get the possible sources my $sources = $iTunes->Sources(); my $sourcesCount = $sources->Count(); my $source = ''; my $sourceKind = ''; my @vidkinds = qw/ None Movie MusicVideo TVShow /; my $n = 1; print "\n"; for my $i (1..3) { print "$i. $vidkinds[$i]\n"; } print "\n"; my $kind = "x"; while ( $kind !~ /^[1-3]$/ ) { print "Change videos to what kind? "; chomp ($kind = ); } # For each source, figure out kind for ($n = 1; $n <= $sourcesCount; $n++) { $source = $sources->Item($n); $sourceKind = $source->Kind(); # print "source no. " . $n . " is "; # print $sourceKind . " -- "; if ($sourceKind == 0) { print "Unknown Source\n"; } if ($sourceKind == 1) { print "Library Source\n"; # Get the playlists in the Library my $playlists = $source->Playlists(); my $num_playlists = $playlists->Count(); print "There are $num_playlists playlists\n"; # For each playlist, show the name and number of tracks for (my $j = 1 ; $j <= $num_playlists; $j++) { my $playlist = $playlists->Item($j); my $playlist_name = $playlist->Name(); print "\t$j : $playlist_name\n"; } print "Enter comma-separated playlist numbers: "; chomp (my $nums = ); my @nums = split(/,/ , $nums); for my $i (@nums) { my $playlist = $playlists->Item($i); my $playlist_name = $playlist->Name(); print "You selected $playlist_name\n"; my $tracks = $playlist->Tracks; my $num_tracks = $tracks->Count(); print "\t$num_tracks tracks\n"; my %seen; # Get all the tracks in the playlist for (my $k = 1 ; $k <= $tracks->Count ; $k++ ) { #print "num: " , $num_tracks , " Count: ", $tracks->Count , " k: ", $k , "\n"; my $track = $tracks->Item($k); my $track_kind = $track->Kind(); if ($track_kind == 1) { # change video kind $track->{'VideoKind'} = $kind; if ( Win32::OLE->LastError() != 0) { print "return value: " . Win32::OLE->LastError() . "\n"; } else { print "Changed kind of " . $track->Name . " to " . $vidkinds[$track->VideoKind()], "\n"; } } } } } } # Destroy the object. Otherwise zombie object will come back # to haunt you quit(); sub quit { # This destroys the object undef $iTunes; exit; }