From 9332da311819d4ec9fa19b327271e3fab1dc49e8 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 14 Aug 2023 21:52:03 -0300 Subject: data: remove 'Has Track Art', compute from credits --- src/data/things/album.js | 1 - src/data/things/track.js | 43 ++++++++++++++++++++++++++----------------- src/data/yaml.js | 1 - src/util/wiki-data.js | 2 +- 4 files changed, 27 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/data/things/album.js b/src/data/things/album.js index d371f51f..0c87b7c1 100644 --- a/src/data/things/album.js +++ b/src/data/things/album.js @@ -104,7 +104,6 @@ export class Album extends Thing { update: {validate: isDimensions}, }, - hasTrackArt: Thing.common.flag(true), hasTrackNumbers: Thing.common.flag(true), isListedOnHomepage: Thing.common.flag(true), isListedInGalleries: Thing.common.flag(true), diff --git a/src/data/things/track.js b/src/data/things/track.js index 00585c1e..a0a4ff41 100644 --- a/src/data/things/track.js +++ b/src/data/things/track.js @@ -1,9 +1,10 @@ import Thing from './thing.js'; import {inspect} from 'util'; -import {color} from '../../util/cli.js'; +import {color} from '../../util/cli.js'; import find from '../../util/find.js'; +import {empty} from '../../util/sugar.js'; export class Track extends Thing { static [Thing.referenceType] = 'track'; @@ -332,36 +333,44 @@ export class Track extends Thing { albumData?.find((album) => album.tracks.includes(track)); // Another reused utility function. This one's logic is a bit more complicated. - static hasCoverArt = ( + static hasCoverArt( track, albumData, coverArtistContribsByRef, hasCoverArt - ) => ( - hasCoverArt ?? - (coverArtistContribsByRef?.length > 0 || null) ?? - Track.findAlbum(track, albumData)?.hasTrackArt ?? - true - ); - - // Now this is a doozy! + ) { + if (!empty(coverArtistContribsByRef)) { + return true; + } + + const album = Track.findAlbum(track, albumData); + if (album && !empty(album.trackCoverArtistContribsByRef)) { + return true; + } + + return false; + } + static hasUniqueCoverArt( track, albumData, coverArtistContribsByRef, hasCoverArt ) { - if (coverArtistContribsByRef?.length > 0) { + if (!empty(coverArtistContribsByRef)) { return true; - } else if (coverArtistContribsByRef) { - return false; - } else if (hasCoverArt === false) { + } + + if (hasCoverArt === false) { return false; - } else if (Track.findAlbum(track, albumData)?.hasTrackArt) { + } + + const album = Track.findAlbum(track, albumData); + if (album && !empty(album.trackCoverArtistContribsByRef)) { return true; - } else { - return false; } + + return false; } [inspect.custom]() { diff --git a/src/data/yaml.js b/src/data/yaml.js index 25dfecb3..d8067a40 100644 --- a/src/data/yaml.js +++ b/src/data/yaml.js @@ -193,7 +193,6 @@ export const processAlbumDocument = makeProcessDocument(T.Album, { color: 'Color', urls: 'URLs', - hasTrackArt: 'Has Track Art', hasTrackNumbers: 'Has Track Numbers', isListedOnHomepage: 'Listed on Homepage', isListedInGalleries: 'Listed in Galleries', diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js index 97a3f3e5..6930496f 100644 --- a/src/util/wiki-data.js +++ b/src/util/wiki-data.js @@ -715,7 +715,7 @@ export function getTrackCover(track, {to}) { // just inherits the album's own cover art. Note that since cover art isn't // guaranteed on albums either, it's possible that this function returns // null! - if (!track.hasCoverArt) { + if (!track.hasUniqueCoverArt) { return getAlbumCover(track.album, {to}); } else { return to('media.trackCover', track.album.directory, track.directory, track.coverArtFileExtension); -- cgit 1.3.0-6-gf8a5