* fixes undefined videoFormat with forced stream id
This commit is contained in:
parent
d386a55bad
commit
7ca97901ee
|
@ -2,7 +2,7 @@ window.addEventListener('DOMContentLoaded', (event) => {
|
||||||
const video = document.getElementById('player_video');
|
const video = document.getElementById('player_video');
|
||||||
const audio = document.getElementById('player_audio');
|
const audio = document.getElementById('player_audio');
|
||||||
|
|
||||||
const formats = JSON.parse(document.getElementById('yt_formats').innerText)
|
formats = JSON.parse(document.getElementById('yt_formats').innerText)
|
||||||
.filter((fmt) => isFormatSupported(fmt) === true)
|
.filter((fmt) => isFormatSupported(fmt) === true)
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
if (a.vcodec === 'none' && b.vcodec !== 'none') {
|
if (a.vcodec === 'none' && b.vcodec !== 'none') {
|
||||||
|
@ -23,17 +23,21 @@ window.addEventListener('DOMContentLoaded', (event) => {
|
||||||
if (localStorage.getItem("videoStream") == null) {
|
if (localStorage.getItem("videoStream") == null) {
|
||||||
const videoFormat = formats.find((fmt) => fmt.vcodec !== 'none');
|
const videoFormat = formats.find((fmt) => fmt.vcodec !== 'none');
|
||||||
const audioFormat = videoFormat.acodec === 'none' ? formats.find((fmt) => fmt.acodec !== 'none') : null;
|
const audioFormat = videoFormat.acodec === 'none' ? formats.find((fmt) => fmt.acodec !== 'none') : null;
|
||||||
console.log('aaaaaaaaaaaaaaa')
|
|
||||||
console.log('selected video format', videoFormat);
|
console.log('selected video format', videoFormat);
|
||||||
console.log('selected audio format', audioFormat);
|
console.log('selected audio format', audioFormat);
|
||||||
|
|
||||||
selectStreams(videoFormat, audioFormat)
|
selectStreams(videoFormat, audioFormat)
|
||||||
} else {
|
} else {
|
||||||
const videoFormat = formats.find((fmt) => fmt.format_id == localStorage.getItem("videoStream"));
|
let videoFormat = formats.find((fmt) => fmt.format_id == localStorage.getItem("videoStream"));
|
||||||
|
if (videoFormat == null) {
|
||||||
|
videoFormat = formats.find((fmt) => fmt.vcodec !== 'none');
|
||||||
|
}
|
||||||
const audioFormat = videoFormat.acodec === 'none' ? formats.find((fmt) => fmt.format_id == localStorage.getItem("audioStream")) : null;
|
const audioFormat = videoFormat.acodec === 'none' ? formats.find((fmt) => fmt.format_id == localStorage.getItem("audioStream")) : null;
|
||||||
|
if (audioFormat == null) {
|
||||||
|
audioFormat = videoFormat.acodec === 'none' ? formats.find((fmt) => fmt.acodec !== 'none') : null;
|
||||||
|
}
|
||||||
console.log('selected video format', videoFormat);
|
console.log('selected video format', videoFormat);
|
||||||
console.log('selected audio format', audioFormat);
|
console.log('selected audio format', audioFormat);
|
||||||
|
|
||||||
|
|
||||||
selectStreams(videoFormat, audioFormat)
|
selectStreams(videoFormat, audioFormat)
|
||||||
}
|
}
|
||||||
|
@ -160,15 +164,17 @@ window.addEventListener('DOMContentLoaded', (event) => {
|
||||||
function applyStreams() {
|
function applyStreams() {
|
||||||
let videoStreamInput = document.querySelector('#videoStreamInput');
|
let videoStreamInput = document.querySelector('#videoStreamInput');
|
||||||
let audioStreamInput = document.querySelector('#audioStreamInput');
|
let audioStreamInput = document.querySelector('#audioStreamInput');
|
||||||
localStorage.setItem("videoStream", parseInt(videoStreamInput.value));
|
localStorage.setItem("videoStream", videoStreamInput.value);
|
||||||
localStorage.setItem("audioStream", parseInt(audioStreamInput.value));
|
localStorage.setItem("audioStream", audioStreamInput.value);
|
||||||
|
|
||||||
|
const videoFormat = formats.find((fmt) => fmt.format_id == videoStreamInput.value);
|
||||||
|
const audioFormat = videoFormat.acodec === 'none' ? formats.find((fmt) => fmt.format_id == audioStreamInput.value) : null;
|
||||||
|
selectStreams(videoFormat, audioFormat)
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetStreams() {
|
function resetStreams() {
|
||||||
localStorage.setItem("videoStream", null);
|
localStorage.removeItem("videoStream");
|
||||||
localStorage.setItem("audioStream", null);
|
localStorage.removeItem("audioStream");
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMimeType(fmt) {
|
function getMimeType(fmt) {
|
||||||
|
|
Loading…
Reference in a new issue