Fix video throttling because of range header (#3234)

* Fix video throttling because of range header

* Use a better way to extract the range
This commit is contained in:
absidue 2023-03-01 02:38:13 +01:00 committed by GitHub
parent 4b25201d19
commit f56f6e7a20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,16 @@ import { calculateColorLuminance, colors } from '../../helpers/colors'
import { pathExists } from '../../helpers/filesystem'
import { getPicturesPath, showSaveDialog, showToast } from '../../helpers/utils'
// YouTube now throttles if you use the `Range` header for the DASH formats, instead of the range query parameter
// videojs-http-streaming calls this hook everytime it makes a request,
// so we can use it to convert the Range header into the range query parameter for the streaming URLs
videojs.Vhs.xhr.beforeRequest = (options) => {
if (options.headers?.Range && new URL(options.uri).hostname.endsWith('.googlevideo.com')) {
options.uri += `&range=${options.headers.Range.split('=')[1]}`
delete options.headers.Range
}
}
export default defineComponent({
name: 'FtVideoPlayer',
props: {