From 8f8df5d8e62ec576a45f10a7e23cbb92ad5ad511 Mon Sep 17 00:00:00 2001 From: Preston Date: Sun, 16 May 2021 21:40:34 -0400 Subject: [PATCH] Fix quality changing logic for Invidious API --- .../ft-video-player/ft-video-player.js | 79 ++++++++++++++----- src/renderer/views/Watch/Watch.js | 1 + 2 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/renderer/components/ft-video-player/ft-video-player.js b/src/renderer/components/ft-video-player/ft-video-player.js index 5da1bbba..a4f6a467 100644 --- a/src/renderer/components/ft-video-player/ft-video-player.js +++ b/src/renderer/components/ft-video-player/ft-video-player.js @@ -537,24 +537,46 @@ export default Vue.extend({ this.setDashQualityLevel('auto') } - let formatsToTest = this.activeAdaptiveFormats.filter((format) => { - return format.height === this.defaultQuality - }) + let formatsToTest - if (formatsToTest.length === 0) { + if (typeof this.activeAdaptiveFormats !== 'undefined' && this.activeAdaptiveFormats.length > 0) { formatsToTest = this.activeAdaptiveFormats.filter((format) => { - return format.height < this.defaultQuality + return format.height === this.defaultQuality + }) + + if (formatsToTest.length === 0) { + formatsToTest = this.activeAdaptiveFormats.filter((format) => { + return format.height < this.defaultQuality + }) + } + + formatsToTest = formatsToTest.sort((a, b) => { + if (a.height === b.height) { + return b.bitrate - a.bitrate + } else { + return b.height - a.height + } + }) + } else { + formatsToTest = this.player.qualityLevels().levels_.filter((format) => { + return format.height === this.defaultQuality + }) + + if (formatsToTest.length === 0) { + formatsToTest = this.player.qualityLevels().levels_.filter((format) => { + return format.height < this.defaultQuality + }) + } + + formatsToTest = formatsToTest.sort((a, b) => { + if (a.height === b.height) { + return b.bitrate - a.bitrate + } else { + return b.height - a.height + } }) } - formatsToTest = formatsToTest.sort((a, b) => { - if (a.height === b.height) { - return b.bitrate - a.bitrate - } else { - return b.height - a.height - } - }) - // TODO: Test formats to determine if HDR / 60 FPS and skip them based on // User settings this.setDashQualityLevel(formatsToTest[0].bitrate) @@ -605,6 +627,8 @@ export default Vue.extend({ }) } + let qualityLabel = adaptiveFormat ? adaptiveFormat.qualityLabel : '' + this.player.qualityLevels().levels_.sort((a, b) => { if (a.height === b.height) { return a.bitrate - b.bitrate @@ -615,13 +639,16 @@ export default Vue.extend({ if (bitrate === 'auto' || bitrate === ql.bitrate) { ql.enabled = true ql.enabled_(true) + if (bitrate !== 'auto' && qualityLabel === '') { + qualityLabel = ql.height + 'p' + } } else { ql.enabled = false ql.enabled_(false) } }) - const selectedQuality = bitrate === 'auto' ? 'auto' : adaptiveFormat.qualityLabel + const selectedQuality = bitrate === 'auto' ? 'auto' : qualityLabel const qualityElement = document.getElementById('vjs-current-quality') qualityElement.innerText = selectedQuality @@ -935,15 +962,25 @@ export default Vue.extend({ return b.height - a.height } }).forEach((quality, index, array) => { - const adaptiveFormat = v.adaptiveFormats.find((format) => { - return format.bitrate === quality.bitrate - }) + let fps + let qualityLabel + let bitrate - v.activeAdaptiveFormats.push(adaptiveFormat) + if (typeof v.adaptiveFormats !== 'undefined' && v.adaptiveFormats > 0) { + const adaptiveFormat = v.adaptiveFormats.find((format) => { + return format.bitrate === quality.bitrate + }) - const fps = adaptiveFormat.fps - const qualityLabel = adaptiveFormat.qualityLabel - const bitrate = quality.bitrate + v.activeAdaptiveFormats.push(adaptiveFormat) + + fps = adaptiveFormat.fps + qualityLabel = adaptiveFormat.qualityLabel ? adaptiveFormat.qualityLabel : quality.height + 'p' + bitrate = quality.bitrate + } else { + fps = 30 + qualityLabel = quality.height + 'p' + bitrate = quality.bitrate + } qualityHtml = qualityHtml + `
  • ${qualityLabel} diff --git a/src/renderer/views/Watch/Watch.js b/src/renderer/views/Watch/Watch.js index 8db9a4dd..0c28c649 100644 --- a/src/renderer/views/Watch/Watch.js +++ b/src/renderer/views/Watch/Watch.js @@ -547,6 +547,7 @@ export default Vue.extend({ this.videoPublished = result.published * 1000 this.videoDescriptionHtml = result.descriptionHtml this.recommendedVideos = result.recommendedVideos + this.adaptiveFormats = result.adaptiveFormats this.isLive = result.liveNow this.captionHybridList = result.captions.map(caption => { caption.url = this.invidiousInstance + caption.url