T357: Added genre handling to the MLPMA importer.

This commit is contained in:
Peter Deltchev 2015-09-07 11:56:00 -07:00
parent 5d9b3f2d5b
commit b66ec54221
3 changed files with 36 additions and 5 deletions

View file

@ -6,6 +6,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Illuminate\Support\Facades\File;
use Entities\Album;
use Entities\Image;
use Entities\Genre;
use Entities\User;
use Entities\Track;
use Commands\UploadTrackCommand;
@ -84,6 +85,11 @@ class ImportMLPMA extends Command {
File::makeDirectory($tmpPath);
}
$UNKNOWN_GENRE = Genre::firstOrCreate([
'name' => 'Unknown',
'slug' => 'unknown'
]);
$this->comment('Enumerating MLP Music Archive source files...');
$files = File::allFiles($mlpmaPath);
$this->info(sizeof($files).' files found!');
@ -182,6 +188,31 @@ class ImportMLPMA extends Command {
$isVocal = $parsedTags['lyrics'] !== null;
//==========================================================================================================
// Determine the genre
//==========================================================================================================
$genreName = $parsedTags['genre'];
$this->info('Genre: '.$genreName);
if ($genreName) {
$genre = Genre::where('name', '=', $genreName)->first();
if ($genre) {
$genreId = $genre->id;
} else {
$genre = new Genre();
$genre->name = $genreName;
$genre->slug = Str::slug($genreName);
$genre->save();
$genreId = $genre->id;
$this->comment('Created a new genre!');
}
} else {
$genreId = $UNKNOWN_GENRE->id; // "Unknown" genre ID
}
//==========================================================================================================
// Determine which artist account this file belongs to using the containing directory.
//==========================================================================================================
@ -215,7 +246,6 @@ class ImportMLPMA extends Command {
//==========================================================================================================
// Extract the cover art, if any exists.
//==========================================================================================================
$this->comment('Extracting cover art!');
$coverId = null;
if (array_key_exists('comments', $allTags) && array_key_exists('picture', $allTags['comments'])) {
@ -253,7 +283,6 @@ class ImportMLPMA extends Command {
//==========================================================================================================
// Is this part of an album?
//==========================================================================================================
// Find the album if it exists and create it if it doesn't.
$albumId = null;
$albumName = $parsedTags['album'];
@ -279,7 +308,6 @@ class ImportMLPMA extends Command {
//==========================================================================================================
// Save this track.
//==========================================================================================================
// "Upload" the track to Pony.fm
$this->comment('Transcoding the track!');
Auth::loginUsingId($artist->id);
@ -300,6 +328,7 @@ class ImportMLPMA extends Command {
$track->title = $parsedTags['title'];
$track->cover_id = $coverId;
$track->album_id = $albumId;
$track->genre_id = $genreId;
$track->track_number = $parsedTags['track_number'];
$track->released_at = $releasedAt;
$track->description = $parsedTags['comments'];

View file

@ -19,7 +19,7 @@ class RebuildTags extends Command {
*
* @var string
*/
protected $description = 'Command description.';
protected $description = 'Rewrites tags in track files, ensuring they\'re up to date.';
/**
* Create a new command instance.

View file

@ -5,6 +5,8 @@
class Genre extends \Eloquent {
protected $table = 'genres';
protected $fillable = ['name', 'slug'];
public $timestamps = false;
use SlugTrait;
}
}