+ basic subtitle handling

merge-requests/6/head
Dominika Liberda 2021-08-02 21:36:32 +00:00
parent 6418c91bd7
commit 906701a152
4 changed files with 48 additions and 8 deletions

View File

@ -6,7 +6,7 @@ cfg[unbuffered]=false
if [[ "${r[url]}" == "/proxy"* ]]; then
cfg[proxy]=true
cfg[proxy_url]='http(s|)://[a-z0-9-]*\.googlevideo\.com/.*'
cfg[proxy_url]='http(s|)://([a-z0-9-]*\.googlevideo\.com|www\.youtube\.com)/.*'
cfg[proxy_param]='url'
fi

View File

@ -2,6 +2,7 @@ window.addEventListener('DOMContentLoaded', (event) => {
const autoplayInput = document.querySelector('#autoplayInput');
const videoStreamInput = document.querySelector('#videoStreamInput');
const audioStreamInput = document.querySelector('#audioStreamInput');
const subsInput = document.querySelector('#subsInput');
const speedInput = document.querySelector("#speedInput");
const loopInput = document.querySelector("#loopInput");
const controlbar = document.querySelector(".html5-video-controls")
@ -24,6 +25,7 @@ window.addEventListener('DOMContentLoaded', (event) => {
loopInput.checked = false;
subs = JSON.parse(document.getElementById('yt_subs').innerText)
formats = JSON.parse(document.getElementById('yt_formats').innerText)
.filter((fmt) => isFormatSupported(fmt) === true)
.sort((a, b) => {
@ -235,6 +237,11 @@ window.addEventListener('DOMContentLoaded', (event) => {
}
}
function handleSubsChange(e) {
Array.from(video.textTracks).forEach((e) => {e.mode='disabled'});
Array.from(video.textTracks)[parseInt(subsInput.value)].mode='showing';
}
function handleKeyboard(e) {
console.log(e)
if (e.target.name != "search_query" && !e.ctrlKey && !e.altKey) {
@ -395,6 +402,7 @@ window.addEventListener('DOMContentLoaded', (event) => {
controlbar.addEventListener('mousemove', (e) => handleMouse("controls", e));
speedInput.addEventListener('change', () => changeSpeed());
speedInput.selectedIndex=2;
subsInput.addEventListener('change', () => handleSubsChange());
seekAbsolute(startTime);
@ -447,6 +455,27 @@ window.addEventListener('DOMContentLoaded', (event) => {
console.log(`A TAKŻE SPECJALNEGO GOŚCIA ${e.format_id}, czyli ${e.height}p WRAZ Z RODZINĄ`)
}
})
uwu = document.createElement('option');
uwu.innerText='';
uwu.value=-1;
subsInput.appendChild(uwu);
let subsIndex = 0;
subs.forEach((e) => {
let track = document.createElement('track');
let uwu = document.createElement('option');
track.src="https://"+window.location.hostname+"/proxy?url="+encodeURIComponent(e.url);
track.srclang=e.lang;
track.label=e.lang;
track.kind="subtitles";
console.log(track.src)
video.appendChild(track);
uwu.innerText=e.lang;
uwu.value=subsIndex;
subsInput.appendChild(uwu);
subsIndex=subsIndex+1;
})
videoStreamInput.selectedIndex = selectedVideoIndex;
audioStreamInput.selectedIndex = selectedAudioIndex;

File diff suppressed because one or more lines are too long

View File

@ -40,14 +40,14 @@ if [[ "${get_data[v]}" ]]; then
fi
else
cd temp
video=$(haruhi-dl --ie-key Youtube --write-pages --cookies "${cfg[_cookies]}" -J "http://youtube.com/watch?v=${get_data[v]}")
video=$(haruhi-dl --all-subs --ie-key Youtube --write-pages --cookies "${cfg[_cookies]}" -J "http://youtube.com/watch?v=${get_data[v]}")
if [[ $video == '' ]]; then # okay who did this
random_hash=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 24 | head -n 1)
video=$(haruhi-dl --ie-key Youtube --write-pages --cookies ${cfg[_cookies]} -J "http://youtube.com/watch?v=${get_data[v]}" 2> output$random_hash.log)
video=$(haruhi-dl --all-subs --ie-key Youtube --write-pages --cookies ${cfg[_cookies]} -J "http://youtube.com/watch?v=${get_data[v]}" 2> output$random_hash.log)
if [[ $video == '' ]]; then # seriously WHO DID THIS
if [[ "${cfg[regionlock_proxy]}" == true ]]; then
# retrying w/ proxy!
video=$(haruhi-dl --ie-key Youtube --write-pages --cookies ${cfg[_cookies]} --proxy "${cfg[regionlock_proxy_url]}" -J "http://youtube.com/watch?v=${get_data[v]}" 2> output$random_hash.log)
video=$(haruhi-dl --all-subs --ie-key Youtube --write-pages --cookies ${cfg[_cookies]} --proxy "${cfg[regionlock_proxy_url]}" -J "http://youtube.com/watch?v=${get_data[v]}" 2> output$random_hash.log)
fi
output=$(cat output$random_hash.log)
rm output$random_hash.log
@ -91,6 +91,15 @@ if [[ "${get_data[v]}" ]]; then
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")
sub_array=()
for i in $(jq -r '.subtitles | keys[]' <<< "$video"); do
sub_array+=("$(jq '.subtitles.'"$i"'[] | select(.ext == "vtt").url | {"url": ., "lang":"'"$i"'"}' <<< "$video")")
done
subs=$(jq -s '.' <<< "${sub_array[@]}")
fi
if [[ "${r[host]}" == "${cfg[flash_host]}" ]]; then