From 9705a81be3e6a7d63909074ab45b862b46c6d88f Mon Sep 17 00:00:00 2001 From: epoch Date: Mon, 12 Oct 2020 09:16:57 +0000 Subject: urititle now will show content-type of gemini links if it isn't text/gemini --- urititle | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'urititle') diff --git a/urititle b/urititle index 510c7cd..f6f93ea 100755 --- a/urititle +++ b/urititle @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash scheme=$(printf "%s\n" "$1" | uricut -s) path=$(printf "%s\n" "$1" | uricut -p) qs=$(printf "%s\n" "$1" | uricut -q) @@ -37,7 +37,17 @@ if [ "$port" ];then fi ;; gemini) - printf "title: %s\n" "$(gemini-get "$1" | grep '^#' | head -n1 | sed 's/^#* *//g')" + first=1 + 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-)" + fi + else + printf "title: %s\n" "$(printf "%s\n" "$line" | grep '^#' | sed 's/^#* *//g')" + fi + done | head -n1 ;; magnet) printf "title: %s\n" "$(printf "%s\n" "$1" | tr '&' '\n' | grep ^dn= | cut -d= -f2- | uriunescape)" -- cgit v1.2.3 From d88e13ca253bd1f2c3acad0dae911f7aa0669dec Mon Sep 17 00:00:00 2001 From: epoch Date: Sun, 18 Oct 2020 03:57:52 +0000 Subject: urititle can now do ftp URIs and if curl errors out on http or https URIs, it'll let you know. --- urititle | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'urititle') diff --git a/urititle b/urititle index f6f93ea..6367473 100755 --- a/urititle +++ b/urititle @@ -18,21 +18,25 @@ if [ "$qs" ];then fi case "$scheme" in http*) -if [ "$port" ];then + if [ "$port" ];then UA="Mozilla/5.0 (impersonator)" # content_type="$(printf "HEAD %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: %s\r\n\r\n" "$path" "$domain" "$UA" | ncat -4 $SSL "$domain" "$port" | grep -i '^Content-Type: ' | head -n1 | cut '-d ' -f2 | cut '-d;' -f1 | tr -d '\r\n')" - a_header="$(curl -Lsi "$1" | head -c 10000 | egrep -ai '^Location: |^Content-Type: ' | head -n1 | tr -d '\r\n')" + a_header="$((curl -Lsi "$1" || echo curl failed) | head -c 10000 | egrep -ai '^curl failed|^Location: |^Content-Type: ' | head -n1 | tr -d '\r\n')" if printf "%s\n" "${a_header}" | grep -i '^Content-Type: ' 2>&1 >/dev/null 2>&1;then content_type="$(printf '%s\n' "${a_header}" | cut '-d ' -f2- | cut '-d;' -f1)" - else - content_type="redirect probably" + fi + if printf "%s\n" "${a_header}" | grep -i '^Location: ' 2>&1 >/dev/null 2>&1;then + content_type="redirect. ${a_header}" + fi + if printf "%s\n" "${a_hreader}" | grep -i '^curl failed' 2>&1 >/dev/null 2>&1;then + content_type="curl failed. cert expired? dunno yet. TODO: code openssl checker." fi if [ "${content_type}" = "text/html" -o "${content_type}" = "application/xhtml+xml" ];then # title="$(printf "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: %s\r\n\r\n" "$path" "$domain" "$UA" | ncat -4 $SSL "$domain" "$port" | head -c 10000 | tr -d '\n' | tr '<' '\n' | grep -A 10 '^title>' | grep -B 10 '^\/title>' | cut '-d>' -f2)" title="$(curl -si "$1" | 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 .)" printf "title: %s\n" "$title" | html_entities_decode else - printf "%s\n" "${a_header}" + printf "%s %s\n" "${a_header}" "${content_type}" fi fi ;; @@ -52,6 +56,9 @@ gemini) magnet) printf "title: %s\n" "$(printf "%s\n" "$1" | tr '&' '\n' | grep ^dn= | cut -d= -f2- | uriunescape)" ;; +ftp) + curl "$1" 2>&1 | tail -n1 + ;; ssh) if [ ! "$port" ];then port=22 -- cgit v1.2.3 From 840a373b74a8202801126af195177b9964e8377a Mon Sep 17 00:00:00 2001 From: epoch Date: Mon, 19 Oct 2020 01:36:21 +0000 Subject: added support for gopher links of type 1 and 0 --- urititle | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'urititle') diff --git a/urititle b/urititle index 6367473..7b159da 100755 --- a/urititle +++ b/urititle @@ -59,6 +59,16 @@ magnet) ftp) curl "$1" 2>&1 | tail -n1 ;; +gopher) + type="$(printf "%s\n" "$1" | uricut -p | cut -b2- | cut -b1)" + if [ "$type" = 1 -o "$type" = "" ];then + printf "title: %s\n" "$(curl -s "$1" | grep ^i | head -n1 | cut -f1 | cut -b2-)" + elif [ "$type" = 0 ];then + printf "title: %s\n" "$(curl -s "$1" | head -n1)" + else + printf "title: don't know how to get title of non-1 gopher links" + fi + ;; ssh) if [ ! "$port" ];then port=22 -- cgit v1.2.3 From 82f7fe701000a5de6c753ef572621dad51e1eace Mon Sep 17 00:00:00 2001 From: epoch Date: Mon, 19 Oct 2020 01:48:04 +0000 Subject: added html over gemini title support --- urititle | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'urititle') diff --git a/urititle b/urititle index 7b159da..85f3259 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')" -- cgit v1.2.3 From a75363e4d77a9f35a9e8fb1515945629aba97d9a Mon Sep 17 00:00:00 2001 From: epoch Date: Mon, 16 Nov 2020 00:51:36 +0000 Subject: http redirects were being output twice in urititle --- urititle | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'urititle') diff --git a/urititle b/urititle index 85f3259..662201c 100755 --- a/urititle +++ b/urititle @@ -25,9 +25,9 @@ http*) if printf "%s\n" "${a_header}" | grep -i '^Content-Type: ' 2>&1 >/dev/null 2>&1;then content_type="$(printf '%s\n' "${a_header}" | cut '-d ' -f2- | cut '-d;' -f1)" fi - if printf "%s\n" "${a_header}" | grep -i '^Location: ' 2>&1 >/dev/null 2>&1;then - content_type="redirect. ${a_header}" - fi + #if printf "%s\n" "${a_header}" | grep -i '^Location: ' 2>&1 >/dev/null 2>&1;then + # content_type="redirect. ${a_header}" + #fi if printf "%s\n" "${a_hreader}" | grep -i '^curl failed' 2>&1 >/dev/null 2>&1;then content_type="curl failed. cert expired? dunno yet. TODO: code openssl checker." fi @@ -70,6 +70,8 @@ gopher) printf "title: %s\n" "$(curl -s "$1" | grep ^i | head -n1 | cut -f1 | cut -b2-)" elif [ "$type" = 0 ];then printf "title: %s\n" "$(curl -s "$1" | head -n1)" + elif [ "$type" = "h" ];then + printf "title: %s\n" "$(curl -s "$1" | 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: don't know how to get title of non-1 gopher links" fi -- cgit v1.2.3