From 5588b836a09823b76bd0abfafe2b2caadefbea09 Mon Sep 17 00:00:00 2001 From: Peter Deltchev Date: Mon, 15 Feb 2016 02:21:43 -0800 Subject: [PATCH] Pony.fm should accept all PCM and ADPCM files now. --- app/Commands/UploadTrackCommand.php | 15 ++++++--------- app/Library/PfmValidator.php | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/Commands/UploadTrackCommand.php b/app/Commands/UploadTrackCommand.php index 1440203e..f1ba085d 100644 --- a/app/Commands/UploadTrackCommand.php +++ b/app/Commands/UploadTrackCommand.php @@ -52,13 +52,8 @@ class UploadTrackCommand extends CommandBase private $_losslessFormats = [ 'flac', - 'pcm_s16le ([1][0][0][0] / 0x0001)', - 'pcm_s16be', - 'adpcm_ms ([2][0][0][0] / 0x0002)', - 'pcm_s24le ([1][0][0][0] / 0x0001)', - 'pcm_s24be', - 'pcm_f32le ([3][0][0][0] / 0x0003)', - 'pcm_f32be (fl32 / 0x32336C66)' + 'pcm', + 'adpcm', ]; public function __construct($allowLossy = false, $allowShortTrack = false, $customTrackSource = null, $autoPublishByDefault = false) @@ -114,7 +109,9 @@ class UploadTrackCommand extends CommandBase $validator = \Validator::make($input, [ 'track' => 'required|' - . ($this->_allowLossy ? '' : 'audio_format:'. implode(',', $this->_losslessFormats).'|') + . ($this->_allowLossy + ? 'audio_format:flac,pcm,adpcm,aac,mp3,vorbis|' + : 'audio_format:flac,pcm,adpcm|') . ($this->_allowShortTrack ? '' : 'min_duration:30|') . 'audio_channels:1,2', @@ -194,7 +191,7 @@ class UploadTrackCommand extends CommandBase // Lossy uploads need to be identified and set as the master file // without being re-encoded. $audioObject = AudioCache::get($source); - $isLossyUpload = !in_array($audioObject->getAudioCodec(), $this->_losslessFormats); + $isLossyUpload = !Str::startsWith($audioObject->getAudioCodec(), $this->_losslessFormats); if ($isLossyUpload) { if ($audioObject->getAudioCodec() === 'mp3') { diff --git a/app/Library/PfmValidator.php b/app/Library/PfmValidator.php index 132bcd74..ecbc5fdc 100644 --- a/app/Library/PfmValidator.php +++ b/app/Library/PfmValidator.php @@ -1,4 +1,5 @@ getPathname()); + $codecString = $file->getAudioCodec(); + + // PCM, ADPCM, and AAC come in several variations as far as FFmpeg + // is concerned. They're all acceptable for Pony.fm, so we check what + // the codec string returned by FFmpeg starts with instead of looking + // for an exact match for these. + if (in_array('adpcm', $parameters) && Str::startsWith($codecString, 'adpcm')) { + return true; + } + + if (in_array('pcm', $parameters) && Str::startsWith($codecString, 'pcm')) { + return true; + } + + if (in_array('aac', $parameters) && Str::startsWith($codecString, 'aac')) { + return true; + } return in_array($file->getAudioCodec(), $parameters); }