From ac879ac79d58ddcd8a0ce9c83b02917cf0484829 Mon Sep 17 00:00:00 2001 From: sech1p Date: Sun, 14 Mar 2021 15:43:17 +0100 Subject: [PATCH 1/5] Add friendly messages to template strings --- webroot/channel.shs | 7 ++++++- webroot/fav.shs | 4 ++++ webroot/index.shs | 2 ++ webroot/playlist.shs | 4 ++++ webroot/register.shs | 2 ++ webroot/search.shs | 6 +++++- webroot/subscribe.shs | 4 ++++ webroot/watch.shs | 4 ++++ 8 files changed, 31 insertions(+), 2 deletions(-) diff --git a/webroot/channel.shs b/webroot/channel.shs index b9181bb..aac1569 100644 --- a/webroot/channel.shs +++ b/webroot/channel.shs @@ -14,6 +14,7 @@ else echo "Please specify either id or name" return fi + title=$(jq -r '.title' <<< $data) if [[ ${cfg[template]} == 'default' ]]; then @@ -27,9 +28,13 @@ video_id=($(jq -r '.entries[].id' <<< $data)) strings[subscribe]="

$title

Subscribe!
" -for (( i=0; i<${#video_id[@]}; i++ )); do +for (( i=0; i<${#video_id[@]}; i++ )); do strings[videos]+="
${video_title[$i]}

" done +if [[ ! ${strings[videos]} ]]; then + strings[videos]="Failed to fetch videos or channel does not have videos" +fi + source "${cfg[namespace]}/templates/header.shs" render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/channel.t" diff --git a/webroot/fav.shs b/webroot/fav.shs index c48b6a0..d5c4307 100644 --- a/webroot/fav.shs +++ b/webroot/fav.shs @@ -23,5 +23,9 @@ for i in $(tac storage/faves | grep -P "^$(session_get_username ${cookies[sh_ses strings[fav]+="

${array[@]:2:999}

"; done +if [[ ! ${strings[fav]} ]]; then + strings[fav]="You are not logged in or you do not have any favorites" +fi + source "${cfg[namespace]}/templates/header.shs" render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/fav.t" diff --git a/webroot/index.shs b/webroot/index.shs index 1980ee5..0d1be18 100755 --- a/webroot/index.shs +++ b/webroot/index.shs @@ -4,6 +4,8 @@ source ${cfg[namespace]}/templates/header.shs declare -A strings +strings[favourites]="No favorite videos found,
you can do it first! ^w^" + IFS=$'\n' for i in $(tac storage/faves); do IFS=':' diff --git a/webroot/playlist.shs b/webroot/playlist.shs index 456b132..6fbb802 100644 --- a/webroot/playlist.shs +++ b/webroot/playlist.shs @@ -22,5 +22,9 @@ for (( i=0; i<${#video_id[@]}; i++ )); do strings[playlist]+="
${video_title[$i]}

" done +if [[ ! ${strings[playlist]} ]]; then + strings[playlist]="Invalid playlist or playlist does not have videos" +fi + source "${cfg[namespace]}/templates/header.shs" render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/playlist.t" diff --git a/webroot/register.shs b/webroot/register.shs index c767b4a..768f4d9 100755 --- a/webroot/register.shs +++ b/webroot/register.shs @@ -14,6 +14,8 @@ source templates/head.sh if [[ $status == 1 && $reason != '' ]]; then strings[reason]="$reason" +else + strings[reason]="" fi render strings "${cfg[namespace]}/templates/themes/${cfg[template]}/register.t" diff --git a/webroot/search.shs b/webroot/search.shs index 098d06e..d6e2619 100755 --- a/webroot/search.shs +++ b/webroot/search.shs @@ -29,7 +29,11 @@ if [[ "${get_data[q]}" ]]; then strings[results]+="
${title[$i]}
| ${runtime[$i]} seconds | ${views[$i]} views
Uploaded by ${channel[$i]}
" done else - echo "search for something will 'ya?" + strings[results]="search for something will 'ya?" +fi + +if [[ ! $(which haruhi-dl) || $? != "0" ]]; then + strings[results]="Could not fetch search results" fi source "${cfg[namespace]}/templates/header.shs" diff --git a/webroot/subscribe.shs b/webroot/subscribe.shs index 5dee1fb..bb79347 100644 --- a/webroot/subscribe.shs +++ b/webroot/subscribe.shs @@ -27,5 +27,9 @@ done unset IFS +if [[ ! ${strings[subscribe]} ]]; then + strings[subscribe]="You are not logged in or you do not have any subscribed channels" +fi + source "${cfg[namespace]}/templates/header.shs" render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/subscribe.t" diff --git a/webroot/watch.shs b/webroot/watch.shs index c3c5e29..182d1f0 100755 --- a/webroot/watch.shs +++ b/webroot/watch.shs @@ -2,6 +2,10 @@ declare -A strings +if [[ ! $(which haruhi-dl) ]]; then + echo "Could not load video" +fi + if [[ "${get_data[v]}" ]]; then if [[ "${get_data[v]}" == '18l' || "${get_data[v]}" == '5eFdt6Y_34E' ]]; then strings[uploader]='MyMusicGroup' From 9219c234817a70b4952262f74beff951c2a04f6b Mon Sep 17 00:00:00 2001 From: sech1p Date: Sun, 14 Mar 2021 15:58:30 +0100 Subject: [PATCH 2/5] watch.shs improved (with support for disabled likes and comments) --- templates/themes/default/watch.t | 2 +- webroot/watch.shs | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/templates/themes/default/watch.t b/templates/themes/default/watch.t index b882d9c..d9f3073 100644 --- a/templates/themes/default/watch.t +++ b/templates/themes/default/watch.t @@ -7,7 +7,7 @@
{{.view_count}} views
- {{.like_count}} likes, {{.dislike_count}} dislikes.
+ {{.like_dislike_count}}
{{.fav}} {{.sub}}

diff --git a/webroot/watch.shs b/webroot/watch.shs index 182d1f0..a31a3a9 100755 --- a/webroot/watch.shs +++ b/webroot/watch.shs @@ -55,8 +55,15 @@ if [[ "${get_data[v]}" ]]; then 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') + like_count=$(echo $video | jq -r '.like_count') + dislike_count=$(echo $video | jq -r '.dislike_count') + if [[ ${cfg[template]} == 'default' ]]; then + if [[ $like_count == 'null' && $dislike_count == 'null' ]]; then + strings[like_dislike_count]="Likes are turned off" + else + strings[like_dislike_count]="$like_count likes, $dislike_count dislikes." + fi + fi strings[sub]='' # @@ -140,6 +147,14 @@ if [[ "${get_data[v]}" ]]; then done fi + if [[ ! ${strings[recommended]} ]]; then + strings[recommended]='An error occurred during fetching Recommended Videos' + fi + + if [[ ! ${strings[comments_list]} ]]; then + strings[comments_list]='Comments are turned off
or an error occured during fetching their' + fi + source "${cfg[namespace]}/templates/header.shs" render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/watch.t" else From 102fdd69f4f24389455806aa49b1befab5c8f77c Mon Sep 17 00:00:00 2001 From: sech1p Date: Sun, 14 Mar 2021 16:07:06 +0100 Subject: [PATCH 3/5] Add checking if "temp" folder exists if not then it creates a temp folder! (prevents watch.shs from broken* (*read as: blank page and temporary files saved in wrong place) --- webroot/watch.shs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/webroot/watch.shs b/webroot/watch.shs index a31a3a9..b69ece7 100755 --- a/webroot/watch.shs +++ b/webroot/watch.shs @@ -1,5 +1,9 @@ #!/bin/bash +if [[ ! -d "temp" ]]; then + mkdir "temp" +fi + declare -A strings if [[ ! $(which haruhi-dl) ]]; then From 14a0adb761cdd2ef35cb9ba10f55b680b5de288a Mon Sep 17 00:00:00 2001 From: sech1p Date: Mon, 15 Mar 2021 19:02:33 +0100 Subject: [PATCH 4/5] + watch.shs error handling --- templates/themes/default/watch_error.t | 2 ++ webroot/watch.shs | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 templates/themes/default/watch_error.t diff --git a/templates/themes/default/watch_error.t b/templates/themes/default/watch_error.t new file mode 100644 index 0000000..bea24e1 --- /dev/null +++ b/templates/themes/default/watch_error.t @@ -0,0 +1,2 @@ +

+{{.error}} diff --git a/webroot/watch.shs b/webroot/watch.shs index b69ece7..a9a7f13 100755 --- a/webroot/watch.shs +++ b/webroot/watch.shs @@ -7,7 +7,11 @@ fi declare -A strings if [[ ! $(which haruhi-dl) ]]; then - echo "Could not load video" + strings[error]='Could not load video' + source templates/head.sh + source "${cfg[namespace]}/templates/header.shs" + render strings "${cfg[namespace]}/templates/themes/${cfg[template]}/watch_error.t" + return fi if [[ "${get_data[v]}" ]]; then @@ -26,8 +30,22 @@ if [[ "${get_data[v]}" ]]; then cd temp video=$(haruhi-dl --write-pages --cookies ${cfg[_cookies]} -J "http://youtube.com/watch?v=${get_data[v]}") if [[ $video == '' ]]; then # okay who did this - video=$(haruhi-dl --write-pages --cookies ${cfg[_cookies]} -J "http://youtube.com/watch?v=${get_data[v]}") + random_hash=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 24 | head -n 1) + video=$(haruhi-dl --write-pages --cookies ${cfg[_cookies]} -J "http://youtube.com/watch?v=${get_data[v]}" &> output$random_hash.log) if [[ $video == '' ]]; then # seriously WHO DID THIS + output=$(cat output$random_hash.log) + rm output$random_hash.log + cd .. + if [[ $output == 'ERROR: Video unavailable' ]]; then + strings[error]='Video unavailable' + elif [[ $output == *'ERROR: Incomplete YouTube ID'* ]]; then + strings[error]='Incomplete YouTube ID' + else + strings[error]='Unexpected error has occured' + fi + source templates/head.sh + source "${cfg[namespace]}/templates/header.shs" + render strings "${cfg[namespace]}/templates/themes/${cfg[template]}/watch_error.t" return fi fi From 5894023a9362c2ef9f1a6fb8a7a7d17e892f8d15 Mon Sep 17 00:00:00 2001 From: sech1p Date: Tue, 16 Mar 2021 12:48:55 +0100 Subject: [PATCH 5/5] fix typo --- webroot/js/player.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webroot/js/player.js b/webroot/js/player.js index 07cb001..b37df45 100644 --- a/webroot/js/player.js +++ b/webroot/js/player.js @@ -120,7 +120,7 @@ window.addEventListener('DOMContentLoaded', (event) => { return 1; } if (a.vcodec !== 'none' && b.vcodec !== 'none') { - return b.width - a.height; + return b.height - a.height; } if (a.acodec !== 'none' && b.acodec !== 'none') { return b.abr - a.abr;