Created
October 21, 2011 15:59
-
-
Save eFrane/1304202 to your computer and use it in GitHub Desktop.
Convert iTunes Music Library.xml path locations
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/php | |
<?php | |
/** | |
Convert iTunes Music Library.xml path locations | |
usage: convert.php library.xml old_library_path new_library_path | |
converted library is written to stdout | |
old and new library paths have to include trailing slashes and | |
lead to the corresponding iTunes Media directories | |
works for Windows and Mac iTunes Libraries | |
To reload the iTunes Media Library from the converted XML: | |
http://support.apple.com/kb/ht1451 | |
**/ | |
$newlib = $argv[2]; | |
$oldlib = $argv[3]; | |
$lib = file_get_contents($argv[1]); | |
$match1 = '/(Music Folder<\/key><string>)([[:print:]]+)(<\/string>)/'; | |
$lib = preg_replace($match1, '$1'.$path.'$3', $lib); | |
$oldlib = str_replace(array('[', '(', ')', ']', '.', '/'), array('\[', '\(', '\)', '\]', '\.', '\/'), $oldlib); | |
$match2 = '/(Location<\/key><string>)('.$oldlib.')([[:print:]]+)(<\/string>)/'; | |
$lib = preg_replace($match2, '$1'.$path.'$3$4', $lib); | |
print $lib; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment