Skip to content

Commit 234c597

Browse files
author
Daniel Neto
committed
Add audio file type handling using constants for better maintainability
1 parent 24a6939 commit 234c597

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

objects/Encoder.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class Encoder extends ObjectYPT
3838
const LOG_TYPE_ERROR = 'error';
3939
const LOG_TYPE_INFO = 'info';
4040

41+
const AUDIO_EXTENSIONS = ['mp3', 'aac', 'm4a', 'ogg', 'opus', 'flac', 'wav', 'wma'];
42+
4143
protected $id;
4244
protected $fileURI;
4345
protected $filename;
@@ -794,6 +796,7 @@ private static function setDownloaded($queue_id, $filePath)
794796
_error_log($msg);
795797
$encoder->setStatus(Encoder::STATUS_DOWNLOADED);
796798
$encoder->setStatus_obs($msg);
799+
$encoder->setDownloadedFileName($filePath);
797800
return $encoder->save();
798801
}
799802

view/queue.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
$e->setTitle($path_parts['filename']);
5555
$e->setPriority($s->getPriority());
5656

57-
if (strtolower(pathinfo($_POST['fileURI'], PATHINFO_EXTENSION)) === 'mp3') {
57+
$fileExtension = strtolower(pathinfo($_POST['fileURI'], PATHINFO_EXTENSION));
58+
if (in_array($fileExtension, Encoder::AUDIO_EXTENSIONS)) {
5859
$e->setFormats_idFromOrder(89); //Audio to MP4
5960
}else if (!empty($_POST['audioOnly']) && $_POST['audioOnly'] !== 'false') {
6061
if (!empty($_POST['spectrum']) && $_POST['spectrum'] !== 'false') {

view/upload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//echo "Success: file extension OK\n";
2424
//chack if is an audio
2525
$type = "video";
26-
if (strcasecmp($extension, 'mp3') == 0 || strcasecmp($extension, 'wav') == 0) {
26+
if (in_array(strtolower($extension), Encoder::AUDIO_EXTENSIONS)) {
2727
$type = 'audio';
2828
}
2929

0 commit comments

Comments
 (0)