Fixed track encodes. They work again! Also implemented a track re-encoding command.

This commit is contained in:
Peter Deltchev 2016-01-04 14:55:20 -08:00
parent a2b450baa6
commit 0eb96f0e83
6 changed files with 93 additions and 22 deletions

View file

@ -235,7 +235,7 @@ class UploadTrackCommand extends CommandBase
$trackFile = new TrackFile();
$trackFile->is_master = $name === 'FLAC' ? true : false;
$trackFile->format = $name;
$trackFile->status = TrackFile::STATUS_PROCESSING;
$trackFile->status = TrackFile::STATUS_PROCESSING_PENDING;
if (in_array($name, Track::$CacheableFormats) && $trackFile->is_master == false) {
$trackFile->is_cacheable = true;

View file

@ -0,0 +1,83 @@
<?php
/**
* Pony.fm - A community for pony fan music.
* Copyright (C) 2015 Peter Deltchev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Poniverse\Ponyfm\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Poniverse\Ponyfm\Jobs\EncodeTrackFile;
use Poniverse\Ponyfm\Models\Track;
class RebuildTrack extends Command
{
use DispatchesJobs;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rebuild:track
{trackId : ID of the track to rebuild}
{--upload : Include this option to use the uploaded file as the encode source instead of the master file}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Re-encodes a track\'s files';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
/** @var Track $track */
$track = Track::with('trackFiles')->find((int) $this->argument('trackId'));
if($this->option('upload')) {
foreach($track->trackFiles as $trackFile) {
$this->info("Re-encoding this track's {$trackFile->format} file...");
$this->dispatch(new EncodeTrackFile($trackFile, false, true, false));
}
} else {
foreach ($track->trackFiles as $trackFile) {
if (!$trackFile->is_master) {
$this->info("Re-encoding this track's {$trackFile->format} file...");
$this->dispatch(new EncodeTrackFile($trackFile, true));
}
}
}
}
}

View file

@ -43,6 +43,7 @@ class Kernel extends ConsoleKernel
\Poniverse\Ponyfm\Console\Commands\PoniverseApiSetup::class,
\Poniverse\Ponyfm\Console\Commands\ClearTrackCache::class,
\Poniverse\Ponyfm\Console\Commands\RebuildTrackCache::class,
\Poniverse\Ponyfm\Console\Commands\RebuildTrack::class,
\Poniverse\Ponyfm\Console\Commands\RebuildFilesizes::class,
\Poniverse\Ponyfm\Console\Commands\MergeDuplicateAccounts::class,
];

View file

@ -42,19 +42,19 @@ class EncodeTrackFile extends Job implements SelfHandling, ShouldQueue
/**
* @var TrackFile
*/
private $trackFile;
protected $trackFile;
/**
* @var
*/
private $isExpirable;
protected $isExpirable;
/**
* @var bool
*/
private $isForUpload;
protected $isForUpload;
/**
* @var bool
*/
private $autoPublishWhenComplete;
protected $autoPublishWhenComplete;
/**
* Create a new job instance.
@ -72,23 +72,10 @@ class EncodeTrackFile extends Job implements SelfHandling, ShouldQueue
throw new InvalidEncodeOptionsException("Master files cannot be encoded unless we're generating a lossless master file during the upload process.");
}
// don't start this job if the file is already being processed or if it's still valid
if (
in_array($trackFile->status, [TrackFile::STATUS_PROCESSING_PENDING, TrackFile::STATUS_PROCESSING]) ||
!$trackFile->is_expired
) {
$this->delete();
return;
}
$this->trackFile = $trackFile;
$this->isExpirable = $isExpirable;
$this->isForUpload = $isForUpload;
$this->autoPublishWhenComplete = $autoPublish;
// "lock" this file for processing
$this->trackFile->status = TrackFile::STATUS_PROCESSING_PENDING;
$this->trackFile->save();
}
/**
@ -151,7 +138,7 @@ class EncodeTrackFile extends Job implements SelfHandling, ShouldQueue
$this->trackFile->track->updateTags($this->trackFile->format);
// Insert the expiration time for cached tracks
if ($this->isExpirable) {
if ($this->isExpirable && $this->trackFile->is_cacheable) {
$this->trackFile->expires_at = Carbon::now()->addMinutes(Config::get('ponyfm.track_file_cache_duration'));
$this->trackFile->save();
}

View file

@ -698,11 +698,11 @@ class Track extends Model
} elseif (
$carry !== static::STATUS_ERROR &&
(int) $trackFile->status === TrackFile::STATUS_PROCESSING) {
in_array($trackFile->status, [TrackFile::STATUS_PROCESSING, TrackFile::STATUS_PROCESSING_PENDING])) {
return static::STATUS_PROCESSING;
} elseif (
!in_array($carry, [static::STATUS_ERROR, static::STATUS_PROCESSING]) &&
!in_array($carry, [static::STATUS_ERROR, static::STATUS_PROCESSING, TrackFile::STATUS_PROCESSING_PENDING]) &&
(int) $trackFile->status === TrackFile::STATUS_NOT_BEING_PROCESSED
) {
return static::STATUS_COMPLETE;

View file

@ -106,7 +106,7 @@ class TrackFile extends Model
}
public function getIsExpiredAttribute() {
return $this->expires_at === null ||
return $this->attributes['expires_at'] === null ||
$this->expires_at->isPast();
}