#100: Progress commit 2

This commit is contained in:
Josef Citrine 2017-02-28 22:49:46 +00:00
parent 8841bd2dc7
commit 1e153a614c

View file

@ -194,11 +194,6 @@ class ImportPonify extends Command
if ($existingFile === null) {
// Can't find a matching format
// Before we do anything, was this from MLPMA?
$mlpmaTrack = DB::table('mlpma_tracks')->where('track_id', '=', $existingTrack->id)->first();
if (!is_null($mlpmaTrack)) {
// This was from the archive
// See if we have a higher quality source file
if (Track::$Formats[$importFormat]['is_lossless']) {
// Source is lossless, is the existing track lossy?
@ -211,7 +206,6 @@ class ImportPonify extends Command
continue;
}
}
}
continue;
@ -221,6 +215,9 @@ class ImportPonify extends Command
// Found a matching format, are they the same?
// Before we check it, see if it came from MLPMA
// We're only replacing tracks with the same format if they're archived
$mlpmaTrack = DB::table('mlpma_tracks')->where('track_id', '=', $existingTrack->id)->first();
if (!is_null($mlpmaTrack)) {
$getId3_source = new getID3;
$getId3_source->option_md5_data = true;
@ -242,8 +239,23 @@ class ImportPonify extends Command
if ($importHash == $targetHash) {
// Audio is identical, no need to reupload
// We can update the metadata though
// TODO: Update metadata
$this->comment("Versions are the same. Skipping...\n");
$this->comment("Versions are the same. Updating metadata...\n");
$changedMetadata = false;
if (strlen($existingTrack->description) < strlen($parsedTags['comments'])) {
$existingTrack->description = $parsedTags['comments'];
$changedMetadata = true;
$this->comment("Updated description");
}
if (strlen($existingTrack->lyrics) < strlen($parsedTags['lyrics'])) {
$existingTrack->lyrics = $parsedTags['lyrics'];
$changedMetadata = true;
$this->comment("Updated lyrics");
}
if ($changedMetadata) $existingTrack->save();
continue;
} else {
// Audio is different, let's replace it
@ -251,6 +263,27 @@ class ImportPonify extends Command
$this->replaceTrack($file, $existingTrack, $artist, $allTags['mime_type']);
continue;
}
} else {
$this->comment("Not replacing, user uploaded");
// We can update the metadata though
$changedMetadata = false;
if (strlen($existingTrack->description) < strlen($parsedTags['comments'])) {
$existingTrack->description = $parsedTags['comments'];
$changedMetadata = true;
$this->comment("Updated description");
}
if (strlen($existingTrack->lyrics) < strlen($parsedTags['lyrics'])) {
$existingTrack->lyrics = $parsedTags['lyrics'];
$changedMetadata = true;
$this->comment("Updated lyrics");
}
if ($changedMetadata) $existingTrack->save();
continue;
}
}
@ -341,6 +374,18 @@ class ImportPonify extends Command
$track->cover_id = $coverId;
$track->license_id = 2;
$track->save();
// If we made it to here, the track is intact! Log the import.
DB::table('ponify_tracks')
->insert([
'track_id' => $result->getResponse()['id'],
'path' => $file->getRelativePath(),
'filename' => $file->getFilename(),
'extension' => $file->getExtension(),
'imported_at' => Carbon::now(),
'parsed_tags' => json_encode($parsedTags),
'raw_tags' => json_encode($rawTags),
]);
}
echo PHP_EOL . PHP_EOL;