add filepath replacement setting (#1402)

This commit is contained in:
jeffvli
2026-01-01 21:46:58 -08:00
parent e406b27170
commit 6aeec1e89c
13 changed files with 594 additions and 165 deletions
@@ -1,6 +1,7 @@
import { z } from 'zod';
import { jfType } from '/@/shared/api/jellyfin/jellyfin-types';
import { replacePathPrefix } from '/@/shared/api/utils';
import {
Album,
AlbumArtist,
@@ -108,6 +109,8 @@ const getPlaylistImageId = (item: z.infer<typeof jfType._response.playlist>): nu
const normalizeSong = (
item: z.infer<typeof jfType._response.song>,
server: null | ServerListItem,
pathReplace?: string,
pathReplaceWith?: string,
): Song => {
let bitRate = 0;
let channels: null | number = null;
@@ -208,7 +211,10 @@ const normalizeSong = (
mbzTrackId: item.ProviderIds?.MusicBrainzTrack || null,
name: item.Name,
participants: getPeople(item),
path,
path:
path && (pathReplace || pathReplaceWith)
? replacePathPrefix(path, pathReplace || '', pathReplaceWith || '')
: path,
peak: null,
playCount: (item.UserData && item.UserData.PlayCount) || 0,
playlistItemId: item.PlaylistItemId,
@@ -2,6 +2,7 @@ import z from 'zod';
import { ndType } from '/@/shared/api/navidrome/navidrome-types';
import { ssType } from '/@/shared/api/subsonic/subsonic-types';
import { replacePathPrefix } from '/@/shared/api/utils';
import {
Album,
AlbumArtist,
@@ -139,6 +140,8 @@ const getArtists = (
const normalizeSong = (
item: z.infer<typeof ndType._response.playlistSong> | z.infer<typeof ndType._response.song>,
server?: null | ServerListItem,
pathReplace?: string,
pathReplaceWith?: string,
): Song => {
let id;
let playlistItemId;
@@ -202,7 +205,7 @@ const normalizeSong = (
name: item.title,
// Thankfully, Windows is merciful and allows a mix of separators. So, we can use the
// POSIX separator here instead
path: (item.libraryPath ? item.libraryPath + '/' : '') + item.path,
path: item.path ? replacePathPrefix(item.path, pathReplace, pathReplaceWith) : null,
peak:
item.rgAlbumPeak || item.rgTrackPeak
? { album: item.rgAlbumPeak, track: item.rgTrackPeak }
@@ -267,6 +270,8 @@ const normalizeAlbum = (
songs?: z.infer<typeof ndType._response.songList>;
},
server?: null | ServerListItem,
pathReplace?: string,
pathReplaceWith?: string,
): Album => {
return {
...parseAlbumTags(item),
@@ -309,7 +314,9 @@ const normalizeAlbum = (
releaseYear: item.maxYear || null,
size: item.size,
songCount: item.songCount,
songs: item.songs ? item.songs.map((song) => normalizeSong(song, server)) : undefined,
songs: item.songs
? item.songs.map((song) => normalizeSong(song, server, pathReplace, pathReplaceWith))
: undefined,
tags: item.tags || null,
updatedAt: item.updatedAt,
userFavorite: item.starred || false,
+13 -3
View File
@@ -1,6 +1,7 @@
import { z } from 'zod';
import { ssType } from '/@/shared/api/subsonic/subsonic-types';
import { replacePathPrefix } from '/@/shared/api/utils';
import {
Album,
AlbumArtist,
@@ -117,6 +118,8 @@ const getGenres = (
const normalizeSong = (
item: z.infer<typeof ssType._response.song>,
server?: null | ServerListItemWithCredential,
pathReplace?: string,
pathReplaceWith?: string,
): Song => {
return {
_itemType: LibraryItem.SONG,
@@ -162,7 +165,10 @@ const normalizeSong = (
mbzTrackId: null,
name: item.title,
participants: getParticipants(item),
path: item.path,
path:
pathReplace || pathReplaceWith
? replacePathPrefix(item.path || '', pathReplace, pathReplaceWith)
: item.path,
peak:
item.replayGain && (item.replayGain.albumPeak || item.replayGain.trackPeak)
? {
@@ -243,6 +249,8 @@ const getReleaseType = (
const normalizeAlbum = (
item: z.infer<typeof ssType._response.album> | z.infer<typeof ssType._response.albumListEntry>,
server?: null | ServerListItemWithCredential,
pathReplace?: string,
pathReplaceWith?: string,
): Album => {
return {
_itemType: LibraryItem.ALBUM,
@@ -286,7 +294,7 @@ const normalizeAlbum = (
songCount: item.songCount,
songs:
(item as z.infer<typeof ssType._response.album>).song?.map((song) =>
normalizeSong(song, server),
normalizeSong(song, server, pathReplace, pathReplaceWith),
) || [],
tags: null,
updatedAt: item.created,
@@ -341,6 +349,8 @@ const normalizeGenre = (
const normalizeFolder = (
item: z.infer<typeof ssType._response.directory>,
server?: null | ServerListItemWithCredential,
pathReplace?: string,
pathReplaceWith?: string,
): Folder => {
const results = item.child?.reduce(
(acc: { folders: Folder[]; songs: Song[] }, item) => {
@@ -350,7 +360,7 @@ const normalizeFolder = (
const folder = normalizeFolder(item, server);
acc.folders.push(folder);
} else {
const song = normalizeSong(item, server);
const song = normalizeSong(item, server, pathReplace, pathReplaceWith);
acc.songs.push(song);
}
+8
View File
@@ -471,3 +471,11 @@ export const sortRadioList = (
return results;
};
export const replacePathPrefix = (path: string, replacePrefix?: string, addPrefix?: string) => {
if (replacePrefix && path.startsWith(replacePrefix)) {
return path.slice(replacePrefix.length);
}
return addPrefix ? addPrefix + path : path;
};