curl-grabtitle: do not try to get title for non-HTML URLs - annna - Annna the n… | |
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
--- | |
commit 408ac5316fd5a2b720b21bc5ae11db810bf33a7b | |
parent a3e40e235d62c466db9c6c9a50b4e80ecad24958 | |
Author: Quentin Rameau <[email protected]> | |
Date: Thu, 15 Jul 2021 00:24:15 +0200 | |
curl-grabtitle: do not try to get title for non-HTML URLs | |
Signed-off-by: Annna Robert-Houdin <[email protected]> | |
Diffstat: | |
M curl-grabtitle | 7 ++++--- | |
M fetch-uri | 20 +++++++++++++++++--- | |
2 files changed, 21 insertions(+), 6 deletions(-) | |
--- | |
diff --git a/curl-grabtitle b/curl-grabtitle | |
@@ -1,11 +1,12 @@ | |
#!/bin/sh | |
export PATH="$HOME/bin:$PATH" | |
-if [ $# -lt 1 ]; | |
+if [ $# -lt 1 ] | |
then | |
- printf "usage: %s\n" "$(basename "$0")" >&2 | |
+ printf "usage: %s URI\n" "$(basename "$0")" >&2 | |
exit 1 | |
fi | |
-fetch-uri "$1" | grabtitle | |
+fetch-uri -h "$1" | grep '^content-type:.* text/html' >/dev/null 2>&1 || exit | |
+fetch-uri "$1" | grabtitle | |
diff --git a/fetch-uri b/fetch-uri | |
@@ -1,9 +1,22 @@ | |
#!/bin/sh | |
-if [ $# -lt 1 ]; | |
-then | |
- printf "usage: %s\n" "$(basename "$0")" >&2 | |
+set -x | |
+ | |
+usage() { | |
+ printf "usage: %s [-h] URI\n" "$(basename "$0")" >&2 | |
exit 1 | |
+} | |
+ | |
+if [ $# -lt 1 ] || [ $# -gt 2 ] | |
+then | |
+ usage | |
+fi | |
+ | |
+if [ $# -eq 2 ] | |
+then | |
+ [ $1 = -h ] || usage | |
+ opth=-I | |
+ shift | |
fi | |
curl \ | |
@@ -12,4 +25,5 @@ curl \ | |
-L --max-redirs 3 \ | |
-m 5 \ | |
-H 'User-Agent:' \ | |
+ $opth \ | |
"$1" 2>/dev/null |