Skip to content

Commit

Permalink
Fix 馃帴live streams on android
Browse files Browse the repository at this point in the history
- patch `getFormatsFromHLSManifest` through OS level HTTP calls
  • Loading branch information
MarmadileManteater committed Dec 11, 2023
1 parent ea18d5b commit 636f570
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 39 deletions.
13 changes: 11 additions & 2 deletions src/renderer/helpers/utils.js
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
})
}
}
Expand Down
69 changes: 32 additions & 37 deletions src/renderer/views/Watch/Watch.js
Expand Up @@ -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)
},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 636f570

Please sign in to comment.