mirror of
https://code.castopod.org/adaures/castopod
synced 2025-06-05 08:52:00 +00:00

- add james-heinrich/getid3 library as a dependency to composer.json - update DEPENDENCIES.md file - fix episodes table migration script - add js devDependencies: prettier, @prettier/plugin-php and lint-staged to automatically format staged files before commit - reformat all files to the prettier format - refactor code by separating some logic as helper functions - overwrite existing files when uploading new files with the same name fixes #1
54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?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'],
|
|
];
|
|
}
|