mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-22 13:07:59 +01:00
Fixed some null errors
This commit is contained in:
parent
23acd16b64
commit
61e907ca37
1 changed files with 69 additions and 66 deletions
|
@ -92,9 +92,9 @@ class ImportPonify extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
$UNKNOWN_GENRE = Genre::firstOrCreate([
|
$UNKNOWN_GENRE = Genre::firstOrCreate([
|
||||||
'name' => 'Unknown',
|
'name' => 'Unknown',
|
||||||
'slug' => 'unknown'
|
'slug' => 'unknown'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
// Get the list of files and artists
|
// Get the list of files and artists
|
||||||
|
@ -172,58 +172,58 @@ class ImportPonify extends Command
|
||||||
$this->info('Title: ' . $parsedTags['title']);
|
$this->info('Title: ' . $parsedTags['title']);
|
||||||
|
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
// Determine the release date.
|
// Determine the release date.
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
$modifiedDate = Carbon::createFromTimeStampUTC(File::lastModified($file->getPathname()));
|
$modifiedDate = Carbon::createFromTimeStampUTC(File::lastModified($file->getPathname()));
|
||||||
$taggedYear = $parsedTags['year'];
|
$taggedYear = $parsedTags['year'];
|
||||||
|
|
||||||
$this->info('Modification year: '.$modifiedDate->year);
|
$this->info('Modification year: '.$modifiedDate->year);
|
||||||
$this->info('Tagged year: '.$taggedYear);
|
$this->info('Tagged year: '.$taggedYear);
|
||||||
|
|
||||||
if ($taggedYear !== null && $modifiedDate->year === $taggedYear) {
|
if ($taggedYear !== null && $modifiedDate->year === $taggedYear) {
|
||||||
$releasedAt = $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...');
|
||||||
$releasedAt = 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...');
|
||||||
$releasedAt = $modifiedDate;
|
$releasedAt = $modifiedDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is later used by the classification/publishing script to determine the publication date.
|
// This is later used by the classification/publishing script to determine the publication date.
|
||||||
$parsedTags['released_at'] = $releasedAt->toDateTimeString();
|
$parsedTags['released_at'] = $releasedAt->toDateTimeString();
|
||||||
|
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
// Does this track have vocals?
|
// Does this track have vocals?
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
$isVocal = $parsedTags['lyrics'] !== null;
|
$isVocal = $parsedTags['lyrics'] !== null;
|
||||||
|
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
// Determine the genre
|
// Determine the genre
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
$genreName = $parsedTags['genre'];
|
$genreName = $parsedTags['genre'];
|
||||||
$this->info('Genre: '.$genreName);
|
$this->info('Genre: '.$genreName);
|
||||||
|
|
||||||
if ($genreName) {
|
if ($genreName) {
|
||||||
$genre = Genre::where('name', '=', $genreName)->first();
|
$genre = Genre::where('name', '=', $genreName)->first();
|
||||||
if ($genre) {
|
if ($genre) {
|
||||||
$genreId = $genre->id;
|
$genreId = $genre->id;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$genre = new Genre();
|
$genre = new Genre();
|
||||||
$genre->name = $genreName;
|
$genre->name = $genreName;
|
||||||
$genre->slug = Str::slug($genreName);
|
$genre->slug = Str::slug($genreName);
|
||||||
$genre->save();
|
$genre->save();
|
||||||
$genreId = $genre->id;
|
$genreId = $genre->id;
|
||||||
$this->comment('Created a new genre!');
|
$this->comment('Created a new genre!');
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$genreId = $UNKNOWN_GENRE->id; // "Unknown" genre ID
|
$genreId = $UNKNOWN_GENRE->id; // "Unknown" genre ID
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
// Check to see if we have this track already, if so, compare hashes of the two files
|
// Check to see if we have this track already, if so, compare hashes of the two files
|
||||||
|
@ -423,28 +423,29 @@ class ImportPonify extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
// Is this part of an album?
|
// Is this part of an album?
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
$albumId = null;
|
$albumId = null;
|
||||||
$albumName = $parsedTags['album'];
|
$albumName = $parsedTags['album'];
|
||||||
|
|
||||||
if ($albumName !== null) {
|
if ($albumName !== null) {
|
||||||
$album = Album::where('user_id', '=', $artist->id)
|
$album = Album::where('user_id', '=', $artist->id)
|
||||||
->where('title', '=', $albumName)
|
->where('title', '=', $albumName)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if (!$album) {
|
if (!$album) {
|
||||||
$album = new Album;
|
$album = new Album;
|
||||||
|
|
||||||
$album->title = $albumName;
|
$album->title = $albumName;
|
||||||
$album->user_id = $artist->id;
|
$album->user_id = $artist->id;
|
||||||
$album->cover_id = $coverId;
|
$album->cover_id = $coverId;
|
||||||
|
$album->description = "";
|
||||||
|
|
||||||
$album->save();
|
$album->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
$albumId = $album->id;
|
$albumId = $album->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
// Send the track into the upload system like a user just uploaded a track
|
// Send the track into the upload system like a user just uploaded a track
|
||||||
|
@ -468,12 +469,14 @@ class ImportPonify extends Command
|
||||||
$track = Track::find($result->getResponse()['id']);
|
$track = Track::find($result->getResponse()['id']);
|
||||||
$track->cover_id = $coverId;
|
$track->cover_id = $coverId;
|
||||||
$track->album_id = $albumId;
|
$track->album_id = $albumId;
|
||||||
$track->genre_id = $genreId;
|
$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->is_downloadable = true;
|
$track->is_downloadable = true;
|
||||||
$track->is_vocal = $isVocal;
|
$track->is_vocal = $isVocal;
|
||||||
$track->license_id = 2;
|
$track->license_id = 2;
|
||||||
|
$track->description = "";
|
||||||
|
$track->lyrics = "";
|
||||||
|
|
||||||
if (!is_null($parsedTags['comments'])) {
|
if (!is_null($parsedTags['comments'])) {
|
||||||
$track->description = $parsedTags['comments'];
|
$track->description = $parsedTags['comments'];
|
||||||
|
|
Loading…
Reference in a new issue