Unknown audio formats are gracefully handled now.

This commit is contained in:
Peter Deltchev 2016-02-15 07:18:31 -08:00
parent 815b505e87
commit 6c83936ce6
3 changed files with 40 additions and 9 deletions

View file

@ -73,22 +73,21 @@ class GenerateTrackFilesCommand extends CommandBase
// without being re-encoded.
$audioObject = AudioCache::get($source);
$isLossyUpload = !$this->isLosslessFile($audioObject);
$codecString = $audioObject->getAudioCodec();
if ($isLossyUpload) {
if ($audioObject->getAudioCodec() === 'mp3') {
if ($codecString === 'mp3') {
$masterFormat = 'MP3';
} else if (Str::startsWith($audioObject->getAudioCodec(), 'aac')) {
} else if (Str::startsWith($codecString, 'aac')) {
$masterFormat = 'AAC';
} else if ($audioObject->getAudioCodec() === 'vorbis') {
} else if ($codecString === 'vorbis') {
$masterFormat = 'OGG Vorbis';
} else {
$validator = new Validator();
$validator->messages()->add('track', 'The track does not contain audio in a known lossy format.');
$this->track->delete();
return CommandResponse::fail($validator);
return CommandResponse::fail(['track' => "The track does not contain audio in a known lossy format. The format read from the file is: {$codecString}"]);
}
// Sanity check: skip creating this TrackFile if it already exists.

View file

@ -25,6 +25,9 @@ use Config;
use getID3;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Input;
use Log;
use Poniverse\Ponyfm\Exceptions\InvalidEncodeOptionsException;
use Poniverse\Ponyfm\Exceptions\UnknownTagFormatException;
use Poniverse\Ponyfm\Models\Album;
use Poniverse\Ponyfm\Models\Genre;
use Poniverse\Ponyfm\Models\Image;
@ -236,7 +239,7 @@ class UploadTrackCommand extends CommandBase
* @param User $artist
* @param string $audioCodec
* @return array the "processed" and raw tags extracted from the file
* @throws \Exception
* @throws BadRequestHttpException
*/
protected function parseOriginalTags(UploadedFile $file, User $artist, string $audioCodec) {
//==========================================================================================================
@ -268,6 +271,21 @@ class UploadTrackCommand extends CommandBase
} elseif (Str::startsWith($audioCodec, ['pcm', 'adpcm'])) {
list($parsedTags, $rawTags) = $this->getAtomTags($allTags);
} else {
// Assume the file is untagged if it's in an unknown format.
$parsedTags = [
'title' => null,
'artist' => null,
'band' => null,
'genre' => null,
'track_number' => null,
'album' => null,
'year' => null,
'release_date' => null,
'comments' => null,
'lyrics' => null,
];
$rawTags = [];
}

View file

@ -23,7 +23,6 @@ namespace Poniverse\Ponyfm\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Poniverse\Ponyfm\Commands\GenerateTrackFilesCommand;
use Poniverse\Ponyfm\Commands\UploadTrackCommand;
use Poniverse\Ponyfm\Jobs\EncodeTrackFile;
use Poniverse\Ponyfm\Models\Track;
@ -66,9 +65,14 @@ class RebuildTrack extends Command
{
/** @var Track $track */
$track = Track::with('trackFiles')->withTrashed()->find((int) $this->argument('trackId'));
$this->printTrackInfo($track);
if($this->option('upload')) {
// The track would've been deleted if its original upload failed.
// It should be restored so the user can publish the track!
$track->restore();
$this->info("Attempting to finish this track's upload...");
$sourceFile = new \SplFileInfo($track->getTemporarySourceFile());
$generateTrackFiles = new GenerateTrackFilesCommand($track, $sourceFile, false);
$result = $generateTrackFiles->execute();
@ -76,10 +80,12 @@ class RebuildTrack extends Command
if ($result->didFail()) {
$this->error("Something went wrong!");
$this->error(json_encode($result->getMessages(), JSON_PRETTY_PRINT));
print_r($result->getMessages());
}
} else {
$this->info("Re-encoding this track's files - there should be a line of output for each format!");
foreach ($track->trackFiles as $trackFile) {
if (!$trackFile->is_master) {
$this->info("Re-encoding this track's {$trackFile->format} file...");
@ -88,4 +94,12 @@ class RebuildTrack extends Command
}
}
}
private function printTrackInfo(Track $track) {
$this->comment("Track info:");
$this->comment(" Title: {$track->title}");
$this->comment(" Uploaded at: {$track->created_at}");
$this->comment(" Artist: {$track->user->display_name} [User ID: {$track->user_id}]");
$this->comment(" Artist email: {$track->user->email}");
}
}