mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-25 14:37:59 +01:00
T357: Added genre handling to the MLPMA importer.
This commit is contained in:
parent
5d9b3f2d5b
commit
b66ec54221
3 changed files with 36 additions and 5 deletions
|
@ -6,6 +6,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use Entities\Album;
|
use Entities\Album;
|
||||||
use Entities\Image;
|
use Entities\Image;
|
||||||
|
use Entities\Genre;
|
||||||
use Entities\User;
|
use Entities\User;
|
||||||
use Entities\Track;
|
use Entities\Track;
|
||||||
use Commands\UploadTrackCommand;
|
use Commands\UploadTrackCommand;
|
||||||
|
@ -84,6 +85,11 @@ class ImportMLPMA extends Command {
|
||||||
File::makeDirectory($tmpPath);
|
File::makeDirectory($tmpPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$UNKNOWN_GENRE = Genre::firstOrCreate([
|
||||||
|
'name' => 'Unknown',
|
||||||
|
'slug' => 'unknown'
|
||||||
|
]);
|
||||||
|
|
||||||
$this->comment('Enumerating MLP Music Archive source files...');
|
$this->comment('Enumerating MLP Music Archive source files...');
|
||||||
$files = File::allFiles($mlpmaPath);
|
$files = File::allFiles($mlpmaPath);
|
||||||
$this->info(sizeof($files).' files found!');
|
$this->info(sizeof($files).' files found!');
|
||||||
|
@ -182,6 +188,31 @@ class ImportMLPMA extends Command {
|
||||||
$isVocal = $parsedTags['lyrics'] !== null;
|
$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.
|
// 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.
|
// Extract the cover art, if any exists.
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
|
|
||||||
$this->comment('Extracting cover art!');
|
$this->comment('Extracting cover art!');
|
||||||
$coverId = null;
|
$coverId = null;
|
||||||
if (array_key_exists('comments', $allTags) && array_key_exists('picture', $allTags['comments'])) {
|
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?
|
// Is this part of an album?
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
// Find the album if it exists and create it if it doesn't.
|
|
||||||
$albumId = null;
|
$albumId = null;
|
||||||
$albumName = $parsedTags['album'];
|
$albumName = $parsedTags['album'];
|
||||||
|
|
||||||
|
@ -279,7 +308,6 @@ class ImportMLPMA extends Command {
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
// Save this track.
|
// Save this track.
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
|
|
||||||
// "Upload" the track to Pony.fm
|
// "Upload" the track to Pony.fm
|
||||||
$this->comment('Transcoding the track!');
|
$this->comment('Transcoding the track!');
|
||||||
Auth::loginUsingId($artist->id);
|
Auth::loginUsingId($artist->id);
|
||||||
|
@ -300,6 +328,7 @@ class ImportMLPMA extends Command {
|
||||||
$track->title = $parsedTags['title'];
|
$track->title = $parsedTags['title'];
|
||||||
$track->cover_id = $coverId;
|
$track->cover_id = $coverId;
|
||||||
$track->album_id = $albumId;
|
$track->album_id = $albumId;
|
||||||
|
$track->genre_id = $genreId;
|
||||||
$track->track_number = $parsedTags['track_number'];
|
$track->track_number = $parsedTags['track_number'];
|
||||||
$track->released_at = $releasedAt;
|
$track->released_at = $releasedAt;
|
||||||
$track->description = $parsedTags['comments'];
|
$track->description = $parsedTags['comments'];
|
||||||
|
|
|
@ -19,7 +19,7 @@ class RebuildTags extends Command {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = 'Command description.';
|
protected $description = 'Rewrites tags in track files, ensuring they\'re up to date.';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command instance.
|
* Create a new command instance.
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
class Genre extends \Eloquent {
|
class Genre extends \Eloquent {
|
||||||
protected $table = 'genres';
|
protected $table = 'genres';
|
||||||
|
protected $fillable = ['name', 'slug'];
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
use SlugTrait;
|
use SlugTrait;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue