chore(api/*): cleans up unnecessary network calls, fixes tag + genre assignments
This commit is contained in:
parent
8890f7dcfc
commit
5a133a7c23
5 changed files with 33 additions and 44 deletions
|
@ -37,9 +37,11 @@ class ArtistImportHandler extends ApiHandler
|
|||
|
||||
try {
|
||||
$artistData = $this->fetchNavidromeArtist($artistId);
|
||||
$artistExists = $this->processArtist($artistData);
|
||||
$albumData = $this->fetchNavidromeAlbums($artistId);
|
||||
$genre = $albumData[0]["genre"] ?? ($albumData[0]["genres"][0]["name"] ?? "");
|
||||
$artistExists = $this->processArtist($artistData, $genre);
|
||||
|
||||
if ($artistExists) $this->processAlbums($artistId, $artistData->name);
|
||||
if ($artistExists) $this->processAlbums($artistId, $artistData->name, $albumData);
|
||||
|
||||
$this->sendJsonResponse("message", "Artist and albums synced successfully", 200);
|
||||
} catch (\Exception $e) {
|
||||
|
@ -90,7 +92,7 @@ class ArtistImportHandler extends ApiHandler
|
|||
return json_decode($response->getBody(), true);
|
||||
}
|
||||
|
||||
private function processArtist(object $artistData): bool
|
||||
private function processArtist(object $artistData, string $genreName = ""): bool
|
||||
{
|
||||
$artistName = $artistData->name ?? "";
|
||||
|
||||
|
@ -103,7 +105,7 @@ class ArtistImportHandler extends ApiHandler
|
|||
$artistKey = sanitizeMediaString($artistName);
|
||||
$slug = "/music/artists/{$artistKey}";
|
||||
$description = strip_tags($artistData->biography ?? "");
|
||||
$genre = $this->resolveGenreId($artistData->genres[0]->name ?? "");
|
||||
$genre = $this->resolveGenreId(strtolower($genreName));
|
||||
$starred = $artistData->starred ?? false;
|
||||
$artistPayload = [
|
||||
"name_string" => $artistName,
|
||||
|
@ -121,7 +123,7 @@ class ArtistImportHandler extends ApiHandler
|
|||
return true;
|
||||
}
|
||||
|
||||
private function processAlbums(string $artistId, string $artistName): void
|
||||
private function processAlbums(string $artistId, string $artistName, array $albumData): void
|
||||
{
|
||||
$artist = $this->getArtistByName($artistName);
|
||||
|
||||
|
@ -129,9 +131,8 @@ class ArtistImportHandler extends ApiHandler
|
|||
|
||||
$existingAlbums = $this->getExistingAlbums($artist["id"]);
|
||||
$existingAlbumKeys = array_column($existingAlbums, "key");
|
||||
$navidromeAlbums = $this->fetchNavidromeAlbums($artistId);
|
||||
|
||||
foreach ($navidromeAlbums as $album) {
|
||||
foreach ($albumData as $album) {
|
||||
$albumName = $album["name"] ?? "";
|
||||
$releaseYearRaw = $album["date"] ?? null;
|
||||
$releaseYear = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue