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/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/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/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; 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..a9a7f13 100755 --- a/webroot/watch.shs +++ b/webroot/watch.shs @@ -1,7 +1,19 @@ #!/bin/bash +if [[ ! -d "temp" ]]; then + mkdir "temp" +fi + declare -A strings +if [[ ! $(which haruhi-dl) ]]; then + 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 if [[ "${get_data[v]}" == '18l' || "${get_data[v]}" == '5eFdt6Y_34E' ]]; then strings[uploader]='MyMusicGroup' @@ -18,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 @@ -51,8 +77,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]='' # @@ -136,6 +169,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