I JUST WANTED TO WATCH YOUTUBE FOR ONCE

18l-fix
Dominika Liberda 2021-04-20 22:21:18 +02:00
parent 783f9e0970
commit d386a55bad
3 changed files with 95 additions and 30 deletions

View File

@ -1,6 +1,44 @@
window.addEventListener('DOMContentLoaded', (event) => {
const video = document.getElementById('player_video');
const audio = document.getElementById('player_audio');
const formats = JSON.parse(document.getElementById('yt_formats').innerText)
.filter((fmt) => isFormatSupported(fmt) === true)
.sort((a, b) => {
if (a.vcodec === 'none' && b.vcodec !== 'none') {
return -1;
}
if (a.vcodec !== 'none' && b.vcodec === 'none') {
return 1;
}
if (a.vcodec !== 'none' && b.vcodec !== 'none') {
return b.height - a.height;
}
if (a.acodec !== 'none' && b.acodec !== 'none') {
return b.abr - a.abr;
}
});
console.log(formats);
if (localStorage.getItem("videoStream") == null) {
const videoFormat = formats.find((fmt) => fmt.vcodec !== 'none');
const audioFormat = videoFormat.acodec === 'none' ? formats.find((fmt) => fmt.acodec !== 'none') : null;
console.log('aaaaaaaaaaaaaaa')
console.log('selected video format', videoFormat);
console.log('selected audio format', audioFormat);
selectStreams(videoFormat, audioFormat)
} else {
const videoFormat = formats.find((fmt) => fmt.format_id == localStorage.getItem("videoStream"));
const audioFormat = videoFormat.acodec === 'none' ? formats.find((fmt) => fmt.format_id == localStorage.getItem("audioStream")) : null;
console.log('selected video format', videoFormat);
console.log('selected audio format', audioFormat);
selectStreams(videoFormat, audioFormat)
}
if (localStorage.getItem("volume") != null) {
setVolume(localStorage.getItem("volume"));
}
@ -110,6 +148,29 @@ window.addEventListener('DOMContentLoaded', (event) => {
}
}
function toggleSettings() {
let menu = document.querySelector('.settings_menu');
if(menu.style.display == "block") {
menu.style.display = "none";
} else {
menu.style.display = "block";
}
}
function applyStreams() {
let videoStreamInput = document.querySelector('#videoStreamInput');
let audioStreamInput = document.querySelector('#audioStreamInput');
localStorage.setItem("videoStream", parseInt(videoStreamInput.value));
localStorage.setItem("audioStream", parseInt(audioStreamInput.value));
}
function resetStreams() {
localStorage.setItem("videoStream", null);
localStorage.setItem("audioStream", null);
}
function getMimeType(fmt) {
const mainType = fmt.vcodec !== 'none' ? 'video' : 'audio';
let secondary = {
@ -135,34 +196,17 @@ window.addEventListener('DOMContentLoaded', (event) => {
return MediaSource.isTypeSupported(getMimeType(fmt));
}
const formats = JSON.parse(document.getElementById('yt_formats').innerText)
.filter((fmt) => isFormatSupported(fmt) === true)
.sort((a, b) => {
if (a.vcodec === 'none' && b.vcodec !== 'none') {
return -1;
}
if (a.vcodec !== 'none' && b.vcodec === 'none') {
return 1;
}
if (a.vcodec !== 'none' && b.vcodec !== 'none') {
return b.height - a.height;
}
if (a.acodec !== 'none' && b.acodec !== 'none') {
return b.abr - a.abr;
}
});
console.log(formats);
const videoFormat = formats.find((fmt) => fmt.vcodec !== 'none');
const audioFormat = videoFormat.acodec === 'none' ? formats.find((fmt) => fmt.acodec !== 'none') : null;
console.log('selected video format', videoFormat);
console.log('selected audio format', audioFormat);
video.src = videoFormat.url;
if (audioFormat) {
audio.src = audioFormat.url;
function selectStreams(videoFormat, audioFormat) {
video.src = videoFormat.url;
if (audioFormat) {
audio.src = audioFormat.url;
}
}
// document.querySelector('.ytp-button-play').addEventListener('click', () => toggleVideo());
document.querySelector('.ytp-settings-button').addEventListener('click', () => toggleSettings());
document.querySelector('#applyStreams').addEventListener('click', () => applyStreams());
document.querySelector('#resetStreams').addEventListener('click', () => resetStreams());
playButton.addEventListener('click', () => toggleVideo());
video.addEventListener('click', () => toggleVideo());
video.addEventListener('dblclick', () => toggleFullscreen());

File diff suppressed because one or more lines are too long

View File

@ -169,12 +169,12 @@ if [[ "${get_data[v]}" ]]; then
done
fi
if [[ ! ${strings[recommended]} ]]; then
strings[recommended]='An error occurred during fetching Recommended Videos'
if [[ ! "${strings[recommended]}" ]]; then
strings[recommended]='An error occurred during fetching recommended videos'
fi
if [[ ! ${strings[comments_list]} ]]; then
strings[comments_list]='Comments are turned off<br>or an error occured during fetching their'
if [[ ! "${strings[comments_list]}" ]]; then
strings[comments_list]='An error ocurred during fetching comments.'
fi
source "${cfg[namespace]}/templates/header.shs"