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