« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/common-util/wiki-data.js4
-rw-r--r--src/data/things/Track.js23
-rw-r--r--src/data/things/album/Album.js67
-rw-r--r--src/gen-thumbs.js4
-rw-r--r--src/urls-default.yaml9
5 files changed, 52 insertions, 55 deletions
diff --git a/src/common-util/wiki-data.js b/src/common-util/wiki-data.js
index a8c9ac8a..d407cb4e 100644
--- a/src/common-util/wiki-data.js
+++ b/src/common-util/wiki-data.js
@@ -177,7 +177,7 @@ export function filterAlbumsByCommentary(albums) {
 export function getAlbumCover(album, {to}) {
   // Some albums don't have art! This function returns null in that case.
   if (album.hasCoverArt) {
-    return to('media.albumCover', album.directory, album.coverArtFileExtension);
+    return to(...album.coverArtworks[0].path);
   } else {
     return null;
   }
@@ -274,7 +274,7 @@ export function getTrackCover(track, {to}) {
   if (!track.hasUniqueCoverArt) {
     return getAlbumCover(track.album, {to});
   } else {
-    return to('media.trackCover', track.album.directory, track.directory, track.coverArtFileExtension);
+    return to(...track.trackArtworks[0].path);
   }
 }
 
diff --git a/src/data/things/Track.js b/src/data/things/Track.js
index ae527be6..a615af4a 100644
--- a/src/data/things/Track.js
+++ b/src/data/things/Track.js
@@ -1464,16 +1464,13 @@ export class Track extends Thing {
   getOwnArtworkPath(artwork) {
     if (!this.album) return null;
 
-    return [
-      'media.trackCover',
-      this.album.directory,
-
+    const ext = artwork.fileExtension;
+    const basename =
       (artwork.unqualifiedDirectory
         ? this.directory + '-' + artwork.unqualifiedDirectory
-        : this.directory),
+        : this.directory);
 
-      artwork.fileExtension,
-    ];
+    return this.album.getAlbumArtPath(`${basename}.${ext}`);
   }
 
   getOwnMusicVideoCoverPath(musicVideo) {
@@ -1489,12 +1486,12 @@ export class Track extends Thing {
         ? ''
         : this.directory + '-');
 
-    return [
-      'media.trackCover',
-      this.album.directory,
-      trackPrefix + musicVideo.unqualifiedDirectory,
-      musicVideo.coverArtFileExtension,
-    ];
+    const filename =
+      trackPrefix +
+      musicVideo.unqualifiedDirectory +
+      `.${musicVideo.coverArtFileExtension}`;
+
+    return this.album.getAlbumArtPath(filename);
   }
 
   countOwnContributionInContributionTotals(_contrib) {
diff --git a/src/data/things/album/Album.js b/src/data/things/album/Album.js
index 44eb1181..7efc2d8c 100644
--- a/src/data/things/album/Album.js
+++ b/src/data/things/album/Album.js
@@ -922,53 +922,54 @@ export class Album extends Thing {
   }
 
   getOwnArtworkPath(artwork) {
+    const ext = artwork.fileExtension;
+
     if (artwork === this.bannerArtwork) {
-      return [
-        'media.albumBanner',
-        this.directory,
-        artwork.fileExtension,
-      ];
+      return this.getAlbumArtPath(`banner.${ext}`);
     }
 
     if (artwork === this.wallpaperArtwork) {
-      if (!empty(this.wallpaperParts)) {
+      if (empty(this.wallpaperParts)) {
+        return this.getAlbumArtPath(`bg.${ext}`);
+      } else {
         return null;
       }
-
-      return [
-        'media.albumWallpaper',
-        this.directory,
-        artwork.fileExtension,
-      ];
     }
 
-    // TODO: using trackCover here is obviously, badly wrong
-    // but we ought to refactor banners and wallpapers similarly
-    // (i.e. depend on those intrinsic artwork paths rather than
-    // accessing media.{albumBanner,albumWallpaper} from content
-    // or other code directly)
-    return [
-      'media.trackCover',
-      this.directory,
-
+    const basename =
       (artwork.unqualifiedDirectory
         ? 'cover-' + artwork.unqualifiedDirectory
-        : 'cover'),
+        : 'cover');
 
-      artwork.fileExtension,
-    ];
+    return this.getAlbumArtPath(`${basename}.${ext}`);
+  }
+
+  getWallpaperPartPath(part) {
+    return this.getAlbumArtPath(part.asset);
   }
 
   getOwnMusicVideoCoverPath(musicVideo) {
-    // Lala, same shenanigan as above, this is media.trackCover
-    // where it shouldn't be.
-
-    return [
-      'media.trackCover',
-      this.directory,
-      musicVideo.unqualifiedDirectory,
-      musicVideo.coverArtFileExtension,
-    ];
+    const filename =
+      musicVideo.unqualifiedDirectory +
+      `.${musicVideo.coverArtFileExtension}`;
+
+    return this.getAlbumArtPath(filename);
+  }
+
+  getAlbumArtPath(filename) {
+    const key = this.#getArtworkPathKey();
+    const front = [key, this.directory];
+    return [...front, filename];
+  }
+
+  #getArtworkPathKey(artwork) {
+    switch (this.style) {
+      case 'in-game vgm':
+        return 'media.vgmAlbumArt';
+
+      default:
+        return 'media.albumArt';
+    }
   }
 
   // As of writing, albums don't even have a `duration` property...
diff --git a/src/gen-thumbs.js b/src/gen-thumbs.js
index a58e96d5..d452c22e 100644
--- a/src/gen-thumbs.js
+++ b/src/gen-thumbs.js
@@ -1231,8 +1231,8 @@ export function getExpectedImagePaths(mediaPath, {urls, wikiData}) {
     wikiData.albumData
       .flatMap(album => album.wallpaperParts
         .filter(part => part.asset)
-        .map(part =>
-          fromRoot.to('media.albumWallpaperPart', album.directory, part.asset))),
+        .map(part => album.getWallpaperPartPath(part))
+        .map(path => fromRoot.to(...path))),
 
     wikiData.musicVideoData
       .filter(musicVideo => musicVideo.path)
diff --git a/src/urls-default.yaml b/src/urls-default.yaml
index 5c6f7245..b88b7286 100644
--- a/src/urls-default.yaml
+++ b/src/urls-default.yaml
@@ -126,16 +126,15 @@ media:
 
   - albumAdditionalFile: 'album-additional/<>/<>'
     albumAdditionalFileInFolder: 'album-additional/<>/<>/<>'
-    albumBanner: 'album-art/<>/banner.<>'
-    albumCover: 'album-art/<>/cover.<>'
-    albumWallpaper: 'album-art/<>/bg.<>'
-    albumWallpaperPart: 'album-art/<>/<>'
+    albumArt: 'album-art/<>/<>'
 
     artistAvatar: 'artist-avatar/<>.<>'
 
     flashArt: 'flash-art/<>.<>'
 
-    trackCover: 'album-art/<>/<>.<>'
+    vgmAlbumAdditionalFile: 'vgm-album-additional/<>/<>'
+    vgmAlbumAdditionalFileInFolder: 'vgm-album-additional/<>/<>/<>'
+    vgmAlbumArt: 'vgm-album-art/<>/<>'
 
 thumb:
   prefix: 'thumb/'