From ee3654c9507512e6b40bb93eccf77bc521f76a8e Mon Sep 17 00:00:00 2001 From: Dominika Liberda Date: Wed, 27 Oct 2021 22:05:22 +0000 Subject: [PATCH] player sorting fixes --- webroot/js/player.js | 35 ++++++++++++++++++++++++++++++----- webroot/watch.shs | 2 +- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/webroot/js/player.js b/webroot/js/player.js index 0f7db5e..37c3d73 100644 --- a/webroot/js/player.js +++ b/webroot/js/player.js @@ -29,6 +29,12 @@ window.addEventListener('DOMContentLoaded', (event) => { formats = JSON.parse(document.getElementById('yt_formats').innerText) .filter((fmt) => isFormatSupported(fmt) === true) .sort((a, b) => { + if (a.format_note.includes("maybe throttled") && ! b.format_note.includes("maybe throttled")) { + return 1; + } + if (! a.format_note.includes("maybe throttled") && b.format_note.includes("maybe throttled")) { + return -1; + } if (a.vcodec === 'none' && b.vcodec !== 'none') { return -1; } @@ -36,10 +42,29 @@ window.addEventListener('DOMContentLoaded', (event) => { return 1; } if (a.vcodec !== 'none' && b.vcodec !== 'none') { - return b.height - a.height; + if (a.height !== b.height) { + return b.height - a.height; + } + if (a.fps !== b.fps) { + return b.fps - a.fps; + } + if (a.acodec === 'none' && b.acodec !== 'none') { + return -1; + } + if (a.acodec !== 'none' && b.acodec === 'none') { + return 1; + } } if (a.acodec !== 'none' && b.acodec !== 'none') { - return b.abr - a.abr; + if (a.acodec === 'opus' && b.acodec !== 'opus') { + return -1; + } + if (a.acodec !== 'opus' && b.acodec === 'opus') { + return 1; + } + if (a.abr !== b.abr) { + return b.abr - a.abr; + } } }); console.log(formats); @@ -426,13 +451,13 @@ window.addEventListener('DOMContentLoaded', (event) => { uwu.innerText = '' audioStreamInput.append(uwu); - let selectedAudioIndex = 0; + let selectedAudioIndex = 1; let selectedVideoIndex = 0; formats.forEach((e) => { let uwu = document.createElement("option"); uwu.value = e.format_id; if (e.acodec == "none") { - uwu.innerText = `${e.ext} ${e.height}p (${e.format_id})`; + uwu.innerText = `${e.format_note} ${e.vcodec.substring(0, 4)} (${e.format_id})`; if (uwu.value == localStorage.getItem("videoStream")) { selectedVideoIndex = videoStreamInput.length; console.log(selectedVideoIndex) @@ -448,7 +473,7 @@ window.addEventListener('DOMContentLoaded', (event) => { audioStreamInput.append(uwu); console.log(`- ${e.format_id}, czyli ${e.acodec} ${e.abr}kbps`) } else { - uwu.innerText = `${e.ext} ${e.height}p (${e.format_id})`; + uwu.innerText = `${e.format_note} ${e.vcodec.substring(0, 4)}+${e.acodec.substring(0, 4)} (${e.format_id})`; if (uwu.value == localStorage.getItem("videoStream")) { selectedVideoIndex = videoStreamInput.length; console.log(selectedVideoIndex) diff --git a/webroot/watch.shs b/webroot/watch.shs index 2cb0e29..d4cc727 100755 --- a/webroot/watch.shs +++ b/webroot/watch.shs @@ -93,7 +93,7 @@ if [[ "${get_data[v]}" ]]; then }' <<< "$video" | sed 's//\>/g;')"'' source templates/head.sh fi - formats=$(jq -c '[.formats[] | select(.protocol == "https") | {"format_id":.format_id,"url":.url,"ext":.ext,"width":.width,"height":.height,"acodec":.acodec,"vcodec":.vcodec,"abr":.abr,"fps":.fps}]' <<< "$video") + formats=$(jq -c '[.formats[] | select(.protocol == "https") | {"format_id":.format_id,"url":.url,"ext":.ext,"width":.width,"height":.height,"format_note":.format_note,"acodec":.acodec,"vcodec":.vcodec,"abr":.abr,"fps":.fps}]' <<< "$video") sub_array=()