From 636f570b31933ccf3e6ae6e65183bbc8a46c265a Mon Sep 17 00:00:00 2001 From: Emma Date: Mon, 11 Dec 2023 16:46:08 -0500 Subject: [PATCH] =?UTF-8?q?Fix=20=F0=9F=8E=A5live=20streams=20on=20android?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - patch `getFormatsFromHLSManifest` through OS level HTTP calls --- src/renderer/helpers/utils.js | 13 +++++- src/renderer/views/Watch/Watch.js | 69 ++++++++++++++----------------- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/renderer/helpers/utils.js b/src/renderer/helpers/utils.js index d70d4e7c1e71..2dcb1dfc41c3 100644 --- a/src/renderer/helpers/utils.js +++ b/src/renderer/helpers/utils.js @@ -5,6 +5,8 @@ import FtToastEvents from '../components/ft-toast/ft-toast-events' import i18n from '../i18n/index' import router from '../router/index' import cordova from 'cordova' +import { cordovaFetch } from './api/local' +import store from '../store' // allowed characters in channel handle: A-Z, a-z, 0-9, -, _, . // https://support.google.com/youtube/answer/11585688#change_handle @@ -155,7 +157,8 @@ export function buildVTTFileLocally(storyboard, videoLengthSeconds) { } export async function getFormatsFromHLSManifest(manifestUrl) { - const response = await fetch(manifestUrl) + const ffetch = process.env.IS_CORDOVA ? cordovaFetch : fetch + const response = await ffetch(manifestUrl) const text = await response.text() const lines = text.split('\n').filter(line => line) @@ -178,10 +181,16 @@ export async function getFormatsFromHLSManifest(manifestUrl) { currentHeight = parseInt(height) currentFPS = parseInt(fps) } else { + const proxyVideos = store.getters.getProxyVideos + const host = store.getters.getCurrentInvidiousInstance + let url = line.trim() + if (proxyVideos || !process.env.IS_ELECTRON) { + url = `${host}${new URL(url).pathname}` + } formats.push({ height: currentHeight, fps: currentFPS, - url: line.trim() + url }) } } diff --git a/src/renderer/views/Watch/Watch.js b/src/renderer/views/Watch/Watch.js index d50d330a88ca..c41a290889f0 100644 --- a/src/renderer/views/Watch/Watch.js +++ b/src/renderer/views/Watch/Watch.js @@ -325,6 +325,36 @@ export default defineComponent({ window.addEventListener('beforeunload', this.handleWatchProgress) }, methods: { + setHlsUrl: async function (hlsUrl) { + try { + const formats = await getFormatsFromHLSManifest(hlsUrl) + + this.videoSourceList = formats + .sort((formatA, formatB) => { + return formatB.height - formatA.height + }) + .map((format) => { + return { + url: format.url, + fps: format.fps, + type: 'application/x-mpegURL', + label: 'Dash', + qualityLabel: `${format.height}p` + } + }) + } catch (e) { + console.error('Failed to extract formats form HLS manifest, falling back to passing it directly to video.js', e) + + this.videoSourceList = [ + { + url: hlsUrl, + type: 'application/x-mpegURL', + label: 'Dash', + qualityLabel: 'Live' + } + ] + } + }, changeTimestamp: function (timestamp) { this.$refs.videoPlayer.player.currentTime(timestamp) }, @@ -493,34 +523,7 @@ export default defineComponent({ } if ((this.isLive || this.isPostLiveDvr) && !this.isUpcoming) { - try { - const formats = await getFormatsFromHLSManifest(result.streaming_data.hls_manifest_url) - - this.videoSourceList = formats - .sort((formatA, formatB) => { - return formatB.height - formatA.height - }) - .map((format) => { - return { - url: format.url, - fps: format.fps, - type: 'application/x-mpegURL', - label: 'Dash', - qualityLabel: `${format.height}p` - } - }) - } catch (e) { - console.error('Failed to extract formats form HLS manifest, falling back to passing it directly to video.js', e) - - this.videoSourceList = [ - { - url: result.streaming_data.hls_manifest_url, - type: 'application/x-mpegURL', - label: 'Dash', - qualityLabel: 'Live' - } - ] - } + await this.setHlsUrl(result.streaming_data.hls_manifest_url) this.showLegacyPlayer = true this.showDashPlayer = false @@ -807,15 +810,7 @@ export default defineComponent({ this.showLegacyPlayer = true this.showDashPlayer = false this.activeFormat = 'legacy' - - this.videoSourceList = [ - { - url: result.hlsUrl, - type: 'application/x-mpegURL', - label: 'Dash', - qualityLabel: 'Live' - } - ] + await this.setHlsUrl(result.hlsUrl) // Grabs the adaptive formats from Invidious. Might be worth making these work. // The type likely needs to be changed in order for these to be played properly.