Completed
Push — master ( 1e45e0...9c8682 )
by
unknown
17s queued 14s
created

AudioVideoMD   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A extractMetadata() 0 14 5
1
<?php
2
3
/**
4
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
5
 *
6
 * This file is part of the Kitodo and TYPO3 projects.
7
 *
8
 * @license GNU General Public License version 3 or later.
9
 * For the full copyright and license information, please read the
10
 * LICENSE.txt file that was distributed with this source code.
11
 */
12
13
namespace Kitodo\Dlf\Format;
14
15
/**
16
 * Process AudioMD and VideoMD metadata.
17
 *
18
 * The technical reason for handling both formats here is that this makes it slightly more
19
 * straightforward to extract `duration` as either video duration or audio duration.
20
 *
21
 * @author Kajetan Dvoracek <[email protected]>
22
 * @package TYPO3
23
 * @subpackage dlf
24
 * @access public
25
 */
26
class AudioVideoMD implements \Kitodo\Dlf\Common\MetadataInterface
27
{
28
    /**
29
     * Extract some essential AudioMD/VideoMD metadata.
30
     *
31
     * @access public
32
     *
33
     * @param \SimpleXMLElement $xml: The XML to extract the metadata from
34
     * @param array &$metadata: The metadata array to fill
35
     *
36
     * @return void
37
     */
38
    public function extractMetadata(\SimpleXMLElement $xml, array &$metadata)
39
    {
40
        $xml->registerXPathNamespace('audiomd', 'http://www.loc.gov/audioMD/');
41
        $xml->registerXPathNamespace('videomd', 'http://www.loc.gov/videoMD/');
42
43
        if (!empty($audioDuration = (string) $xml->xpath('./audiomd:audioInfo/audiomd:duration')[0])) {
44
            $metadata['audio_duration'] = [$audioDuration];
45
        }
46
47
        if (!empty($videoDuration = (string) $xml->xpath('./videomd:videoInfo/videomd:duration')[0])) {
48
            $metadata['video_duration'] = [$videoDuration];
49
        }
50
51
        $metadata['duration'] = $metadata['video_duration'] ?: $metadata['audio_duration'] ?: [];
52
    }
53
}
54