mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2025-02-18 02:54:21 +01:00
T357: MLPMA import script is mostly implemented now.
This commit is contained in:
parent
b7084de228
commit
dbab3a9ecc
2 changed files with 184 additions and 85 deletions
|
@ -8,6 +8,7 @@ use Entities\Album;
|
||||||
use Entities\Image;
|
use Entities\Image;
|
||||||
use Entities\User;
|
use Entities\User;
|
||||||
use Entities\ShowSong;
|
use Entities\ShowSong;
|
||||||
|
use Entities\Track;
|
||||||
use Entities\TrackType;
|
use Entities\TrackType;
|
||||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
@ -110,22 +111,22 @@ class ImportMLPMA extends Command {
|
||||||
$this->info('Tagged year: '.$taggedYear);
|
$this->info('Tagged year: '.$taggedYear);
|
||||||
|
|
||||||
if ($taggedYear !== null && $modifiedDate->year === $taggedYear) {
|
if ($taggedYear !== null && $modifiedDate->year === $taggedYear) {
|
||||||
$released_at = $modifiedDate;
|
$releasedAt = $modifiedDate;
|
||||||
|
|
||||||
} else if ($taggedYear !== null && $modifiedDate->year !== $taggedYear) {
|
} else if ($taggedYear !== null && $modifiedDate->year !== $taggedYear) {
|
||||||
$this->error('Release years don\'t match! Using the tagged year...');
|
$this->error('Release years don\'t match! Using the tagged year...');
|
||||||
$released_at = Carbon::create($taggedYear);
|
$releasedAt = Carbon::create($taggedYear);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// $taggedYear is null
|
// $taggedYear is null
|
||||||
$this->error('This track isn\'t tagged with its release year! Using the track\'s last modified date...');
|
$this->error('This track isn\'t tagged with its release year! Using the track\'s last modified date...');
|
||||||
$released_at = $modifiedDate;
|
$releasedAt = $modifiedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
// Does this track have vocals?
|
// Does this track have vocals?
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
$is_vocal = $parsedTags['lyrics'] !== null;
|
$isVocal = $parsedTags['lyrics'] !== null;
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
|
@ -161,7 +162,7 @@ class ImportMLPMA extends Command {
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
// Extract the cover art, if any exists.
|
// Extract the cover art, if any exists.
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
$cover_id = null;
|
$coverId = null;
|
||||||
if (array_key_exists('comments', $tags) && array_key_exists('picture', $tags['comments'])) {
|
if (array_key_exists('comments', $tags) && array_key_exists('picture', $tags['comments'])) {
|
||||||
$image = $tags['comments']['picture'][0];
|
$image = $tags['comments']['picture'][0];
|
||||||
|
|
||||||
|
@ -187,6 +188,7 @@ class ImportMLPMA extends Command {
|
||||||
$imageFile = new UploadedFile($imageFilePath, $imageFilename, $image['image_mime']);
|
$imageFile = new UploadedFile($imageFilePath, $imageFilename, $image['image_mime']);
|
||||||
|
|
||||||
$cover = Image::upload($imageFile, $artist);
|
$cover = Image::upload($imageFile, $artist);
|
||||||
|
$coverId = $cover->id;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->error('No cover art found!');
|
$this->error('No cover art found!');
|
||||||
|
@ -196,37 +198,40 @@ 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;
|
||||||
|
$albumName = $parsedTags['album'];
|
||||||
|
|
||||||
// TODO: find/create the album
|
if ($albumName !== null) {
|
||||||
$album_name = $parsedTags['album'];
|
|
||||||
|
|
||||||
if ($album_name !== null) {
|
|
||||||
$album = Album::where('user_id', '=', $artist->id)
|
$album = Album::where('user_id', '=', $artist->id)
|
||||||
->where('title', '=', $album_name)
|
->where('title', '=', $albumName)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if (!$album) {
|
if (!$album) {
|
||||||
$album = new Album;
|
$album = new Album;
|
||||||
|
|
||||||
$album->title = $album_name;
|
$album->title = $albumName;
|
||||||
$album->user_id = $artist->id;
|
$album->user_id = $artist->id;
|
||||||
$album->cover_id = $cover->id;
|
$album->cover_id = $coverId;
|
||||||
|
|
||||||
$album->save();
|
$album->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$albumId = $album->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
// Original, show song remix, fan song remix, show audio remix, or ponified song?
|
// Original, show song remix, fan song remix, show audio remix, or ponified song?
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
$track_type = TrackType::ORIGINAL_TRACK;
|
$trackType = TrackType::ORIGINAL_TRACK;
|
||||||
|
$linkedSongIds = [];
|
||||||
|
|
||||||
$sanitized_track_title = $parsedTags['title'];
|
$sanitizedTrackTitle = $parsedTags['title'];
|
||||||
$sanitized_track_title = str_replace(' - ', ' ', $sanitized_track_title);
|
$sanitizedTrackTitle = str_replace(' - ', ' ', $sanitizedTrackTitle);
|
||||||
$sanitized_track_title = str_replace('ft. ', '', $sanitized_track_title);
|
$sanitizedTrackTitle = str_replace('ft. ', '', $sanitizedTrackTitle);
|
||||||
$sanitized_track_title = str_replace('*', '', $sanitized_track_title);
|
$sanitizedTrackTitle = str_replace('*', '', $sanitizedTrackTitle);
|
||||||
|
|
||||||
$queriedTitle = DB::connection()->getPdo()->quote($sanitized_track_title);
|
$queriedTitle = DB::connection()->getPdo()->quote($sanitizedTrackTitle);
|
||||||
$officialSongs = ShowSong::select(['id', 'title'])
|
$officialSongs = ShowSong::select(['id', 'title'])
|
||||||
->whereRaw("
|
->whereRaw("
|
||||||
MATCH (title)
|
MATCH (title)
|
||||||
|
@ -235,66 +240,105 @@ class ImportMLPMA extends Command {
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
|
||||||
// It it has "Ingram" in the name, it's definitely an official song remix.
|
// If it has "Ingram" in the name, it's definitely an official song remix.
|
||||||
if (Str::contains(Str::lower($file->getFilename()), 'ingram')) {
|
if (Str::contains(Str::lower($file->getFilename()), 'ingram')) {
|
||||||
$track_type = TrackType::OFFICIAL_TRACK_REMIX;
|
|
||||||
$this->comment('This is an official song remix!');
|
$this->comment('This is an official song remix!');
|
||||||
|
|
||||||
foreach($officialSongs as $song) {
|
list($trackType, $linkedSongIds) = $this->classifyTrack($file, $officialSongs, true);
|
||||||
$this->comment('=> Matched official song: ['.$song->id.'] '.$song->title);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sizeof($officialSongs) === 1) {
|
|
||||||
$linkedSongIds = [$officialSongs[0]->id];
|
|
||||||
} else {
|
|
||||||
list($track_type, $linkedSongIds) = $this->classifyTrack($officialSongs);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// If it has "remix" in the name, it's definitely a remix.
|
// If it has "remix" in the name, it's definitely a remix.
|
||||||
} else if (Str::contains(Str::lower($sanitized_track_title), 'remix')) {
|
} else if (Str::contains(Str::lower($sanitizedTrackTitle), 'remix')) {
|
||||||
$this->comment('This is some kind of remix!');
|
$this->comment('This is some kind of remix!');
|
||||||
|
|
||||||
foreach($officialSongs as $song) {
|
list($trackType, $linkedSongIds) = $this->classifyTrack($file, $officialSongs);
|
||||||
$this->comment('=> Matched official song: [' . $song->id . '] ' . $song->title);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
// Save this track.
|
// Save this track.
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
|
$title = $parsedTags['title'];
|
||||||
|
|
||||||
// TODO: use these variables
|
// Has this track already been imported?
|
||||||
$cover;
|
$track = Track::where('user_id', '=', $artist->id)
|
||||||
$album;
|
->where('title', '=', $title)
|
||||||
$cover_id;
|
->first();
|
||||||
$released_at;
|
|
||||||
$is_vocal;
|
if (!$track) {
|
||||||
$track_type;
|
$track = new Track;
|
||||||
|
|
||||||
|
$track->user_id = $artist->id;
|
||||||
|
$track->title = $parsedTags['title'];
|
||||||
|
$track->cover_id = $coverId;
|
||||||
|
$track->album_id = $albumId;
|
||||||
|
$track->released_at = $releasedAt;
|
||||||
|
$track->is_vocal = $isVocal;
|
||||||
|
$track->track_type_id = $trackType;
|
||||||
|
|
||||||
|
$track->save();
|
||||||
|
|
||||||
|
if (sizeof($linkedSongIds) > 0) {
|
||||||
|
$track->showSongs()->attach($linkedSongIds);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: mark imported tracks as needing QA
|
// TODO: mark imported tracks as needing QA
|
||||||
|
} else {
|
||||||
|
$this->comment('This track has already been imported!');
|
||||||
|
}
|
||||||
|
|
||||||
echo PHP_EOL;
|
|
||||||
|
|
||||||
|
echo PHP_EOL.PHP_EOL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function classifyTrack()
|
protected function classifyTrack($file, $officialSongs, $isRemixOfOfficialTrack = false)
|
||||||
{
|
{
|
||||||
$trackTypeId = null;
|
$trackTypeId = null;
|
||||||
$linkedSongIds = [];
|
$linkedSongIds = [];
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($officialSongs as $song) {
|
||||||
|
$this->comment('=> Matched official song: [' . $song->id . '] ' . $song->title);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($isRemixOfOfficialTrack && sizeof($officialSongs) === 1) {
|
||||||
|
$linkedSongIds = [$officialSongs[0]->id];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if ($isRemixOfOfficialTrack) {
|
||||||
$this->question('Multiple official songs matched! Please enter the ID of the correct one.');
|
$this->question('Multiple official songs matched! Please enter the ID of the correct one.');
|
||||||
|
|
||||||
|
} else if (sizeof($officialSongs) > 0) {
|
||||||
|
$this->question('This looks like a remix of an official song!');
|
||||||
|
$this->question('Press "r" if the match above is right!');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->question('Exactly what kind of track is this?');
|
||||||
|
|
||||||
|
}
|
||||||
$this->question('If this is a medley, multiple song ID\'s can be separated by commas. ');
|
$this->question('If this is a medley, multiple song ID\'s can be separated by commas. ');
|
||||||
$this->question(' Other options:');
|
$this->question(' ');
|
||||||
|
$this->question(' '.$file->getFilename().' ');
|
||||||
|
$this->question(' ');
|
||||||
|
$this->question(' r = official song remix (accept all "guessed" matches) ');
|
||||||
|
$this->question(' # = official song remix (enter the ID(s) of the show song(s)) ');
|
||||||
$this->question(' a = show audio remix ');
|
$this->question(' a = show audio remix ');
|
||||||
$this->question(' f = fan track remix ');
|
$this->question(' f = fan track remix ');
|
||||||
$this->question(' p = ponified track ');
|
$this->question(' p = ponified track ');
|
||||||
$this->question(' o = original track ');
|
$this->question(' o = original track ');
|
||||||
$input = $this->ask('[#/a/f/p/o]: ');
|
$this->question(' ');
|
||||||
|
$input = $this->ask('[r/#/a/f/p/o]: ');
|
||||||
|
|
||||||
switch ($input) {
|
switch ($input) {
|
||||||
|
case 'r':
|
||||||
|
$trackTypeId = TrackType::OFFICIAL_TRACK_REMIX;
|
||||||
|
foreach ($officialSongs as $officialSong) {
|
||||||
|
$linkedSongIds[] = (int) $officialSong->id;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'a':
|
case 'a':
|
||||||
$trackTypeId = TrackType::OFFICIAL_AUDIO_REMIX;
|
$trackTypeId = TrackType::OFFICIAL_AUDIO_REMIX;
|
||||||
break;
|
break;
|
||||||
|
@ -314,10 +358,15 @@ class ImportMLPMA extends Command {
|
||||||
default:
|
default:
|
||||||
$trackTypeId = TrackType::OFFICIAL_TRACK_REMIX;
|
$trackTypeId = TrackType::OFFICIAL_TRACK_REMIX;
|
||||||
$linkedSongIds = explode(',', $input);
|
$linkedSongIds = explode(',', $input);
|
||||||
$linkedSongIds = array_map(function($item){ return (int) $item; }, $linkedSongIds);
|
$linkedSongIds = array_map(function ($item) {
|
||||||
|
return (int) $item;
|
||||||
|
}, $linkedSongIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return [$trackTypeId, $linkedSongIds];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the console command arguments.
|
* Get the console command arguments.
|
||||||
*
|
*
|
||||||
|
@ -364,20 +413,25 @@ class ImportMLPMA extends Command {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function getAtomTags($rawTags) {
|
protected function getAtomTags($rawTags) {
|
||||||
// TODO: finish this
|
$tags = $rawTags['tags']['quicktime'];
|
||||||
print_r($rawTags['tags']['quicktime']);
|
|
||||||
print_r($rawTags['quicktime']['comments']);
|
$trackNumber = null;
|
||||||
|
if (isset($tags['track_number'])) {
|
||||||
|
$trackNumberComponents = explode('/', $tags['track_number'][0]);
|
||||||
|
$trackNumber = $trackNumberComponents[0];
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'title' => null,
|
'title' => $tags['title'][0],
|
||||||
'artist' => null,
|
'artist' => $tags['artist'][0],
|
||||||
'band' => null,
|
'band' => isset($tags['band']) ? $tags['band'][0] : null,
|
||||||
'genre' => null,
|
'album_artist' => isset($tags['album_artist']) ? $tags['album_artist'][0] : null,
|
||||||
'track_number' => null,
|
'genre' => isset($tags['genre']) ? $tags['genre'][0] : null,
|
||||||
'album' => null,
|
'track_number' => $trackNumber,
|
||||||
'year' => null,
|
'album' => isset($tags['album']) ? $tags['album'][0] : null,
|
||||||
'comments' => null,
|
'year' => isset($tags['year']) ? (int) $tags['year'][0] : null,
|
||||||
'lyrics' => null,
|
'comments' => isset($tags['comments']) ? $tags['comments'][0] : null,
|
||||||
|
'lyrics' => isset($tags['lyrics']) ? $tags['lyrics'][0] : null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class AddNewIndices extends Migration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
DB::statement('ALTER TABLE `show_songs` ADD FULLTEXT show_songs_title_fulltext (title)');
|
||||||
|
|
||||||
|
Schema::table('images', function ($table) {
|
||||||
|
$table->index('hash');
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('track_files', function ($table) {
|
||||||
|
$table->index('is_master');
|
||||||
|
$table->index('format');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
DB::statement('ALTER TABLE `show_songs` DROP INDEX show_songs_title_fulltext');
|
||||||
|
|
||||||
|
Schema::table('images', function ($table) {
|
||||||
|
$table->dropIndex('images_hash_index');
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('track_files', function ($table) {
|
||||||
|
$table->dropIndex('track_files_is_master_index');
|
||||||
|
$table->dropIndex('track_files_format_index');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue