1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ownCloud - Music app |
5
|
|
|
* |
6
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
7
|
|
|
* later. See the COPYING file. |
8
|
|
|
* |
9
|
|
|
* @author Pauli Järvinen <[email protected]> |
10
|
|
|
* @copyright Pauli Järvinen 2018 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace OCA\Music\Utility; |
14
|
|
|
|
15
|
|
|
use \OCA\Music\AppFramework\Core\Logger; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
|
19
|
|
|
class DetailsHelper { |
20
|
|
|
private $extractor; |
21
|
|
|
private $logger; |
22
|
|
|
|
23
|
|
|
public function __construct( |
24
|
|
|
Extractor $extractor, |
25
|
|
|
Logger $logger) { |
26
|
|
|
$this->extractor = $extractor; |
27
|
|
|
$this->logger = $logger; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $fileId |
32
|
|
|
* @param string $userId |
|
|
|
|
33
|
|
|
* @param Folder $userFolder |
34
|
|
|
* $return array|null |
35
|
|
|
*/ |
36
|
|
|
public function getDetails($fileId, $userFolder) { |
37
|
|
|
$fileNodes = $userFolder->getById($fileId); |
38
|
|
|
if (\count($fileNodes) > 0) { |
39
|
|
|
$data = $this->extractor->extract($fileNodes[0]); |
40
|
|
|
|
41
|
|
|
$result = [ |
42
|
|
|
'fileinfo' => $data['audio'], |
43
|
|
|
'tags' => self::flattenComments($data['comments']) |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
// binary data has to be encoded |
47
|
|
|
$result['tags']['picture']['data'] = \base64_encode($result['tags']['picture']['data']); |
48
|
|
|
|
49
|
|
|
// 'streams' contains duplicate data |
50
|
|
|
unset($result['fileinfo']['streams']); |
51
|
|
|
|
52
|
|
|
// one track number is enough |
53
|
|
|
if (\array_key_exists('track', $result['tags']) |
54
|
|
|
&& \array_key_exists('track_number', $result['tags'])) { |
55
|
|
|
unset($result['tags']['track']); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// add file path |
59
|
|
|
$result['path'] = $userFolder->getRelativePath($fileNodes[0]->getPath()); |
60
|
|
|
|
61
|
|
|
return $result; |
62
|
|
|
} |
63
|
|
|
return null; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
// In the 'comments' field from the extractor, the value for each key is a 1-element |
67
|
|
|
// array containing the actual tag value. Remove these intermediate arrays. |
68
|
|
|
private static function flattenComments($array) { |
69
|
|
|
foreach ($array as $key => $value) { |
70
|
|
|
$array[$key] = $value[0]; |
71
|
|
|
} |
72
|
|
|
return $array; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.