Newer
Older
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
<?php
/**
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
use JamesHeinrich\GetID3\GetID3;
/**
* Saves a file to the corresponding podcast folder in `public/media`
*
* @param UploadedFile $file
* @param string $podcast_name
* @param string $file_name
*
* @return string The absolute path of the file
*/
function save_podcast_media($file, $podcast_name, $file_name)
{
$image_storage_folder = 'media/' . $podcast_name . '/';
// overwrite file if already existing
$file->move($image_storage_folder, $file_name, true);
return $image_storage_folder . $file_name;
}
/**
* Gets audio file metadata and ID3 info
*
* @param UploadedFile $file
*
* @return array
*/
function get_file_metadata($file)
{
if (!$file->isValid()) {
throw new RuntimeException(
$file->getErrorString() . '(' . $file->getError() . ')'
);
}
$getID3 = new GetID3();
$FileInfo = $getID3->analyze($file);
return [
'cover_picture' => $FileInfo['comments']['picture'][0]['data'],
'filesize' => $FileInfo['filesize'],
'mime_type' => $FileInfo['mime_type'],
'playtime_seconds' => $FileInfo['playtime_seconds'],
];
}