bashtube/webroot/watch.shs
2021-02-18 01:27:27 +01:00

142 lines
6.2 KiB
Bash
Executable file

#!/bin/bash
if [[ "${get_data[v]}" ]]; then
if [[ "${get_data[v]}" == '18l' || "${get_data[v]}" == '5eFdt6Y_34E' ]]; then
uploader='MyMusicGroup'
title='█▬█ █ ▀█▀ Jeden Osiem L - Jak Zapomnieć (Oficjalny Teledysk)'
url='http://sakamoto.pl/tmp/videoplayback_.webm'
meta[title]=$title
source templates/head.sh
else
video=$(haruhi-dl $([[ ${cfg[_cookies]} != "" ]] && echo -n -- "-c ${cfg[_cookies]}") -J "http://youtube.com/watch?v=${get_data[v]}")
if [[ $video == '' ]]; then
video=$(haruhi-dl $([[ ${cfg[_cookies]} != "" ]] && echo -n -- "-c ${cfg[_cookies]}") -J "http://youtube.com/watch?v=${get_data[v]}")
if [[ $video == '' ]]; then
return
fi
fi
#echo "http://youtube.com/watch?v=${get_data[v]}" > /dev/stderr
channel_id=$(echo $video | jq -r '.channel_url' | sed -s 's/http:\/\/www.youtube.com\/channel\///')
uploader=$(echo $video | jq -r '.uploader')
title=$(echo $video | jq -r '.title')
meta[title]=$title
source templates/head.sh
IFS=$'\n'
urls=($(echo $video | jq -r '.formats[] | select(.format_id == "22" or .format_id == "18").url'))
unset IFS
if [[ ${urls[1]} != '' ]]; then
url=${urls[1]}
else
url=${urls[0]}
fi
fi
echo "<form action='search.shs'>
<input name='q' type='text'>
<input type='submit' value='Search'>
</form>
<div><br>"
source "${cfg[namespace]}/webroot/player.shs"
#<video id='player' src='$url' controls></video>
echo "<h2>$title</h2>
<div>
<div>
Uploaded by <b><a href='/channel/$channel_id'>$uploader</a></b> on <b>$(date -d "$(echo $video | jq -r '.upload_date' | sed -E 's/..../&-/;s/....-../&-/')" "+%d %B %Y")</b>
</div>
<div>
<b>$(echo $video | jq -r '.view_count')</b> views<br>
<b>$(echo $video | jq -r '.like_count')</b> likes, <b>$(echo $video | jq -r '.dislike_count')</b> dislikes.<br>"
if [[ ${cookies[sh_session]} ]]; then
if [[ $(grep $(session_get_username "${cookies[sh_session]}") storage/faves | grep "${get_data[v]}") == '' ]]; then
echo "<a href='fav.shs?v=$(sed -s 's/<//g;' <<< "${get_data[v]}")' target='_blank'>Add to favourites</a><br>"
else
echo "<a href='unfav.shs?v=$(sed -s 's/<//g;' <<< "${get_data[v]}")' target='_blank'>Remove from favourites</a><br>"
fi
if [[ $(grep $(session_get_username "${cookies[sh_session]}") storage/subscribed | grep "$channel_id") == '' ]]; then
echo "<a href='subscribe.shs?id=$channel_id' target='_blank'>Subscribe to $uploader!</a><br>"
else
echo "<a href='unsubscribe.shs?id=$channel_id' target='_blank'>Unsubscribe from $uploader</a><br>"
fi
else
echo "<b><a href='/login.shs?r=$(echo ${r[url]} | sed -s 's/?/___/')'>Log in</a> to add this video to your favourites and/or subscribe to this channel!</b><br>"
fi
echo "<br><br>
</div>
</div>
<span><i>Description</i>:<br>$(echo "$video" | jq -r '.description' | sed -E 's/$/<br>/g')</span>
</div>";
vid="$(curl -s "https://www.youtube.com/watch?v=${get_data[v]}" -c cookiejar)"
echo "<h1>Recommended</h1>"
for i in $(echo "$vid" | grep -ohE "watch\?v\=[A-zaz0-9]{11}" | uniq | cut -c 9-19); do
echo "<div><img src='http://i.ytimg.com/vi/$i/mqdefault.jpg'><br></div>";
done
echo "<h1>Comments</h1>"
cont="$(echo "$vid" | grep -Poh 'continuation":".*?"' | sed -E 's/.*":"//g;s/"//g')"
CSRF="$(echo "$vid" | grep -Poh 'XSRF_TOKEN":".*?"' | sed -E 's/XSRF_TOKEN":"//g;s/"//g;s/\\u00/%/g')"
comments="$(curl -s 'https://www.youtube.com/comment_service_ajax?action_get_comments=1&pbj=1&ctoken='"$cont"'&continuation='"$cont" -H 'Accept: */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'X-YouTube-Client-Name: 1' -H 'X-YouTube-Client-Version: 2.20201105.01.01' --data-raw 'session_token='"$CSRF" -b cookiejar)"
IFS=$'\n'
comment_nick=($(jq -r '.response.continuationContents.itemSectionContinuation.contents[].commentThreadRenderer.comment.commentRenderer.authorText.simpleText' <<< "$comments"))
comment_published=($(jq -r '.response.continuationContents.itemSectionContinuation.contents[].commentThreadRenderer.comment.commentRenderer.publishedTimeText.runs[0].text' <<< "$comments"))
comment_likes=($(jq -r '.response.continuationContents.itemSectionContinuation.contents[].commentThreadRenderer.comment.commentRenderer.likeCount' <<< "$comments"))
comment_avatar=($(jq -r '.response.continuationContents.itemSectionContinuation.contents[].commentThreadRenderer.comment.commentRenderer.authorThumbnail.thumbnails[1].url' <<< "$comments"))
unset IFS
x=$(jq '.response.continuationContents.itemSectionContinuation.contents[].commentThreadRenderer.comment.commentRenderer.contentText.runs | map(.text)' <<< "$comments")
IFS=']'
for i in $x; do
comment_text+=($(echo "$i]" | jq -r 'join("")')) # sincerely, fsck [] shell expansion
done
for (( i=0; i<${#comment_nick[@]}; i++ )); do
echo "<div><img src='${comment_avatar[$i]}'>
<b>${comment_nick[$i]}</b> | ${comment_published[$i]} | ${comment_likes[$i]} liked<br>
<pre>${comment_text[$i]}</pre>
</div><hr>"
done
if [[ "${get_data[playlist]}" ]]; then
playlist=$(haruhi-dl $([[ ${cfg[_cookies]} != "" ]] && echo -n -- "-c ${cfg[_cookies]}") -j --flat-playlist "https://www.youtube.com/playlist?list=${get_data[playlist]}")
IFS=$'\n'
video_title=($(jq -r '.title' <<< $playlist))
video_id=($(jq -r '.id' <<< $playlist))
for (( i=0; i<${#video_id[@]}; i++ )); do
if [[ "${video_id[$i]}" == "${get_data[v]}" ]]; then
next="${video_id[$((i+1))]}"
break
fi
done
[[ "$next" == '' ]] && next='dQw4w9WgXcQ'
echo "$next"
echo "<script type='text/javascript'>
window.addEventListener('DOMContentLoaded', (event) => {
var video = document.getElementById('player');
// video.play();
video.addEventListener('ended',function(){
window.location = 'watch?v=$next&playlist=$(html_encode ${get_data[playlist]})';
});
});
</script>"
echo "<h1>Playlist</h1>"
for (( i=0; i<${#video_id[@]}; i++ )); do
echo "<a href='watch?v=${video_id[$i]}&playlist=$(html_encode ${get_data[playlist]})'><img src='http://i.ytimg.com/vi/${video_id[$i]}/mqdefault.jpg'><br>${video_title[$i]}</a><br>"
done
fi
echo "<script type='text/javascript' src='js/player.js'></script>"
else
source templates/head.sh
echo "pls add ?v param i'm still WiP"
fi