Last active
December 27, 2015 13:49
-
-
Save ajslaghu/7336042 to your computer and use it in GitHub Desktop.
updated with json builder for xml stuff.
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
<?php | |
// required: apt-get install apt-get install php5-tidy | |
if (!file_exists('incontxt-download.tidy.xml')) { | |
$config = array( | |
'indent' => true, | |
'clean' => true, | |
'input-xml' => true, | |
'output-xml' => true, | |
'wrap' => false | |
); | |
if (file_exists('incontxt-download.xml')) { | |
$xmlstr = tidy_repair_file('incontxt-download.xml', $config); | |
file_put_contents('incontxt-download.tidy.xml', $xmlstr); | |
} else | |
die('-1'); | |
} | |
$xml = simplexml_load_file('incontxt-download.tidy.xml', null, LIBXML_PARSEHUGE); | |
// lets get the prids of all incontext id's, then you can get the links | |
//<str name="id">KRO_30_93730</str> --> KRO_1605885 (PRID) | |
if (!file_exists('incontxtid2prid.json')) { | |
$data = array(); | |
foreach ($xml->result->doc as $doc) { | |
foreach ($doc->str as $str) { | |
if ($str['name'] != 'id') { | |
continue; | |
} | |
$exp = explode('_', $str); //print_r( $exp); | |
print("Episode lookup " . $str . " exp2:" . ($exp[2])); | |
$prid = file_get_contents('http://getprid.kro.nl/getprid.ashx?episodeid=' . ($exp[2])); | |
print(" PRID:" . $prid . " Result:"); | |
if ($prid == 'Episode not found') { | |
print($prid . " on:" . $str . "\n"); | |
} else { | |
print('Episode found on ' . $str . " with: " . $prid . "\n"); | |
$data[(string) $str] = $prid; | |
} | |
} | |
} | |
$json = json_encode($data); | |
file_put_contents('incontxtid2prid.json', $json); | |
} | |
if (!file_exists('incontxt.json')) { | |
$data = array(); | |
foreach ($xml->result->doc as $doc) { | |
// get id <str name="id">KRO_370_4286</str> | |
$fields = array(); | |
foreach ($doc->str as $str) { | |
//print("Name found: ". (string)$str['name'] ." value: " . (string)$str ); | |
$fields[(string) $str['name']] = (string) $str; | |
//print("\n"); | |
} | |
//print_r($fields); | |
foreach ($doc->arr as $arr) { | |
// print("Name found: " . (string) $arr['name'] ." value: "); | |
foreach ($arr as $item) { | |
$fields[((string) $arr['name'])][] = (string) $item; //print((string) $item); | |
} | |
//print("\n"); | |
} | |
//print_r($fields); | |
$data[($fields['id'])] = $fields; | |
} | |
file_put_contents('incontxt.json', json_encode($data)); | |
} | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment