1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Divergence package. |
4
|
|
|
* |
5
|
|
|
* (c) Henry Paradiz <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Divergence\Models\Media; |
12
|
|
|
|
13
|
|
|
use Exception; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Audio Media Model |
17
|
|
|
* |
18
|
|
|
* @author Henry Paradiz <[email protected]> |
19
|
|
|
* @author Chris Alfano <[email protected]> |
20
|
|
|
* |
21
|
|
|
* {@inheritDoc} |
22
|
|
|
*/ |
23
|
|
|
class Audio extends Media |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
// configurables |
26
|
|
|
public static $previewExtractCommand = 'ffmpeg -i %1$s -ss %3$u -t %4$u -f mp3 -y %2$s'; // 1=input file, 2=output file, 3=start time, 4=duration |
27
|
|
|
public static $previewDuration = 30; |
28
|
|
|
public static $iconPath = '/site-root/img/icons/filetypes/mp3.png'; |
29
|
|
|
|
30
|
|
|
public function getValue($name) |
31
|
|
|
{ |
32
|
|
|
switch ($name) { |
33
|
|
|
case 'ThumbnailMIMEType': |
34
|
|
|
return 'image/png'; |
35
|
|
|
|
36
|
|
|
case 'Width': |
37
|
|
|
return 128; |
38
|
|
|
|
39
|
|
|
case 'Height': |
40
|
|
|
return 128; |
41
|
|
|
|
42
|
|
|
case 'Extension': |
43
|
|
|
|
44
|
|
|
switch ($this->getValue('MIMEType')) { |
45
|
|
|
case 'audio/mpeg': |
46
|
|
|
return 'mp3'; |
47
|
|
|
default: |
48
|
|
|
throw new Exception('Unable to find audio extension for mime-type: '.$this->getValue('MIMEType')); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// no break |
52
|
|
|
default: |
53
|
|
|
return parent::getValue($name); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getImage($sourceFile = null) |
58
|
|
|
{ |
59
|
|
|
if (!isset($sourceFile)) { |
60
|
|
|
$sourceFile = $this->BlankPath; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return imagecreatefromstring(file_get_contents($sourceFile)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function createPreview() |
67
|
|
|
{ |
68
|
|
|
// check if a preview already exists |
69
|
|
|
|
70
|
|
|
if (!empty($_REQUEST['startTime']) && is_numeric($_REQUEST['startTime']) && ($_REQUEST['startTime'] >= 0) && ($_REQUEST['startTime'] < $this->getValue('Duration'))) { |
71
|
|
|
$startTime = $_REQUEST['startTime']; |
72
|
|
|
} else { |
73
|
|
|
$startTime = 0; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$previewPath = tempnam('/tmp', 'mediaPreview'); |
77
|
|
|
|
78
|
|
|
// generate preview |
79
|
|
|
$cmd = sprintf(static::$previewExtractCommand, $this->FilesystemPath, $previewPath, $startTime, static::$previewDuration); |
80
|
|
|
shell_exec($cmd); |
81
|
|
|
|
82
|
|
|
if (!filesize($previewPath)) { |
83
|
|
|
throw new Exception('Preview output is empty'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// create media instance |
87
|
|
|
$PreviewMedia = Media::createFromFile($previewPath, [ |
88
|
|
|
'ContextClass' => 'Media' |
89
|
|
|
,'ContextID' => $this->getValue('ID') |
90
|
|
|
,'Caption' => sprintf('%u sec preview (%us-%us)', static::$previewDuration, $startTime, $startTime+static::$previewDuration), |
91
|
|
|
]); |
92
|
|
|
|
93
|
|
|
return $PreviewMedia; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths