Last active
April 21, 2016 12:13
-
-
Save jjok/3419972 to your computer and use it in GitHub Desktop.
Reformat episode number for EPG XML.
This file contains hidden or 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
<?php | |
try { | |
if(isset($_SERVER['argv'][1])) { | |
$xml_file = $_SERVER['argv'][1]; | |
} | |
else { | |
$xml_file = 'TVGuide.xml'; | |
} | |
if(!is_readable($xml_file)) { | |
throw new Exception("File $xml_file not found."); | |
} | |
$xml = new DOMDocument('1.1', 'UTF-8'); | |
$xml->load($xml_file); | |
foreach($xml->getElementsByTagName('episode-num') as $n => $episode) { | |
$val = $episode->nodeValue; | |
$parts = explode('.', $episode->nodeValue); | |
if(count($parts) != 3) { | |
echo "'$val' is in a different format.", PHP_EOL; | |
continue; | |
} | |
$val = $parts[1]; | |
$episode->nodeValue = str_replace('/', '-', trim($val, ' /')); | |
$episode->setAttribute('system', 'dd_progid'); | |
if($n%10 == 0){ | |
echo '.'; | |
} | |
} | |
$pos = strrpos($xml_file, '.'); | |
$new_file = sprintf('%s_processed%s', substr($xml_file, 0, $pos), substr($xml_file, $pos)); | |
if($xml->save($new_file) !== false) { | |
echo "\n\nFile saved to $new_file\n"; | |
} | |
} | |
catch (Exception $e) { | |
echo $e->getMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment