From 0e69898c32cf1670a1459a615c31c31ce9464340 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Sat, 28 Dec 2024 17:50:28 +0100 Subject: [PATCH] Prioritizing known video qualities as fallbacks, fixed Gamma quality format. --- config/default.js | 2 +- src/media.js | 10 +++++++++- src/scrapers/gamma.js | 11 +++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/config/default.js b/config/default.js index b56cd2dc..2906f565 100755 --- a/config/default.js +++ b/config/default.js @@ -438,7 +438,7 @@ module.exports = { thumbnailQuality: 100, lazySize: 90, lazyQuality: 90, - trailerQuality: [540, 720, 480, 360, 960, 1080, 320, 1440, 1600, 1920, 2160, 270, 240, 180], + trailerQuality: [540, 720, 960, 480, 1080, 360, 320, 1440, 1600, 1920, 2160, 270, 240, 180], limit: 25, // max number of photos per release attempts: 2, fetchStreams: true, diff --git a/src/media.js b/src/media.js index af553626..5516197f 100755 --- a/src/media.js +++ b/src/media.js @@ -213,7 +213,7 @@ function baseSourceToBaseMedia(baseSource, role, metadata) { function sortBaseTrailersByQuality(sources, role) { if (role === 'trailers') { - const sortedSources = sources.sort((sourceA, sourceB) => { + const sortedSources = sources.toSorted((sourceA, sourceB) => { if (config.media.trailerQuality.includes(sourceB.quality) && config.media.trailerQuality.indexOf(sourceA.quality) > config.media.trailerQuality.indexOf(sourceB.quality)) { return 1; } @@ -222,6 +222,14 @@ function sortBaseTrailersByQuality(sources, role) { return -1; } + if (config.media.trailerQuality.includes(sourceB.quality) && !config.media.trailerQuality.includes(sourceA.quality)) { + return 1; + } + + if (config.media.trailerQuality.includes(sourceA.quality) && !config.media.trailerQuality.includes(sourceB.quality)) { + return -1; + } + return 0; }); diff --git a/src/scrapers/gamma.js b/src/scrapers/gamma.js index 9e1cce1e..44a8d096 100755 --- a/src/scrapers/gamma.js +++ b/src/scrapers/gamma.js @@ -436,6 +436,10 @@ async function scrapeScene({ query }, url, channel, baseRelease, mobileItem, opt return release; } +const qualityMap = { + '4k': 2160, +}; + async function scrapeReleaseApi(data, site, options, movieScenes) { const release = {}; @@ -478,7 +482,10 @@ async function scrapeReleaseApi(data, site, options, movieScenes) { release.teaser = `https://videothumb.gammacdn.com/500x281/${release.entryId}.mp4`; if (data.trailers) { - release.trailer = Object.entries(data.trailers).map(([quality, source]) => ({ src: source, quality })); + release.trailer = Object.entries(data.trailers).map(([quality, source]) => ({ + src: source, + quality: qualityMap[quality] || parseInt(quality, 10) || quality, + })); } if (data.movie_id && !data.movie_path && options.parameters.sceneMovies !== false) { @@ -494,7 +501,7 @@ async function scrapeReleaseApi(data, site, options, movieScenes) { } release.channel = slugify(data.mainChannel?.id || data.sitename, ''); // remove - - release.qualities = data.download_sizes; + release.qualities = data.download_sizes?.map((quality) => qualityMap[quality] || parseInt(quality, 10) || quality); return release; }