Skip to content

Commit

Permalink
swap artist names only if album is from library
Browse files Browse the repository at this point in the history
partial fix for #180
  • Loading branch information
RocketMan committed Oct 16, 2023
1 parent ff4f3af commit 7ebabdd
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
12 changes: 7 additions & 5 deletions api/Playlists.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]);
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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"]);
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/ArtworkControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions controllers/ExportPlaylist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down Expand Up @@ -249,7 +249,7 @@ public function emitHTML() {
$break = true;
}
})->onSpin(function($entry) use(&$break) {
echo " <TR><TD ALIGN=LEFT VALIGN=TOP>".htmlentities(PlaylistEntry::swapNames($entry->getArtist())) . "</TD><TD ALIGN=LEFT VALIGN=TOP>" .
echo " <TR><TD ALIGN=LEFT VALIGN=TOP>".htmlentities($entry->getTag() ? PlaylistEntry::swapNames($entry->getArtist()) : $entry->getArtist()) . "</TD><TD ALIGN=LEFT VALIGN=TOP>" .
htmlentities($entry->getTrack()). "</TD><TD ALIGN=LEFT>" .
htmlentities($entry->getAlbum()). "<BR><FONT CLASS=\"sub\">" .
htmlentities($entry->getLabel()). "</FONT></TD><TD ALIGN=RIGHT VALIGN=TOP>";
Expand Down
6 changes: 4 additions & 2 deletions controllers/PushServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) ||
Expand Down
5 changes: 3 additions & 2 deletions engine/PlaylistEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
}
Expand Down Expand Up @@ -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"]);
}
Expand Down
2 changes: 1 addition & 1 deletion ui/PlaylistBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected function __construct(array $params) {
$created = $entry->getCreatedTimestamp();
$timeplayed = self::timestampToLocale($created);
$reviewCell = $entry->getReviewed() ? "<div class='albumReview'></div>" : "";
$artistName = PlaylistEntry::swapNames($entry->getArtist());
$artistName = $entry->getTag() ? PlaylistEntry::swapNames($entry->getArtist()) : $entry->getArtist();

$albumLink = $this->makeAlbumLink($entry, true);
echo "<tr class='songRow'>" . $editCell .
Expand Down

0 comments on commit 7ebabdd

Please sign in to comment.