Skip to content

Instantly share code, notes, and snippets.

@ajslaghu
Last active December 23, 2015 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ajslaghu/6582193 to your computer and use it in GitHub Desktop.
Save ajslaghu/6582193 to your computer and use it in GitHub Desktop.
Open Beelden data loader
<?php // written by AJ Slaghuis (c) 2013
$input = 'FIN-180912-3681a_hd'; // the video name we are looking for
// let's not bang too much on the openbeelden server
if (!file_exists('download.xml')) {
$file = file_get_contents('http://www.openbeelden.nl/feeds/oai/?verb=ListRecords&metadataPrefix=oai_dc&from=2012-01-01&until=2012-12-31');
file_put_contents('download.xml', $file);
}
$xml = simplexml_load_file('download.xml'); // print_r(scandir('.'));
$namespaces = $xml->getNamespaces(true); //print_r($namespaces);
$records = $xml->ListRecords->record;
foreach ($records as $record) {
// $record->header->identifier, datestamp and setSpec
// print_r($record->header);
$data = $record->metadata->children($namespaces['oai_dc']);
$rows = $data->children($namespaces['dc']);
/* print_r($rows), $rows->title, creator, subject, description, publisher, contributor,
* date, type, format[i], identifier, source, relation[?], language, coverage[i], rights
*/
/* use this for debugging your XML marker and checking namespaces
$rows->yourpointer->asXML('php://output');
*/
foreach ($rows->title as $title) {
if ($title == $input) {
print($title . "\n");
//print_r($rows->format);
$uris = (array) $rows->format;
//print_r($uris);
foreach ($uris as $uri) {
$arr = explode('.', $uri); //print(end($arr) . "\n");
if (end($arr) == 'png') {// print($uri);
$farr = explode('/', $arr[sizeof($arr) - 2]);
$filename = end($farr) . '.' . end($arr); // print($filename);
if (!file_exists($filename)) {
$content_file = file_get_contents($uri);
file_put_contents($filename, $content_file);
}
}
}
}
}
}
?>
@gerbenjacobs
Copy link

Nice example, but uncommon input. Why not something more dynamic, with an hint of preventing information overflow?

@ajslaghu
Copy link
Author

I thought to illustrate a bridge from searching the web interface (seeing a picture or categorie one likes ) to actually getting it.

Making it more dynamic. We could do some random stuf, in the other Gist (NieuwsQuiz) I actually do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment