From 002fb7a35e6cf4703002e55cac4c733148d6a4ed Mon Sep 17 00:00:00 2001 From: Linden Ryuujin Date: Wed, 22 Feb 2023 23:58:35 +0000 Subject: [PATCH 1/2] When setting the cover image prefer images called "cover", otherwise fallback to original behaviour of first in the list. --- server/objects/LibraryItem.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/server/objects/LibraryItem.js b/server/objects/LibraryItem.js index 95674288..b1548099 100644 --- a/server/objects/LibraryItem.js +++ b/server/objects/LibraryItem.js @@ -444,8 +444,15 @@ class LibraryItem { // Set cover image if not set const imageFiles = this.libraryFiles.filter(lf => lf.fileType === 'image') if (imageFiles.length && !this.media.coverPath) { - this.media.coverPath = imageFiles[0].metadata.path - Logger.debug('[LibraryItem] Set media cover path', this.media.coverPath) + //attempt to find a file called cover. otherwise just fall back to the first image found + var coverMatch = imageFiles.find(iFile => /\/cover\.[^.\/]*$/.test(iFile.metadata.path)) + if (coverMatch) { + this.media.coverPath = coverMatch.metadata.path + } + else { + this.media.coverPath = imageFiles[0].metadata.path + } + Logger.info('[LibraryItem] Set media cover path', this.media.coverPath) hasUpdated = true } From f58e2b6dceb8ca164ebe9171e8952f73521a70ad Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 23 Feb 2023 17:55:11 -0600 Subject: [PATCH 2/2] Update cover image set on first scan --- server/objects/LibraryItem.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/server/objects/LibraryItem.js b/server/objects/LibraryItem.js index b1548099..a6d620f8 100644 --- a/server/objects/LibraryItem.js +++ b/server/objects/LibraryItem.js @@ -197,9 +197,15 @@ class LibraryItem { if (key === 'libraryFiles') { this.libraryFiles = payload.libraryFiles.map(lf => lf.clone()) - // Use first image library file as cover - const firstImageFile = this.libraryFiles.find(lf => lf.fileType === 'image') - if (firstImageFile) this.media.coverPath = firstImageFile.metadata.path + // Set cover image + const imageFiles = this.libraryFiles.filter(lf => lf.fileType === 'image') + const coverMatch = imageFiles.find(iFile => /\/cover\.[^.\/]*$/.test(iFile.metadata.path)) + if (coverMatch) { + this.media.coverPath = coverMatch.metadata.path + } else if (imageFiles.length) { + this.media.coverPath = imageFiles[0].metadata.path + } + } else if (this[key] !== undefined && key !== 'media') { this[key] = payload[key] } @@ -444,12 +450,11 @@ class LibraryItem { // Set cover image if not set const imageFiles = this.libraryFiles.filter(lf => lf.fileType === 'image') if (imageFiles.length && !this.media.coverPath) { - //attempt to find a file called cover. otherwise just fall back to the first image found - var coverMatch = imageFiles.find(iFile => /\/cover\.[^.\/]*$/.test(iFile.metadata.path)) + // attempt to find a file called cover. otherwise just fall back to the first image found + const coverMatch = imageFiles.find(iFile => /\/cover\.[^.\/]*$/.test(iFile.metadata.path)) if (coverMatch) { this.media.coverPath = coverMatch.metadata.path - } - else { + } else { this.media.coverPath = imageFiles[0].metadata.path } Logger.info('[LibraryItem] Set media cover path', this.media.coverPath)