Skip to content

Instantly share code, notes, and snippets.

@jjok
Last active April 21, 2016 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjok/3419972 to your computer and use it in GitHub Desktop.
Save jjok/3419972 to your computer and use it in GitHub Desktop.
Reformat episode number for EPG XML.
<?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