Fix adaptive format picked by video JS sometimes not showing up in quality selector (#3350)

* ! Fix adaptive format picked by video JS sometimes not showing up in quality selector

* Apply suggestions from code review

Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>

* ! Workaround invidious issue on AV1 formats

* Update src/renderer/views/Watch/Watch.js

Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>

---------

Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>
This commit is contained in:
PikachuEXE 2023-04-02 02:27:30 +08:00 committed by GitHub
parent 13cde9063e
commit 5db3ab5b5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 15 deletions

View File

@ -256,9 +256,14 @@ export function filterInvidiousFormats(formats, allowAv1 = false) {
}
})
if (allowAv1 && av1Formats.length > 0) {
return [...audioFormats, ...av1Formats]
} else {
// Disabled AV1 as a workaround to https://github.com/FreeTubeApp/FreeTube/issues/3382
// Which is caused by Invidious API limitation on AV1 formats (see related issues)
// Commented code to be restored after Invidious issue fixed
//
// if (allowAv1 && av1Formats.length > 0) {
// return [...audioFormats, ...av1Formats]
// } else {
// return [...audioFormats, ...h264Formats]
// }
return [...audioFormats, ...h264Formats]
}
}

View File

@ -586,10 +586,15 @@ export default defineComponent({
// we need to alter the result object so the toDash function uses the filtered formats too
result.streaming_data.adaptive_formats = filterLocalFormats(result.streaming_data.adaptive_formats, this.allowDashAv1Formats)
this.adaptiveFormats = result.streaming_data.adaptive_formats.map(mapLocalFormat)
// When `this.proxyVideos` is true
// It's possible that the Invidious instance used, only supports a subset of the formats from Local API
// i.e. the value passed into `adaptiveFormats`
// e.g. Supports 720p60, but not 720p - https://[DOMAIN_NAME]/api/manifest/dash/id/v3wm83zoSSY?local=true
if (this.proxyVideos) {
this.adaptiveFormats = await this.getAdaptiveFormatsInvidious()
this.dashSrc = await this.createInvidiousDashManifest()
} else {
this.adaptiveFormats = result.streaming_data.adaptive_formats.map(mapLocalFormat)
this.dashSrc = await this.createLocalDashManifest(result)
}
@ -636,7 +641,7 @@ export default defineComponent({
this.videoStoryboardSrc = `${this.currentInvidiousInstance}/api/v1/storyboards/${this.videoId}?height=90`
invidiousGetVideoInformation(this.videoId)
.then(result => {
.then(async result => {
if (result.error) {
throw new Error(result.error)
}
@ -668,14 +673,7 @@ export default defineComponent({
this.videoPublished = result.published * 1000
this.videoDescriptionHtml = result.descriptionHtml
this.recommendedVideos = result.recommendedVideos
this.adaptiveFormats = filterInvidiousFormats(result.adaptiveFormats, this.allowDashAv1Formats)
.map((format) => {
format.bitrate = parseInt(format.bitrate)
if (typeof format.resolution !== 'undefined') {
format.height = parseInt(format.resolution.replace('p', ''))
}
return format
})
this.adaptiveFormats = await this.getAdaptiveFormatsInvidious(result)
this.isLive = result.liveNow
this.isFamilyFriendly = result.isFamilyFriendly
this.captionHybridList = result.captions.map(caption => {
@ -1266,6 +1264,24 @@ export default defineComponent({
]
},
getAdaptiveFormatsInvidious: async function(existingInfoResult = null) {
let result
if (existingInfoResult) {
result = existingInfoResult
} else {
result = await invidiousGetVideoInformation(this.videoId)
}
return filterInvidiousFormats(result.adaptiveFormats, this.allowDashAv1Formats)
.map((format) => {
format.bitrate = parseInt(format.bitrate)
if (typeof format.resolution === 'string') {
format.height = parseInt(format.resolution.replace('p', ''))
}
return format
})
},
createLocalStoryboardUrls: async function (storyboardInfo) {
const results = buildVTTFileLocally(storyboardInfo, this.videoLengthSeconds)
const userData = await getUserDataPath()