bashtube/webroot/yt/watch.shs

67 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
# fetching recommended disabled for speed
#for i in $(curl https://www.youtube.com/watch?v=${get_data[v]} | grep -ohE "watch\?v\=[A-zaz0-9]{11}" | uniq | cut -c 9-19); do
# echo "<div><img src='http://i.ytimg.com/vi/$i/hqdefault.jpg'><br><audio src='$(youtube-dl -g -f 251 $i)' controls></audio></div>";
#done
if [[ ${get_data[v]} ]]; then
video=$(youtube-dl -J "http://youtube.com/watch?v=${get_data[v]}")
if [[ $video == '' ]]; then
video=$(youtube-dl -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
echo "<form action='search.shs'>
<input name='q' type='text'>
<input type='submit' value='Search'>
</form>
<div><br><video src='$url' controls></video>
<h2>$title</h2>
<div>
<div>
Uploaded by <b><a href='channel.shs?id=$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 [[ $(cat storage/faves | grep $(echo -n ${cookies[username]} | sed -E 's/\r//g') | grep ${get_data[v]}) == '' ]]; then
echo "<a href='fav.shs?v=$(echo ${get_data[v]} | sed -s 's/<//g;')' target='_blank'>Add to favourites</a><br>"
else
echo "<a href='unfav.shs?v=$(echo ${get_data[v]} | sed -s 's/<//g;')' target='_blank'>Remove from favourites</a><br>"
fi
if [[ $(cat storage/subscribed | grep $(echo -n ${cookies[username]} | sed -E 's/\r//g') | 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>";
else
source templates/head.sh
echo "pls add ?v param i'm still WiP"
fi