Rewrite for template engine

18l-fix
sech1p 2021-02-28 17:43:40 +01:00
parent a42af1ceef
commit 89feca7ae8
22 changed files with 259 additions and 183 deletions

View File

@ -1,3 +1,4 @@
cfg[title]='BashTube'
cfg[_cookies]='cookiejar'
cfg[flash_host]='flash.xn--domi-o5a.pl'
cfg[template]='default'

View File

@ -0,0 +1,2 @@
<a href='./'>&lt;--- back to main</a><br><h1>Your favourites</h1>
{{.fav}}

View File

@ -0,0 +1 @@
{{.feed}}

View File

@ -0,0 +1,8 @@
<form action='/search.shs'>
<input name='q' type='text'>
<input type='submit' value='Search'>
</form>
<h1>All user's favourites:</h1>
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));'>
{{.favourites}}
</div>

View File

@ -0,0 +1,9 @@
<h1>Log in...</h1>
<form method='post'>
<label for='login'>Login:</label>
<input type='text' name='login'><br>
<label for='password'>Password:</label>
<input type='password' name='password'><br>
<input type='submit' value='Login'>
</form>
{{.reason}}

View File

@ -0,0 +1 @@
{{.playlist}}

View File

@ -0,0 +1,10 @@
<h1>Register</h1>
<form method='post'>
<label for='login'>Login:</label>
<input type='text' name='login'><br>
<label for='password'>Password:</label>
<input type='password' name='password'><br>
<input type='submit' value='Register'>
</form>
(please make sure that you're connecting over SSL)<br>
{{.reason}}

View File

@ -0,0 +1,4 @@
{{.search}}
<input type='submit' value='Search'>
</form><br>
{{.results}}

View File

@ -0,0 +1,2 @@
<a href='./'>&lt;--- back to main</a><br><h1>Channels you subscribe to</h1>
{{.subscribe}}

View File

@ -0,0 +1,27 @@
<form action='search.shs'>
<input name='q' type='text'>
<input type='submit' value='Search'>
</form>
<div><br>
{{.player}}
<h2>{{.title}}</h2>
<div>
<div>
Uploaded by <b><a href='/channel/{{.channel_id}}'>{{.uploader}}</a></b> on <b>{{.upload_date}}</b>
</div>
<div>
<b>{{.view_count}}</b> views<br>
<b>{{.like_count}}</b> likes, <b>{{.dislike_count}}</b> dislikes.<br>
{{.fav}}
<br><br>
</div>
</div>
<span><i>Description</i>:<br>{{.description}}</span>
</div>
<h1>Recommended</h1>
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));'>
{{.recommended}}
</div><h1>Comments</h1>
{{.comments_list}}
{{.playlist}}
<script type='text/javascript' src='js/player.js'></script>

View File

@ -0,0 +1,27 @@
<form action='search.shs'>
<input name='q' type='text'>
<input type='submit' value='Search'>
</form>
<div><br>
{{.player}}
<h2>{{.title}}</h2>
<div>
<div>
Uploaded by <b><a href='/channel/{{.channel_id}}'>{{.uploader}}</a></b> on <b>{{.upload_date}}</b>
</div>
<div>
<b>{{.view_count}}</b> views<br>
<b>{{.like_count}}</b> likes, <b>{{.dislike_count}}</b> dislikes.<br>
{{.fav}}
<br><br>
</div>
</div>
<span><i>Description</i>:<br>{{.description}}</span>
</div>
<h1>Recommended</h1>
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));'>
{{.recommended}}
</div><h1>Comments</h1>
{{.comments_list}}
{{.playlist}}
<script type='text/javascript' src='js/player.js'></script>

View File

@ -1,5 +1,7 @@
#!/bin/bash
declare -A strings
if session_verify "${cookies[sh_session]}" && [[ "${get_data[v]}" != '' ]]; then
title=$(haruhi-dl --cookies ${cfg[_cookies]} -e "https://youtube.com/watch?v=${get_data[v]}")
if [[ $(grep -F "$title" storage/faves | grep "$(echo ${cookies[username]} | sed -E "s/\r//")") == '' ]]; then
@ -7,9 +9,9 @@ if session_verify "${cookies[sh_session]}" && [[ "${get_data[v]}" != '' ]]; then
fi
fi
source templates/head.sh
echo "<a href='./'>&lt;--- back to main</a><br><h1>Your favourites</h1>"
if [[ ${cfg[template]} == 'default' ]]; then
source templates/head.sh
fi
IFS=$'\n'
for i in $(tac storage/faves | grep -P "^$(session_get_username ${cookies[sh_session]}):"); do
@ -18,5 +20,7 @@ for i in $(tac storage/faves | grep -P "^$(session_get_username ${cookies[sh_ses
if [[ ${array[1]} == '' ]]; then
break
fi
echo "<div><a href='watch?v=${array[1]}'><img src='https://i.ytimg.com/vi/${array[1]}/mqdefault.jpg'><br><b>${array[@]:2:999}</b></a><br></div>";
strings[fav]+="<div><a href='watch?v=${array[1]}'><img src='https://i.ytimg.com/vi/${array[1]}/mqdefault.jpg'><br><b>${array[@]:2:999}</b></a><br></div>";
done
render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/fav.t"

View File

@ -1,6 +1,10 @@
#!/bin/bash
source templates/head.sh
if [[ ${cfg[template]} == 'default' ]]; then
source templates/head.sh
fi
declare -A strings
if session_verify "${cookies[sh_session]}"; then
while read i; do
@ -18,8 +22,10 @@ if session_verify "${cookies[sh_session]}"; then
queue=$(for (( i=0; i<${#video_id[@]}; i++ )); do echo "$i ${video_date[i]}"; done | sort -k2r | awk '{print $1}')
while read i; do
echo "<a href='watch?v=${video_id[$i]}'><img src='http://i.ytimg.com/vi/${video_id[$i]}/mqdefault.jpg'><br>${video_title[$i]}</a>$(date -d "@${video_date[$i]}" "+%H:%M, %d %h %Y")<br>"
strings[feed]+="<a href='watch?v=${video_id[$i]}'><img src='http://i.ytimg.com/vi/${video_id[$i]}/mqdefault.jpg'><br>${video_title[$i]}</a>$(date -d "@${video_date[$i]}" "+%H:%M, %d %h %Y")<br>"
done <<< "$queue"
else
echo "gtfo"
strings[feed]="gtfo"
fi
render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/feed.t"

View File

@ -2,14 +2,7 @@
source templates/head.sh
source ${cfg[namespace]}/templates/header.shs
echo "<form action='${r[url]}/search.shs'>
<input name='q' type='text'>
<input type='submit' value='Search'>
</form>
<h1>All user's favourites:</h1>"
echo "<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));'>"
declare -A strings
IFS=$'\n'
for i in $(tac storage/faves); do
@ -18,7 +11,5 @@ for i in $(tac storage/faves); do
if [[ ${array[1]} == '' ]]; then
break
fi
echo "<div><a href='watch?v=${array[1]}'><img src='https://i.ytimg.com/vi/${array[1]}/mqdefault.jpg'><br><b>${array[@]:2:999}</b></a><br>Favourited by ${array[0]}</div>";
storage[favourites]+="<div><a href='watch?v=${array[1]}'><img src='https://i.ytimg.com/vi/${array[1]}/mqdefault.jpg'><br><b>${array[@]:2:999}</b></a><br>Favourited by ${array[0]}</div>";
done
echo "</div>"

View File

@ -1,5 +1,7 @@
#!/bin/bash
declare -A strings
if [[ ${post_data[login]} != '' && ${post_data[password]} != '' ]]; then
login "${post_data[login]}" "${post_data[password]}"
status=$?
@ -15,14 +17,7 @@ fi
source templates/head.sh
if [[ $status == 1 && $reason != '' ]]; then
echo "$reason"
strings[reason]="$reason"
fi
echo "<h1>Log in...</h1>
<form method='post'>
<label for='login'>Login:</label>
<input type='text' name='login'><br>
<label for='password'>Password:</label>
<input type='password' name='password'><br>
<input type='submit' value='Login'>
</form>"
render strings "${cfg[namespace]}/templates/themes/${cfg[template]}/login.t"

View File

@ -1,7 +1,13 @@
#!/bin/bash
declare -A strings
logout
meta[redirect]='/'
source templates/head.sh
echo "Logged out successully. Redirecting.."
if [[ ${cfg[template]} == 'default' ]]; then
echo "Logged out successully. Redirecting.."
fi
render strings "${cfg[namespace]}/templates/themes/${cfg[template]}/logout.t"

View File

@ -1,13 +1,17 @@
#!/bin/bash
title=$(curl -s "https://www.youtube.com/feeds/videos.xml?playlist_id=${get_data[list]}" | grep title | head -n 1 | sed -s 's/ <title>//;s/<\/title>//')
meta[title]="$title"
source templates/head.sh
declare -A strings
if [[ ${cfg[template]} == 'default' ]]; then
meta[title]="$title"
source templates/head.sh
fi
if [[ "${get_data[list]}" ]]; then
data=$(haruhi-dl --cookies ${cfg[_cookies]} -j --flat-playlist "https://www.youtube.com/playlist?list=${get_data[list]}")
else
echo "Please specify id"
return
strings[playlist]="Please specify id"
fi
IFS=$'\n'
@ -15,5 +19,7 @@ video_title=($(jq -r '.title' <<< $data))
video_id=($(jq -r '.id' <<< $data))
for (( i=0; i<${#video_id[@]}; i++ )); do
echo "<a href='watch?v=${video_id[$i]}&playlist=$(html_encode "${get_data[list]}")'><img src='https://i.ytimg.com/vi/${video_id[$i]}/mqdefault.jpg'><br>${video_title[$i]}</a><br>"
strings[playlist]+="<a href='watch?v=${video_id[$i]}&playlist=$(html_encode "${get_data[list]}")'><img src='https://i.ytimg.com/vi/${video_id[$i]}/mqdefault.jpg'><br>${video_title[$i]}</a><br>"
done
render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/playlist.t"

View File

@ -1,5 +1,7 @@
#!/bin/bash
declare -A strings
if [[ ${post_data[login]} != '' && ${post_data[password]} != '' ]]; then
register ${post_data[login]} ${post_data[password]}
status=$?
@ -11,15 +13,7 @@ fi
source templates/head.sh
if [[ $status == 1 && $reason != '' ]]; then
echo $reason
strings[reason]="$reason"
fi
echo "<h1>Register</h1>
<form method='post'>
<label for='login'>Login:</label>
<input type='text' name='login'><br>
<label for='password'>Password:</label>
<input type='password' name='password'><br>
<input type='submit' value='Register'>
</form>
(please make sure that you're connecting over SSL)"
render strings "${cfg[namespace]}/templates/themes/${cfg[template]}/register.t"

View File

@ -1,23 +1,20 @@
#!/bin/bash
meta[title]="youtube but not really"
source templates/head.sh
declare -A strings
if [[ ${cfg[template]} == 'default' ]]; then
meta[title]="youtube but not really"
source templates/head.sh
fi
if [[ "${get_data[q]}" ]]; then
query="${get_data[q]}"
query_nice=$(sed -s 's/+/ /g' <<< "${get_data[q]}")
echo "<form action='/search.shs'>
<input name='q' type='text' value='$(html_encode "$query_nice")'>"
strings[search]="<form action='/search.shs'><input name='q' type='text' value='$(html_encode "$query_nice")'>"
else
echo "<form action='/search.shs'>
<input name='q' type='text'>"
strings[search]="<form action='/search.shs'><input name='q' type='text'>"
fi
echo "<input type='submit' value='Search'>
</form><br>"
if [[ "${get_data[q]}" ]]; then
data=$(haruhi-dl "ytsearch30:${get_data[q]}" --flat-playlist -J | jq '.entries[]')
@ -32,8 +29,10 @@ if [[ "${get_data[q]}" ]]; then
unset IFS
for (( i=0; i<${#id[@]}; i++ )); do
echo "<a href='/watch?v=${id[$i]}'><img src='https://i.ytimg.com/vi/${id[$i]}/mqdefault.jpg'><br>${title[$i]}</a> | ${runtime[$i]} seconds | ${views[$i]} views<br>Uploaded by <a href='/channel/${channel_id[$i]}'>${channel[$i]}</a><br>"
strings[results]+="<a href='/watch?v=${id[$i]}'><img src='https://i.ytimg.com/vi/${id[$i]}/mqdefault.jpg'><br>${title[$i]}</a> | ${runtime[$i]} seconds | ${views[$i]} views<br>Uploaded by <a href='/channel/${channel_id[$i]}'>${channel[$i]}</a><br>"
done
else
echo "search for something will 'ya?"
fi
render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/search.t"

View File

@ -1,5 +1,7 @@
#!/bin/bash
declare -A strings
if session_verify ${cookies[sh_session]} && [[ ${get_data[id]} != '' ]]; then
title=$(curl https://www.youtube.com/feeds/videos.xml?channel_id=${get_data[id]} | grep title | head -n 1 | sed -s 's/ <title>//;s/<\/title>//')
if [[ $((grep -PF ":$title$" | grep "$(echo ${cookies[username]} | sed -E "s/\r//")") <<< storage/subscribed) == '' ]]; then
@ -7,9 +9,9 @@ if session_verify ${cookies[sh_session]} && [[ ${get_data[id]} != '' ]]; then
fi
fi
source templates/head.sh
echo "<a href='./'>&lt;--- back to main</a><br><h1>Channels you subscribe to</h1>"
if [[ ${cfg[template]} == 'default' ]]; then
source templates/head.sh
fi
IFS=$'\n'
for i in $(tac storage/subscribed | grep -P "^$(session_get_username ${cookies[sh_session]}):"); do
@ -20,7 +22,9 @@ for i in $(tac storage/subscribed | grep -P "^$(session_get_username ${cookies[s
break
fi
echo "<div><a href='channel.shs?id=${array[1]}'>${array[@]:2:9999}</a><br></div>";
strings[subscribe]+="<div><a href='channel.shs?id=${array[1]}'>${array[@]:2:9999}</a><br></div>";
done
unset IFS
render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/subscribe.t"

View File

@ -1,12 +1,16 @@
#!/bin/bash
declare -A strings
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)'
strings[uploader]='MyMusicGroup'
strings[title]='█▬█ █ ▀█▀ Jeden Osiem L - Jak Zapomnieć (Oficjalny Teledysk)'
url='https://sakamoto.pl/tmp/videoplayback_.webm'
meta[title]=$title
source templates/head.sh
if [[ ${cfg[template]} == 'default' ]]; then
meta[title]="${strings[title]}"
source templates/head.sh
fi
else
cd temp
video=$(haruhi-dl --write-pages --cookies ${cfg[_cookies]} -J "http://youtube.com/watch?v=${get_data[v]}")
@ -18,11 +22,13 @@ if [[ "${get_data[v]}" ]]; then
fi
cd ..
#echo "http://youtube.com/watch?v=${get_data[v]}" > /dev/stderr
channel_id=$(jq -r '.channel_url' <<< "$video" | sed -s 's/http:\/\/www.youtube.com\/channel\///')
uploader=$(jq -r '.uploader' <<< "$video")
title=$(jq -r '.title' <<< "$video")
meta[title]="$title"
source templates/head.sh
strings[channel_id]=$(jq -r '.channel_url' <<< "$video" | sed -s 's/http:\/\/www.youtube.com\/channel\///')
strings[uploader]=$(jq -r '.uploader' <<< "$video")
strings[title]=$(jq -r '.title' <<< "$video")
if [[ ${cfg[template]} == 'default' ]]; then
meta[title]="${strings[title]}"
source templates/head.sh
fi
IFS=$'\n'
urls=($(jq -r '.formats[] | select(.format_id == "22" or .format_id == "18").url' <<< "$video"))
unset IFS
@ -32,58 +38,51 @@ if [[ "${get_data[v]}" ]]; then
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"
strings[player]=$(source "${cfg[namespace]}/webroot/player.shs")
strings[upload_date]=$(date -d "$(echo $video | jq -r '.upload_date' | sed -E 's/..../&-/;s/....-../&-/')" "+%d %B %Y")
strings[view_count]=$(echo $video | jq -r '.view_count')
strings[like_count]=$(echo $video | jq -r '.like_count')
strings[dislike_count]=$(echo $video | jq -r '.dislike_count')
#<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>"
if [[ ${cookies[sh_session]} ]]; then
if [[ $(grep $(session_get_username "${cookies[sh_session]}") storage/faves | grep "${get_data[v]}") == '' ]]; then
if [[ ${cfg[template]} == 'default' ]]; then
strings[fav]="<a href='fav.shs?v=$(sed -s 's/<//g;' <<< "${get_data[v]}")' target='_blank'>Add to favourites</a><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
if [[ ${cfg[template]} == 'default' ]]; then
strings[fav]="<a href='unfav.shs?v=$(sed -s 's/<//g;' <<< "${get_data[v]}")' target='_blank'>Remove from favourites</a><br>"
fi
fi
if [[ $(grep $(session_get_username "${cookies[sh_session]}") storage/subscribed | grep "$channel_id") == '' ]]; then
if [[ ${cfg[template]} == 'default' ]]; then
strings[fav]="<a href='subscribe.shs?id=$channel_id' target='_blank'>Subscribe to $uploader!</a><br>"
fi
else
if [[ ${cfg[template]} == 'default' ]]; then
strings[fav]="<a href='unsubscribe.shs?id=$channel_id' target='_blank'>Unsubscribe from $uploader</a><br>"
fi
fi
else
if [[ ${cfg[template]} == 'default' ]]; then
strings[fav]="<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
fi
strings[description]=$(echo "$video" | jq -r '.description' | sed -E 's/$/<br>/g')
vid="$(cat "temp/${get_data[v]}_https_-_"*"watch"*".dump")"
vid_json="$(tr -d '\n' <<< "$vid" | grep -Poh "ytInitialData.*?</script>" | sed 's/ytInitialData = //;s/<\/script>//')"
echo "<h1>Recommended</h1>
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));'>"
jq -r '.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results[] | .compactAutoplayRenderer.contents[0].compactVideoRenderer, .compactVideoRenderer | if .videoId != null then "<div><a href='"'"'/watch?v="+.videoId+"'"'"'><img src='"'"'https://i.ytimg.com/vi/"+.videoId+"/mqdefault.jpg'"'"'>"+.title.simpleText+"</a></div>" else empty end' <<< "$vid_json"
strings[recommended]=$(jq -r '.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results[] | .compactAutoplayRenderer.contents[0].compactVideoRenderer, .compactVideoRenderer | if .videoId != null then "<div><a href='"'"'/watch?v="+.videoId+"'"'"'><img src='"'"'https://i.ytimg.com/vi/"+.videoId+"/mqdefault.jpg'"'"'>"+.title.simpleText+"</a></div>" else empty end' <<< "$vid_json")
#for i in $(grep -ohE "watch\?v\=[A-zaz0-9]{11}" <<< "$vid" | cut -c 9-19 | uniq); do
# echo "<div><a href='/watch?v=$i'><img src='https://i.ytimg.com/vi/$i/mqdefault.jpg'></a><br></div>";
#done
vid="$(curl -s "https://www.youtube.com/watch?v=${get_data[v]}" -c cookiejar_)" # broken comment support, we need this for now
echo "</div><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')"
@ -104,12 +103,11 @@ if [[ "${get_data[v]}" ]]; then
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>"
strings[comments_list]+=$(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
strings[playlist]=""
if [[ "${get_data[playlist]}" ]]; then
playlist=$(haruhi-dl --cookies ${cfg[_cookies]} -j --flat-playlist "https://www.youtube.com/playlist?list=${get_data[playlist]}")
@ -126,23 +124,14 @@ if [[ "${get_data[v]}" ]]; then
[[ "$next" == '' ]] && next='dQw4w9WgXcQ'
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>"
strings[playlist]+="<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><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>"
strings[playlist]+="<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>"
render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/watch.t"
else
source templates/head.sh
echo "pls add ?v param i'm still WiP"

View File

@ -1,12 +1,16 @@
#!/bin/bash
declare -A strings
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)'
strings[uploader]='MyMusicGroup'
strings[title]='█▬█ █ ▀█▀ Jeden Osiem L - Jak Zapomnieć (Oficjalny Teledysk)'
url='https://f.sakamoto.pl/videoplayback_.flv'
meta[title]="$title"
source templates/head.sh
if [[ ${cfg[template]} == 'default' ]]; then
meta[title]="${strings[title]}"
source templates/head.sh
fi
else
cd temp
video=$(haruhi-dl --write-pages --cookies ${cfg[_cookies]} -J "http://youtube.com/watch?v=${get_data[v]}")
@ -18,11 +22,13 @@ if [[ "${get_data[v]}" ]]; then
fi
cd ..
#echo "http://youtube.com/watch?v=${get_data[v]}" > /dev/stderr
channel_id=$(jq -r '.channel_url' <<< "$video" | sed -s 's/http:\/\/www.youtube.com\/channel\///')
uploader=$(jq -r '.uploader' <<< "$video")
title=$(jq -r '.title' <<< "$video")
meta[title]="$title"
source templates/head.sh
strings[channel_id]=$(jq -r '.channel_url' <<< "$video" | sed -s 's/http:\/\/www.youtube.com\/channel\///')
strings[uploader]=$(jq -r '.uploader' <<< "$video")
strings[title]=$(jq -r '.title' <<< "$video")
if [[ ${cfg[template]} == 'default' ]]; then
meta[title]="${strings[title]}"
source templates/head.sh
fi
IFS=$'\n'
urls=($(jq -r '.formats[] | select(.format_id == "22" or .format_id == "18").url' <<< "$video"))
unset IFS
@ -32,50 +38,44 @@ if [[ "${get_data[v]}" ]]; then
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_flash.shs"
strings[player]=$(source "${cfg[namespace]}/webroot/player_flash.shs")
strings[upload_date]=$(date -d "$(echo $video | jq -r '.upload_date' | sed -E 's/..../&-/;s/....-../&-/')" "+%d %B %Y")
strings[view_count]=$(echo $video | jq -r '.view_count')
strings[like_count]=$(echo $video | jq -r '.like_count')
strings[dislike_count]=$(echo $video | jq -r '.dislike_count')
#<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>"
if [[ ${cookies[sh_session]} ]]; then
if [[ $(grep $(session_get_username "${cookies[sh_session]}") storage/faves | grep "${get_data[v]}") == '' ]]; then
if [[ ${cfg[template]} == 'default' ]]; then
echo "<a href='fav.shs?v=$(sed -s 's/<//g;' <<< "${get_data[v]}")' target='_blank'>Add to favourites</a><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
if [[ ${cfg[template]} == 'default' ]]; then
echo "<a href='unfav.shs?v=$(sed -s 's/<//g;' <<< "${get_data[v]}")' target='_blank'>Remove from favourites</a><br>"
fi
fi
if [[ $(grep $(session_get_username "${cookies[sh_session]}") storage/subscribed | grep "$channel_id") == '' ]]; then
if [[ ${cfg[template]} == 'default' ]]; then
echo "<a href='subscribe.shs?id=$channel_id' target='_blank'>Subscribe to $uploader!</a><br>"
fi
else
if [[ ${cfg[template]} == 'default' ]]; then
echo "<a href='unsubscribe.shs?id=$channel_id' target='_blank'>Unsubscribe from $uploader</a><br>"
fi
fi
else
if [[ ${cfg[template]} == 'default' ]]; then
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
fi
vid="$(cat "temp/${get_data[v]}_https_-_"*"watch"*".dump")"
vid_json="$(tr -d '\n' <<< "$vid" | grep -Poh "ytInitialData.*?</script>" | sed 's/ytInitialData = //;s/<\/script>//')"
echo "<h1>Recommended</h1>
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));'>"
jq -r '.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results[] | .compactAutoplayRenderer.contents[0].compactVideoRenderer, .compactVideoRenderer | if .videoId != null then "<div><a href='"'"'/watch?v="+.videoId+"'"'"'><img src='"'"'https://i.ytimg.com/vi/"+.videoId+"/mqdefault.jpg'"'"'>"+.title.simpleText+"</a></div>" else empty end' <<< "$vid_json"
strings[recommended]=$(jq -r '.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results[] | .compactAutoplayRenderer.contents[0].compactVideoRenderer, .compactVideoRenderer | if .videoId != null then "<div><a href='"'"'/watch?v="+.videoId+"'"'"'><img src='"'"'https://i.ytimg.com/vi/"+.videoId+"/mqdefault.jpg'"'"'>"+.title.simpleText+"</a></div>" else empty end' <<< "$vid_json")
#for i in $(grep -ohE "watch\?v\=[A-zaz0-9]{11}" <<< "$vid" | cut -c 9-19 | uniq); do
# echo "<div><a href='/watch?v=$i'><img src='https://i.ytimg.com/vi/$i/mqdefault.jpg'></a><br></div>";
@ -104,12 +104,11 @@ if [[ "${get_data[v]}" ]]; then
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>"
strings[comments_list]+="<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
strings[playlist]=""
if [[ "${get_data[playlist]}" ]]; then
playlist=$(haruhi-dl --cookies ${cfg[_cookies]} -j --flat-playlist "https://www.youtube.com/playlist?list=${get_data[playlist]}")
@ -126,23 +125,14 @@ if [[ "${get_data[v]}" ]]; then
[[ "$next" == '' ]] && next='dQw4w9WgXcQ'
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>"
strings[playlist]+="<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><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>"
strings[playlist]+="<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>"
render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/watch_flash.t"
else
source templates/head.sh
echo "pls add ?v param i'm still WiP"