mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-25 14:37:59 +01:00
Merge rPFb66ec54221d5: T357: Added genre handling to the MLPMA importer.
This commit is contained in:
parent
1fe6aa98b5
commit
5a2fb2f05e
2 changed files with 36 additions and 2 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Genre;
|
||||
use App\Image;
|
||||
use App\Track;
|
||||
use App\User;
|
||||
|
@ -87,6 +88,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!');
|
||||
|
@ -189,6 +195,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.
|
||||
//==========================================================================================================
|
||||
|
@ -264,7 +295,7 @@ 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'];
|
||||
|
||||
|
@ -311,6 +342,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'];
|
||||
|
|
|
@ -2,12 +2,14 @@
|
|||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Traits\SlugTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Genre extends Model
|
||||
{
|
||||
protected $table = 'genres';
|
||||
protected $fillable = ['name', 'slug'];
|
||||
public $timestamps = false;
|
||||
|
||||
use SlugTrait;
|
||||
}
|
Loading…
Reference in a new issue