"; } echo "ini_get('default_charset') ". ini_get('default_charset')."\n"; $writeNewPlaylistFile = true; $outputDir = "newPlaylists"; if ($writeNewPlaylistFile == true) { if (!file_exists($outputDir)) { mkdir($outputDir); } } $time_start = microtime(true); // load up old library, and playlists $oldLibrary = new iTunesLibrary($oldiTunesFile, true, $trackLimit); $time = (microtime(true) - $time_start); printf("Time to load old lib and playlists: %01.3f\n", $time); $time_start = microtime(true); // load up new library, just the tracks $newLibrary = new iTunesLibrary($newiTunesFile, false); $time = (microtime(true) - $time_start); printf("Time to load new lib: %01.3f\n", $time); echo "old lib playlist count: " . $oldLibrary->getPlaylistCount() . "\n"; echo "new lib track count: " . $newLibrary->getCount() . "\n"; echo "old lib track count: " . $oldLibrary->getCount() . "\n"; foreach ($oldLibrary->getPlaylists() as $playlist) { $time_start = microtime(true); if (count($playlist->tracks)>0 && count($playlist->tracks) < $trackLimit) { echo "Playlist Name: $playlist->Name\n"; $newTrackIDs = array(); foreach ($playlist->tracks as $trackID => $trackValues) { // echo "trackID: $trackID, Name = " . $trackValues["Name"] . "\n"; list($id, $location) = $newLibrary->getIDAndLocation($trackID, $trackValues["Name"], $trackValues["Total_Time"], $trackValues["Artist"], $trackValues["Album"]); // echo "newID: $id, new location: $location\n\n"; if (is_null($id) == false) { $newTrackIDs[]=$id; } else{ // echo "OHNO: Could not find new ID for: " . $trackValues["Name"] . "\n"; } } $time = (microtime(true) - $time_start); printf("Time to lookup new data for playlist with %u tracks: %01.3f\n",count($playlist->tracks), $time); // write new xml, need name and trackIds if ($writeNewPlaylistFile == true && count($newTrackIDs)>0) { outputPlaylistFile($playlist->Name, $newTrackIDs); $time = (microtime(true) - $time_start); printf("Time to write new playlist with %u tracks: %01.3f\n",count($playlist->tracks), $time); } } } $time = (microtime(true) - $real_time_start); printf("Total time: %01.3f\n", $time); exit; /** * Get the track name and location for a specific track ID * * @param string $playlistName * @param array $trackIDs * * @return array */ function outputPlaylistFile($playlistName, $trackIDs){ global $outputDir; $playlistName = $playlistName . "_NEW"; $playlistNameFilename = $playlistName . ".xml"; $header = <<< HEAD Tracks HEAD; $mid1 = <<< MID1 Playlists Name MID1; $footer = <<< FOOT FOOT; $mid = <<< MID Description All Items Playlist Items MID; $str = $header; foreach ($trackIDs as $trackID) { $str = $str ."" . $trackID .""; } $str = $str . $mid1 . $playlistName . $mid; // loop through tracks foreach ($trackIDs as $trackID) { $str = $str . "Track ID" . $trackID . ""; } $str = $str . $footer; $filename = "$outputDir/$playlistNameFilename"; if (!$handle = fopen($filename, 'w')) { echo "Cannot open file ($filename)\n"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $str) === FALSE) { echo "Cannot write to file ($filename)\n"; exit; } // echo "Success, wrote to file ($filename)\n"; fclose($handle); } ?>