#1332: Improve cover image score algorithm:
- If filename score is equal, pick highest resolution - Search for keyword occurrence in file name
This commit is contained in:
@@ -74,15 +74,23 @@ function filterOnExtension (torrent, extensions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function scoreCoverFile (file) {
|
function scoreCoverFile (file) {
|
||||||
const name = path.basename(file.name, path.extname(file.name)).toLowerCase()
|
const fileName = path.basename(file.name, path.extname(file.name)).toLowerCase()
|
||||||
switch (name) {
|
const relevanceScore = {
|
||||||
case 'cover': return 100
|
cover: 100,
|
||||||
case 'folder': return 95
|
folder: 95,
|
||||||
case 'front': return 85
|
front: 90,
|
||||||
case 'front-cover': return 90
|
back: 20
|
||||||
case 'back': return 40
|
|
||||||
default: return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (let keyword in relevanceScore) {
|
||||||
|
if (fileName === keyword) {
|
||||||
|
return relevanceScore[keyword]
|
||||||
|
}
|
||||||
|
if (fileName.indexOf(keyword) !== -1) {
|
||||||
|
return 0.8 * relevanceScore[keyword]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function torrentPosterFromAudio (torrent, cb) {
|
function torrentPosterFromAudio (torrent, cb) {
|
||||||
@@ -94,7 +102,9 @@ function torrentPosterFromAudio (torrent, cb) {
|
|||||||
score: scoreCoverFile(file)
|
score: scoreCoverFile(file)
|
||||||
}
|
}
|
||||||
}).sort((a, b) => {
|
}).sort((a, b) => {
|
||||||
return b.score - a.score
|
const delta = b.score - a.score
|
||||||
|
// If score is equal, pick the largest file, aiming for highest resolution
|
||||||
|
return delta === 0 ? b.file.length - a.file.length : delta
|
||||||
})
|
})
|
||||||
|
|
||||||
if (bestCover.length < 1) return cb(new Error('Generated poster contains no data'))
|
if (bestCover.length < 1) return cb(new Error('Generated poster contains no data'))
|
||||||
|
|||||||
Reference in New Issue
Block a user