From 7ebabdd1668e30c170f174f4e322c384bf1e0ed0 Mon Sep 17 00:00:00 2001 From: Jim Mason Date: Mon, 16 Oct 2023 15:07:27 +0100 Subject: [PATCH] swap artist names only if album is from library partial fix for #180 --- api/Playlists.php | 12 +++++++----- controllers/ArtworkControl.php | 2 +- controllers/ExportPlaylist.php | 4 ++-- controllers/PushServer.php | 6 ++++-- engine/PlaylistEntry.php | 5 +++-- ui/PlaylistBuilder.php | 2 +- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/api/Playlists.php b/api/Playlists.php index fea0ed78..dd654d17 100644 --- a/api/Playlists.php +++ b/api/Playlists.php @@ -168,7 +168,8 @@ public static function fromRecord($rec, $flags) { })->onSpin(function($entry) use(&$events, $relations, $flags) { $spin = $entry->asArray(); $spin["type"] = "spin"; - $spin["artist"] = PlaylistEntry::swapNames($spin["artist"]); + if($spin["tag"]) + $spin["artist"] = PlaylistEntry::swapNames($spin["artist"]); $spin["created"] = $entry->getCreatedTime(); if($spin["tag"] && $flags & self::LINKS_ALBUMS) { $tag = $spin["tag"]; @@ -317,11 +318,11 @@ public function fetchRelationship(RequestInterface $request): ResponseInterface unset($attrs["tag"]); unset($attrs["id"]); $a->merge($attrs); - $a->set("artist", PlaylistEntry::swapNames($entry->getArtist())); $a->set("created", $entry->getCreatedTime()); $tag = $entry->getTag(); if($tag) { + $a->set("artist", PlaylistEntry::swapNames($entry->getArtist())); if($flags && sizeof($albums = Engine::api(ILibrary::class)->search(ILibrary::ALBUM_KEY, 0, 1, $tag))) $res = Albums::fromArray($albums, $flags)[0]; else @@ -665,7 +666,7 @@ public function addRelatedResources(RequestInterface $request): ResponseInterfac // don't allow modification of album info if tag is set $entry->setTag($album->id()); if(!$albumrec[0]["iscoll"]) - $entry->setArtist(PlaylistEntry::swapNames($albumrec[0]["artist"])); + $entry->setArtist($albumrec[0]["artist"]); $entry->setAlbum($albumrec[0]["album"]); $entry->setLabel($albumrec[0]["name"]); } @@ -717,7 +718,8 @@ public function addRelatedResources(RequestInterface $request): ResponseInterfac $list['id'] = $key; if($entry->isType(PlaylistEntry::TYPE_SPIN)) { $spin = $entry->asArray(); - $spin['artist'] = PlaylistEntry::swapNames($spin['artist']); + if($spin['tag']) + $spin['artist'] = PlaylistEntry::swapNames($spin['artist']); } else $spin = null; @@ -790,7 +792,7 @@ public function replaceRelatedResources(RequestInterface $request): ResponseInte // don't allow modification of album info if tag is set $entry->setTag($album->id()); if(!$albumrec[0]["iscoll"]) - $entry->setArtist(PlaylistEntry::swapNames($albumrec[0]["artist"])); + $entry->setArtist($albumrec[0]["artist"]); $entry->setAlbum($albumrec[0]["album"]); $entry->setLabel($albumrec[0]["name"]); } diff --git a/controllers/ArtworkControl.php b/controllers/ArtworkControl.php index 9a2de718..1e717e35 100644 --- a/controllers/ArtworkControl.php +++ b/controllers/ArtworkControl.php @@ -39,7 +39,7 @@ protected function refreshList($playlist) { Engine::api(IPlaylist::class)->getTracksWithObserver($playlist, (new PlaylistObserver())->on('spin', function($entry) use($imageApi, &$count) { if(!$entry->getTag() && $entry->getCreated()) { - $artist = PlaylistEntry::swapNames($entry->getArtist()); + $artist = $entry->getArtist(); if($this->verbose) echo " deleting $artist\n"; $imageApi->deleteArtistArt($artist); diff --git a/controllers/ExportPlaylist.php b/controllers/ExportPlaylist.php index fb54b0ae..badb5a87 100644 --- a/controllers/ExportPlaylist.php +++ b/controllers/ExportPlaylist.php @@ -177,7 +177,7 @@ public function emitCSV() { // emit the tracks echo "Artist\tTrack\tAlbum\tTag\tLabel\tTimestamp\n"; $observer = (new PlaylistObserver())->onSpin(function($entry) { - echo $entry->getArtist()."\t". + echo ($entry->getTag() ? PlaylistEntry::swapNames($entry->getArtist()) : $entry->getArtist())."\t". $entry->getTrack()."\t". $entry->getAlbum()."\t". $entry->getTag()."\t". @@ -249,7 +249,7 @@ public function emitHTML() { $break = true; } })->onSpin(function($entry) use(&$break) { - echo " ".htmlentities(PlaylistEntry::swapNames($entry->getArtist())) . "" . + echo " ".htmlentities($entry->getTag() ? PlaylistEntry::swapNames($entry->getArtist()) : $entry->getArtist()) . "" . htmlentities($entry->getTrack()). "" . htmlentities($entry->getAlbum()). "
" . htmlentities($entry->getLabel()). ""; diff --git a/controllers/PushServer.php b/controllers/PushServer.php index 7ff3686e..7dae30c4 100644 --- a/controllers/PushServer.php +++ b/controllers/PushServer.php @@ -154,7 +154,8 @@ protected function loadOnNow() { $filter = Engine::api(IPlaylist::class)->getTracksWithObserver($show['id'], (new PlaylistObserver())->onSpin(function($entry) use(&$event) { $spin = $entry->asArray(); - $spin['artist'] = PlaylistEntry::swapNames($spin['artist']); + if($spin['tag']) + $spin['artist'] = PlaylistEntry::swapNames($spin['artist']); $event = $spin; })->on('comment logEvent setSeparator', function($entry) use(&$event) { $event = null; @@ -460,7 +461,8 @@ protected function enqueueEntry($entry, $imageApi) { } // fixup artist name - $entry->setArtist(PlaylistEntry::swapNames($entry->getArtist())); + if($entry->getTag()) + $entry->setArtist(PlaylistEntry::swapNames($entry->getArtist())); if($entry->getTag() && $imageApi->getAlbumArt($entry->getTag(), true) || diff --git a/engine/PlaylistEntry.php b/engine/PlaylistEntry.php index 16a85e03..dcee3593 100644 --- a/engine/PlaylistEntry.php +++ b/engine/PlaylistEntry.php @@ -186,7 +186,7 @@ public static function fromJSON($json) { // don't allow modification of album info if tag is set $entry->setTag($a); if(!$albumrec[0]["iscoll"]) - $entry->setArtist(self::swapNames($albumrec[0]["artist"])); + $entry->setArtist($albumrec[0]["artist"]); $entry->setAlbum($albumrec[0]["album"]); $entry->setLabel($albumrec[0]["name"]); } @@ -221,7 +221,8 @@ public static function fromArray($array) { if(sizeof($albumrec)) { // don't allow modification of album info if tag is set $entry->setTag($album->id()); - $entry->setArtist(self::swapNames($albumrec[0]["artist"])); + if(!$albumrec[0]["iscoll"]) + $entry->setArtist($albumrec[0]["artist"]); $entry->setAlbum($albumrec[0]["album"]); $entry->setLabel($albumrec[0]["name"]); } diff --git a/ui/PlaylistBuilder.php b/ui/PlaylistBuilder.php index 51a1caf1..66dfb359 100644 --- a/ui/PlaylistBuilder.php +++ b/ui/PlaylistBuilder.php @@ -125,7 +125,7 @@ protected function __construct(array $params) { $created = $entry->getCreatedTimestamp(); $timeplayed = self::timestampToLocale($created); $reviewCell = $entry->getReviewed() ? "
" : ""; - $artistName = PlaylistEntry::swapNames($entry->getArtist()); + $artistName = $entry->getTag() ? PlaylistEntry::swapNames($entry->getArtist()) : $entry->getArtist(); $albumLink = $this->makeAlbumLink($entry, true); echo "" . $editCell .