mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-22 13:07:59 +01:00
T125: Implemented TrackFile model to facilitate lossy master files.
This commit is contained in:
parent
76fe042652
commit
2e146df697
4 changed files with 72 additions and 0 deletions
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Entities\Track;
|
||||||
|
use Entities\TrackFile;
|
||||||
|
|
||||||
|
class CreateTrackFilesTable extends Migration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
// Fill in the table
|
||||||
|
DB::transaction(function(){
|
||||||
|
Schema::create('track_files', function($table){
|
||||||
|
$table->increments('id');
|
||||||
|
$table->integer('track_id')->unsigned()->indexed();
|
||||||
|
$table->boolean('is_master')->default(false)->indexed();
|
||||||
|
$table->string('format')->indexed();
|
||||||
|
|
||||||
|
$table->foreign('track_id')->references('id')->on('tracks');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach (Track::all() as $track){
|
||||||
|
foreach (Track::$Formats as $name => $item) {
|
||||||
|
DB::table('track_files')->insert(
|
||||||
|
[
|
||||||
|
'track_id' => $track->id,
|
||||||
|
'is_master' => $name === 'FLAC' ? true : false,
|
||||||
|
'format' => $name,
|
||||||
|
'created_at'=> $track->created_at,
|
||||||
|
'updated_at'=> Carbon\Carbon::now()
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::drop('track_files');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -3,6 +3,7 @@
|
||||||
namespace Commands;
|
namespace Commands;
|
||||||
|
|
||||||
use Entities\Track;
|
use Entities\Track;
|
||||||
|
use Entities\TrackFile;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class UploadTrackCommand extends CommandBase {
|
class UploadTrackCommand extends CommandBase {
|
||||||
|
@ -53,6 +54,11 @@
|
||||||
$processes = [];
|
$processes = [];
|
||||||
|
|
||||||
foreach (Track::$Formats as $name => $format) {
|
foreach (Track::$Formats as $name => $format) {
|
||||||
|
$trackFile = new TrackFile();
|
||||||
|
$trackFile->is_master = $name === 'FLAC' ? true : false;
|
||||||
|
$trackFile->format = $name;
|
||||||
|
$track->trackFiles()->save($trackFile);
|
||||||
|
|
||||||
$target = $destination . '/' . $track->getFilenameFor($name);
|
$target = $destination . '/' . $track->getFilenameFor($name);
|
||||||
|
|
||||||
$command = $format['command'];
|
$command = $format['command'];
|
||||||
|
|
|
@ -297,6 +297,10 @@
|
||||||
return $this->belongsTo('Entities\Album');
|
return $this->belongsTo('Entities\Album');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function trackFiles() {
|
||||||
|
return $this->hasMany('Entities\TrackFile');
|
||||||
|
}
|
||||||
|
|
||||||
public function getYear() {
|
public function getYear() {
|
||||||
return date('Y', strtotime($this->release_date));
|
return date('Y', strtotime($this->release_date));
|
||||||
}
|
}
|
||||||
|
@ -424,6 +428,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateTags() {
|
public function updateTags() {
|
||||||
|
$this->trackFiles()->touch();
|
||||||
foreach (self::$Formats as $format => $data) {
|
foreach (self::$Formats as $format => $data) {
|
||||||
$this->{$data['tag_method']}($format);
|
$this->{$data['tag_method']}($format);
|
||||||
}
|
}
|
||||||
|
|
7
app/models/Entities/TrackFile.php
Normal file
7
app/models/Entities/TrackFile.php
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?php namespace Entities;
|
||||||
|
|
||||||
|
class TrackFile extends \Eloquent {
|
||||||
|
public function track() {
|
||||||
|
return $this->belongsTo('Entities\Track');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue