diff --git a/config.sh b/config.sh index 1880b32..3ed30d8 100644 --- a/config.sh +++ b/config.sh @@ -1,3 +1,4 @@ cfg[title]='BashTube' cfg[_cookies]='cookiejar' cfg[flash_host]='flash.xn--domi-o5a.pl' +cfg[template]='default' diff --git a/templates/themes/default/fav.t b/templates/themes/default/fav.t new file mode 100644 index 0000000..4246b56 --- /dev/null +++ b/templates/themes/default/fav.t @@ -0,0 +1,2 @@ +<--- back to main

Your favourites

+{{.fav}} diff --git a/templates/themes/default/feed.t b/templates/themes/default/feed.t new file mode 100644 index 0000000..47cf858 --- /dev/null +++ b/templates/themes/default/feed.t @@ -0,0 +1 @@ +{{.feed}} diff --git a/templates/themes/default/index.t b/templates/themes/default/index.t new file mode 100644 index 0000000..0e6857c --- /dev/null +++ b/templates/themes/default/index.t @@ -0,0 +1,8 @@ +
+ + +
+

All user's favourites:

+
+{{.favourites}} +
diff --git a/templates/themes/default/login.t b/templates/themes/default/login.t new file mode 100644 index 0000000..a037f01 --- /dev/null +++ b/templates/themes/default/login.t @@ -0,0 +1,9 @@ +

Log in...

+
+ +
+ +
+ +
+{{.reason}} diff --git a/templates/themes/default/playlist.t b/templates/themes/default/playlist.t new file mode 100644 index 0000000..b379393 --- /dev/null +++ b/templates/themes/default/playlist.t @@ -0,0 +1 @@ +{{.playlist}} diff --git a/templates/themes/default/register.t b/templates/themes/default/register.t new file mode 100644 index 0000000..06f36a8 --- /dev/null +++ b/templates/themes/default/register.t @@ -0,0 +1,10 @@ +

Register

+
+ +
+ +
+ +
+(please make sure that you're connecting over SSL)
+{{.reason}} diff --git a/templates/themes/default/search.t b/templates/themes/default/search.t new file mode 100644 index 0000000..2b014ad --- /dev/null +++ b/templates/themes/default/search.t @@ -0,0 +1,4 @@ +{{.search}} + +
+{{.results}} diff --git a/templates/themes/default/subscribe.t b/templates/themes/default/subscribe.t new file mode 100644 index 0000000..66f36e7 --- /dev/null +++ b/templates/themes/default/subscribe.t @@ -0,0 +1,2 @@ +<--- back to main

Channels you subscribe to

+{{.subscribe}} diff --git a/templates/themes/default/watch.t b/templates/themes/default/watch.t new file mode 100644 index 0000000..f98c038 --- /dev/null +++ b/templates/themes/default/watch.t @@ -0,0 +1,27 @@ +
+ + +
+

+{{.player}} +

{{.title}}

+
+
+ Uploaded by {{.uploader}} on {{.upload_date}} +
+
+ {{.view_count}} views
+ {{.like_count}} likes, {{.dislike_count}} dislikes.
+{{.fav}} +

+
+
+Description:
{{.description}}
+
+

Recommended

+
+{{.recommended}} +

Comments

+{{.comments_list}} +{{.playlist}} + diff --git a/templates/themes/default/watch_flash.t b/templates/themes/default/watch_flash.t new file mode 100644 index 0000000..f98c038 --- /dev/null +++ b/templates/themes/default/watch_flash.t @@ -0,0 +1,27 @@ +
+ + +
+

+{{.player}} +

{{.title}}

+
+
+ Uploaded by {{.uploader}} on {{.upload_date}} +
+
+ {{.view_count}} views
+ {{.like_count}} likes, {{.dislike_count}} dislikes.
+{{.fav}} +

+
+
+Description:
{{.description}}
+
+

Recommended

+
+{{.recommended}} +

Comments

+{{.comments_list}} +{{.playlist}} + diff --git a/webroot/fav.shs b/webroot/fav.shs index e3c7d7f..2d1440e 100644 --- a/webroot/fav.shs +++ b/webroot/fav.shs @@ -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 "<--- back to main

Your favourites

" +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 "

${array[@]:2:999}

"; + strings[fav]+="

${array[@]:2:999}

"; done + +render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/fav.t" diff --git a/webroot/feed.shs b/webroot/feed.shs index 92b8225..c7953e5 100644 --- a/webroot/feed.shs +++ b/webroot/feed.shs @@ -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 "
${video_title[$i]}
$(date -d "@${video_date[$i]}" "+%H:%M, %d %h %Y")
" + strings[feed]+="
${video_title[$i]}
$(date -d "@${video_date[$i]}" "+%H:%M, %d %h %Y")
" done <<< "$queue" else - echo "gtfo" + strings[feed]="gtfo" fi + +render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/feed.t" diff --git a/webroot/index.shs b/webroot/index.shs index 27dc76c..4629c09 100755 --- a/webroot/index.shs +++ b/webroot/index.shs @@ -2,14 +2,7 @@ source templates/head.sh source ${cfg[namespace]}/templates/header.shs -echo "
- - -
- -

All user's favourites:

" - -echo "
" +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 "

${array[@]:2:999}

Favourited by ${array[0]}
"; + storage[favourites]+="

${array[@]:2:999}

Favourited by ${array[0]}
"; done - -echo "
" diff --git a/webroot/login.shs b/webroot/login.shs index d8b879d..99bd2e9 100755 --- a/webroot/login.shs +++ b/webroot/login.shs @@ -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 "

Log in...

-
- -
- -
- -
" +render strings "${cfg[namespace]}/templates/themes/${cfg[template]}/login.t" diff --git a/webroot/logout.shs b/webroot/logout.shs index 538ef39..3a8dd46 100755 --- a/webroot/logout.shs +++ b/webroot/logout.shs @@ -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" diff --git a/webroot/playlist.shs b/webroot/playlist.shs index 3c53c75..b07c750 100644 --- a/webroot/playlist.shs +++ b/webroot/playlist.shs @@ -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/ //;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" diff --git a/webroot/register.shs b/webroot/register.shs index 4913367..c767b4a 100755 --- a/webroot/register.shs +++ b/webroot/register.shs @@ -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" diff --git a/webroot/search.shs b/webroot/search.shs index 37d9f5b..a8be51a 100755 --- a/webroot/search.shs +++ b/webroot/search.shs @@ -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" diff --git a/webroot/subscribe.shs b/webroot/subscribe.shs index f83b66f..0053dfb 100644 --- a/webroot/subscribe.shs +++ b/webroot/subscribe.shs @@ -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='./'><--- 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" diff --git a/webroot/watch.shs b/webroot/watch.shs index 06b8e0c..ede7756 100755 --- a/webroot/watch.shs +++ b/webroot/watch.shs @@ -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" diff --git a/webroot/watch_flash.shs b/webroot/watch_flash.shs index ad4be8b..177006f 100755 --- a/webroot/watch_flash.shs +++ b/webroot/watch_flash.shs @@ -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"