From 297f79f6e2f319e65bd00a2b48d656d76a725318 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Sun, 24 Jan 2021 20:43:34 +0100 Subject: [PATCH] Restored sorting trailers by quality. --- config/default.js | 2 +- src/media.js | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/config/default.js b/config/default.js index 38696fc3..aa53bc8b 100644 --- a/config/default.js +++ b/config/default.js @@ -236,7 +236,7 @@ module.exports = { thumbnailQuality: 100, lazySize: 90, lazyQuality: 90, - videoQuality: [480, 360, 320, 540, 720, 1080, 2160, 270, 240, 180], + trailerQuality: [480, 720, 360, 1080, 320, 540, 2160, 270, 240, 180], limit: 25, // max number of photos per release streamConcurrency: 2, // max number of video streams (m3u8 etc.) to fetch and process at once }, diff --git a/src/media.js b/src/media.js index 06b5d9f9..36ff092e 100644 --- a/src/media.js +++ b/src/media.js @@ -152,12 +152,34 @@ function baseSourceToBaseMedia(baseSource, role, metadata) { return null; } +function sortBaseTrailersByQuality(sources, role) { + if (role === 'trailers') { + const sortedSources = sources.sort((sourceA, sourceB) => { + if (config.media.trailerQuality.indexOf(sourceA.quality) > config.media.trailerQuality.indexOf(sourceB.quality)) { + return 1; + } + + if (config.media.trailerQuality.indexOf(sourceA.quality) < config.media.trailerQuality.indexOf(sourceB.quality)) { + return -1; + } + + return 0; + }); + + return sortedSources; + } + + return sources; +} + function fallbackMediaToBaseMedia(rawMedia, role, metadata) { const baseSources = rawMedia .map(source => toBaseSource(source)) .filter(Boolean); - return baseSourceToBaseMedia(baseSources, role, metadata); + const sortedBaseSources = sortBaseTrailersByQuality(baseSources, role); + + return baseSourceToBaseMedia(sortedBaseSources, role, metadata); } function toBaseMedias(rawMedias, role, metadata) {