repo: uritools
action: commit
revision: 
path_from: 
revision_from: 82f7fe701000a5de6c753ef572621dad51e1eace:
path_to: 
revision_to: 
git.thebackupbox.net
uritools
git clone git://git.thebackupbox.net/uritools
commit 82f7fe701000a5de6c753ef572621dad51e1eace
Author: epoch 
Date:   Mon Oct 19 01:48:04 2020 +0000

    added html over gemini title support

diff --git a/urititle b/urititle
index 7b159da1b38966a65a1cb836f50fd4287327c7df..
index ..85f32597d4d1385b741314d32c23ef3a668cf902 100755
--- a/urititle
+++ b/urititle
@@ -45,8 +45,13 @@ gemini)
   gemini-get "$1" | while read -r line;do
     if [ "$first" ];then
       unset first
-      if ! printf "%s\n" "$line" | grep '^[^ ]* text/gemini' 2>&1 >/dev/null;then
-        printf "title: %s\n" "$(printf "%s\n" "$line" | tr '\t' ' ' | tr -s ' ' | cut '-d ' -f2-)"
+      type="$(printf "%s\n" "$line" | tr -s ' ' | cut '-d ' -f2 | tr -d '\r')"
+      if [ "$type" != 'text/gemini' ];then
+        if [ "$type" = "text/html" ];then
+          head -c 1000000 | tr -d '\n' | tr '<' '\n' | grep -iA 10 '^title' | grep -iB 10 '^\/title>' | cut '-d>' -f2 | tr '\t' ' ' | sed 's/^ *//g' | sed 's/ *$//g' | grep .
+        else
+          printf "title: %s\n" "$(printf "%s\n" "$line" | tr '\t' ' ' | tr -s ' ' | cut '-d ' -f2-)"
+        fi
       fi
     else
       printf "title: %s\n" "$(printf "%s\n" "$line" | grep '^#' | sed 's/^#* *//g')"

-----END OF PAGE-----