Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
iTunes Connect screenshot upload script
#!/usr/bin/php
<?php
/*
Usage (at your own risk!):
1. Work on screenshots (try this Sketch template: http://bit.ly/1G9xstD)
2. Setup:
alias iTMSTransporter="/Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/MacOS/itms/bin/iTMSTransporter"
3. Grab latest ITMS data:
iTMSTransporter -m lookupMetadata -u email@address.com -p password -vendor_id APPVENDORID -destination YourApp.itmsp
4. Open up the metadata.xml and remove the fields you don't want to change - this is probably going to be the currently-live
version, and maybe the product info at the bottom.
5. Export all the screenshots into the itmsp package folder
6. Run this tool (update_itmsp_screenshots.php YourApp.itmsp)
7. Check that everything looks okay
8. Verify
iTMSTransporter -m verify -u email@address.com -p password -f YourApp.itmsp
9. Upload
iTMSTransporter -m upload -u email@address.com -p password -f YourApp.itmsp
*/
// This maps between the device/language identifiers iTunes Connect uses, and the format of the screenshot filenames
$DEVICES = array('iOS-iPad' => 'iPad',
'iOS-3.5-in' => 'iPhone 3.5"',
'iOS-4-in' => 'iPhone 4"',
'iOS-4.7-in' => 'iPhone 4.7"',
'iOS-5.5-in' => 'iPhone 5.5"');
$LANGUAGES = array('en-US' => 'English',
'de-DE' => 'German',
'it-IT' => 'Italian',
'ja-JP' => 'Japanese',
'da-DK' => 'Danish',
'el-GR' => 'Greek',
'es-ES' => 'Spanish',
'fr-FR' => 'French',
'ko-KR' => 'Korean',
'nl-NL' => 'Dutch',
'pt-BR' => 'Brazilian Portuguese',
'ru-RU' => 'Russian',
'sv-SE' => 'Swedish',
'tr-TR' => 'Turkish',
'cmn-Hans' => 'Chinese');
$INDENT = ' ';
$DEFAULT_LANGUAGE = 'en-US';
// First argument: path to itmsp
$itmsp=$argv[1];
if ( !$itmsp || !file_exists($itmsp) ) {
echo "\"$itmsp\" not found";
exit(1);
}
// Second argument, if present: comma-separated device list (or '.' for default)
if ( isset($argv[2]) && $argv[2] != '.' ) {
$selectedDevices = explode(",", $argv[2]);
$DEVICES = array_intersect_key($DEVICES, array_flip($selectedDevices));
}
// Third argument, if present: comma/separated language list (or '.' for default)
if ( isset($argv[3]) && $argv[3] != '.' ) {
$selectedLanguages = explode(",", $argv[3]);
$LANGUAGES = array_intersect_key($LANGUAGES, array_flip($selectedLanguages));
}
$xmlpath = "$itmsp/metadata.xml";
$xmlcontents = file_get_contents($xmlpath);
// Any other languages not in $LANGUAGES?
if ( preg_match_all('/<locale name="([^"]+)"/', $xmlcontents, $matches) ) {
foreach ( $matches[1] as $lang ) {
if ( !isset($LANGUAGES[$lang]) ) {
$LANGUAGES[$lang] = $lang;
}
}
}
foreach ( $LANGUAGES as $languageCode => $languageName ) {
$screenshots = "";
foreach ( $DEVICES as $device => $devicePrefix ) {
$prefix = "$languageName $devicePrefix";
for ( $index = 1; $index <= 5; $index++ ) {
$filename="$prefix $index.jpg";
$cleaned_filename = preg_replace("/[\/: \"]/", "-", $filename);
if ( file_exists("$itmsp/$filename") ) {
rename("$itmsp/$filename", "$itmsp/$cleaned_filename");
}
$fullpath="$itmsp/$cleaned_filename";
if ( !file_exists($fullpath) ) {
if ( $languageCode != $DEFAULT_LANGUAGE ) {
$filename=$LANGUAGES[$DEFAULT_LANGUAGE]." $devicePrefix $index.jpg";
$cleaned_filename = preg_replace("/[\/: \"]/", "-", $filename);
if ( file_exists("$itmsp/$filename") ) {
rename("$itmsp/$filename", "$itmsp/$cleaned_filename");
}
if ( file_exists("$itmsp/$cleaned_filename") ) {
echo "Using $DEFAULT_LANGUAGE instead of $languageCode for $device $index ($fullpath)\n";
$fullpath = "$itmsp/$cleaned_filename";
}
}
if ( !file_exists($fullpath) ) {
echo "Skipping $languageCode $device $index ($fullpath)\n";
continue;
}
}
$size = filesize($fullpath);
$checksum = md5_file($fullpath);
$screenshots .= "\n$INDENT <software_screenshot display_target=\"$device\" position=\"$index\">";
$screenshots .= "\n$INDENT <size>$size</size>";
$screenshots .= "\n$INDENT <file_name>$cleaned_filename</file_name>";
$screenshots .= "\n$INDENT <checksum type=\"md5\">$checksum</checksum>";
$screenshots .= "\n$INDENT </software_screenshot>";
}
}
$screenshots .= "\n$INDENT";
$xmlcontents = preg_replace("@(<locale name=\"$languageCode\">.*?<software_screenshots>).*?(</software_screenshots>)@ms",
'$1'.$screenshots.'$2',
$xmlcontents);
}
rename($xmlpath, "$xmlpath.backup");
$f = fopen($xmlpath, "w");
fwrite($f, $xmlcontents);
fclose($f);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment