From d386a55badbc3c2cfb7c48271d15b61d70d11704 Mon Sep 17 00:00:00 2001 From: Dominika Liberda Date: Tue, 20 Apr 2021 22:21:18 +0200 Subject: [PATCH] I JUST WANTED TO WATCH YOUTUBE FOR ONCE --- webroot/js/player.js | 94 ++++++++++++++++++++++++++++++++------------ webroot/player.shs | 23 ++++++++++- webroot/watch.shs | 8 ++-- 3 files changed, 95 insertions(+), 30 deletions(-) diff --git a/webroot/js/player.js b/webroot/js/player.js index a7452f5..9b1fb5f 100644 --- a/webroot/js/player.js +++ b/webroot/js/player.js @@ -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()); diff --git a/webroot/player.shs b/webroot/player.shs index ade4f5f..3b18a8e 100755 --- a/webroot/player.shs +++ b/webroot/player.shs @@ -8,7 +8,28 @@ echo ' width: 854px; height: 480px; } + .settings_menu { + height: 175px; + width: 250px; + display: none; + background-color: #1b1b1b; + z-index: 999; + position: relative; + margin-left: auto; + } -
[x]
Video ID:
Dimensions:
Resolution:
Volume:
Stream Type:
CPN:
Mime Type:
DASH:
Protected:
Bandwidth:
Decoded FramesDropped FramesParsed FramesPresented Frames
Video Bytes DecodedAudio Bytes DecodedPainted FramesPaint Delay
0:00
+
+
[x]
Video ID:
Dimensions:
Resolution:
Volume:
Stream Type:
CPN:
Mime Type:
DASH:
Protected:
Bandwidth:
Decoded FramesDropped FramesParsed FramesPresented Frames
Video Bytes DecodedAudio Bytes DecodedPainted FramesPaint Delay
+ +
+ +
+ + + +
+ +
0:00
+
' diff --git a/webroot/watch.shs b/webroot/watch.shs index 7724b1b..06f7cf4 100755 --- a/webroot/watch.shs +++ b/webroot/watch.shs @@ -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
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"