diff --git a/app/commands/ImportMLPMA.php b/app/commands/ImportMLPMA.php index 8e0ab371..3bdfeb35 100644 --- a/app/commands/ImportMLPMA.php +++ b/app/commands/ImportMLPMA.php @@ -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']; diff --git a/app/commands/RebuildTags.php b/app/commands/RebuildTags.php index edf1cc2c..31889cd1 100644 --- a/app/commands/RebuildTags.php +++ b/app/commands/RebuildTags.php @@ -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. diff --git a/app/models/Entities/Genre.php b/app/models/Entities/Genre.php index e1b2abe2..0680fe00 100644 --- a/app/models/Entities/Genre.php +++ b/app/models/Entities/Genre.php @@ -5,6 +5,8 @@ class Genre extends \Eloquent { protected $table = 'genres'; + protected $fillable = ['name', 'slug']; + public $timestamps = false; use SlugTrait; - } \ No newline at end of file + }