-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_vid_streamingModel_and_data.php
55 lines (43 loc) · 1.66 KB
/
add_vid_streamingModel_and_data.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env drush
/*
Script to add video streaming model and datastream to object.
5/20/2020
*/
<?php
$tuquePath = libraries_get_path('tuque') . '/*.php'; foreach ( glob($tuquePath) as $filename) {
require_once($filename);
}
$serializer = new FedoraApiSerializer();
$cache = new SimpleCache();
$connection = new RepositoryConnection('fedora_url', 'user', 'password');
$api = new FedoraApi($connection, $serializer);
$repository = new FedoraRepository($api, $cache);
$csv = array_map('str_getcsv', file('/file/path/test_vid_files.csv'));
foreach ($csv as $row) {
$id = $row[0];
$link = $row[1];
$object = $repository->getObject($id);
if (!$object) {
drupal_set_message("Fedora Object isn't in the repo!");
} else {
$object->relationships->add('info:fedora/fedora-system:def/model#', 'hasModel','islandora:sp_streaming');
$dsid = 'STREAMING';
$datastream = isset($object[$dsid]) ? $object[$dsid] : $object->constructDatastream($dsid);
$datastream->label = 'Streaming Info';
$datastream->mimeType = 'application/xml';
$dom = new DomDocument();
$sources = $dom->appendChild($dom->createElement('sources'));
$source = $sources->appendChild($dom->createElement('source'));
$url = $source->appendChild($dom->createElement('url'));
$url->appendChild($dom->createTextNode($link));
$mime = $source->appendChild($dom->createElement('mime'));
$mime->appendChild($dom->createTextNode('video/mp4'));
$dom->formatOutput = true;
$xml_string = $dom->saveXML();
$datastream->setContentFromString($xml_string);
if (!isset($object['STREAMING'])) {
$object->ingestDatastream($datastream);
}
}
}
?>