Compare commits
1
Commits
@@ -68,6 +68,21 @@ async function coverPathIfExists(path: string): Promise<string | null> {
|
|||||||
.catch(() => null)
|
.catch(() => null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function shouldReplaceCover(dbCover: string | null) {
|
||||||
|
return dbCover === null || (await coverPathIfExists(dbCover)) === null
|
||||||
|
}
|
||||||
|
|
||||||
|
function isCodecPath(filePath: string, codec: string) {
|
||||||
|
return filePath.startsWith(`${DATA_DIR}/${codec}/`)
|
||||||
|
}
|
||||||
|
|
||||||
|
function releaseDate(common: music.ICommonTagsResult) {
|
||||||
|
if (common.date) {
|
||||||
|
return common.date
|
||||||
|
}
|
||||||
|
return common.year ? `01-01-${common.year}` : ""
|
||||||
|
}
|
||||||
|
|
||||||
async function syncArtistCover(
|
async function syncArtistCover(
|
||||||
ctx: ActionCtx,
|
ctx: ActionCtx,
|
||||||
codec: string,
|
codec: string,
|
||||||
@@ -77,13 +92,13 @@ async function syncArtistCover(
|
|||||||
) {
|
) {
|
||||||
const onDisk = await coverPathIfExists(diskPath)
|
const onDisk = await coverPathIfExists(diskPath)
|
||||||
if (onDisk !== null) {
|
if (onDisk !== null) {
|
||||||
if (dbCover !== onDisk) {
|
if (await shouldReplaceCover(dbCover)) {
|
||||||
await ctx.runMutation(internal.library.updateArtistCover, {
|
await ctx.runMutation(internal.library.updateArtistCover, {
|
||||||
id,
|
id,
|
||||||
cover: onDisk,
|
cover: onDisk,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else if (dbCover !== null && dbCover.includes(codec)) {
|
} else if (dbCover !== null && isCodecPath(dbCover, codec)) {
|
||||||
await ctx.runMutation(internal.library.updateArtistCover, {
|
await ctx.runMutation(internal.library.updateArtistCover, {
|
||||||
id,
|
id,
|
||||||
cover: null,
|
cover: null,
|
||||||
@@ -100,13 +115,13 @@ async function syncAlbumCover(
|
|||||||
) {
|
) {
|
||||||
const onDisk = await coverPathIfExists(diskPath)
|
const onDisk = await coverPathIfExists(diskPath)
|
||||||
if (onDisk !== null) {
|
if (onDisk !== null) {
|
||||||
if (dbCover !== onDisk) {
|
if (await shouldReplaceCover(dbCover)) {
|
||||||
await ctx.runMutation(internal.library.updateAlbumCover, {
|
await ctx.runMutation(internal.library.updateAlbumCover, {
|
||||||
id,
|
id,
|
||||||
cover: onDisk,
|
cover: onDisk,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else if (dbCover !== null && dbCover.includes(codec)) {
|
} else if (dbCover !== null && isCodecPath(dbCover, codec)) {
|
||||||
await ctx.runMutation(internal.library.updateAlbumCover, {
|
await ctx.runMutation(internal.library.updateAlbumCover, {
|
||||||
id,
|
id,
|
||||||
cover: null,
|
cover: null,
|
||||||
@@ -402,9 +417,8 @@ export const scheduledUpdateLibrary = internalAction({
|
|||||||
name: metadata.common.album || potentialAlbum,
|
name: metadata.common.album || potentialAlbum,
|
||||||
folder: potentialAlbum,
|
folder: potentialAlbum,
|
||||||
cover,
|
cover,
|
||||||
year: metadata.common.year || 2026,
|
year: metadata.common.year || 0,
|
||||||
date:
|
date: releaseDate(metadata.common),
|
||||||
metadata.common.date || `01-01-${metadata.common.year || 2026}`,
|
|
||||||
artist: dbArtist._id,
|
artist: dbArtist._id,
|
||||||
})
|
})
|
||||||
} catch {}
|
} catch {}
|
||||||
@@ -494,11 +508,14 @@ export const scheduledUpdateLibrary = internalAction({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (existingSong) {
|
if (existingSong) {
|
||||||
|
// A tracked path that still exists is a different file with the
|
||||||
|
// same title; replacing it would flip-flop between scans.
|
||||||
|
const trackedPath = existingSong.files[codec]
|
||||||
if (
|
if (
|
||||||
!(codec in existingSong.files) ||
|
trackedPath === undefined ||
|
||||||
existingSong.files[codec] !== path
|
!fsSync.existsSync(trackedPath)
|
||||||
) {
|
) {
|
||||||
const update = { [codec]: path, ...existingSong.files }
|
const update = { ...existingSong.files, [codec]: path }
|
||||||
updateSongs.push({
|
updateSongs.push({
|
||||||
id: existingSong._id,
|
id: existingSong._id,
|
||||||
files: update,
|
files: update,
|
||||||
@@ -550,10 +567,8 @@ export const scheduledUpdateLibrary = internalAction({
|
|||||||
? null
|
? null
|
||||||
: metadata.common.disk.no,
|
: metadata.common.disk.no,
|
||||||
track: metadata.common.track.no || 0,
|
track: metadata.common.track.no || 0,
|
||||||
year: metadata.common.year || 2026,
|
year: metadata.common.year || 0,
|
||||||
date:
|
date: releaseDate(metadata.common),
|
||||||
metadata.common.date ||
|
|
||||||
`01-01-${metadata.common.year || 2026}`,
|
|
||||||
genres: metadata.common.genre || [],
|
genres: metadata.common.genre || [],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user