summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2015-05-02 18:45:31 +0100
committerLuke Bratch <luke@bratch.co.uk>2015-05-02 18:45:31 +0100
commitf2fb938c798f0493248049204b32b87afd7c178c (patch)
tree06430ed6766467b02fc7f313d7cfc3eaa3d400af
parente0c0eec421954badbe5c9d67868b9fe1f368d24a (diff)
Add support for gzip compression
-rwxr-xr-xtitle.bash11
1 files changed, 9 insertions, 2 deletions
diff --git a/title.bash b/title.bash
index 9bed0c5..7a44ca3 100755
--- a/title.bash
+++ b/title.bash
@@ -12,6 +12,7 @@
# v0.8 : strip newlines and leading whitespace from "broken" titles
: update user agent string
# v0.8.1: change name in version string to "blatitle"
+# v0.9 : add support for gzip compression
OPTS='--location --insecure --silent --max-filesize 1048576 --max-time 10 -A "Mozilla/5.0 (X11; Linux x86_64; rv:36.0) Gecko/20100101 Firefox/36.0"'
@@ -22,7 +23,13 @@ then
echo "Usage: '!title <url>' where <url> is an http:// or https:// URL"
elif [ "$url" == "-v" ] || [ "$url" == "--version" ]
then
- echo "blatitle version 0.8.1"
+ echo "blatitle version 0.9"
else
- curl $OPTS "$url" | sed -n -e 'H;${x;s!.*<head[^>]*>\(.*\)</head>.*!\1!I;tnext};b;:next;s!.*<title>\(.*\)</title>.*!\1!pI' | sed ':a;N;$!ba;s/\n//g' | sed -e 's/^[ \t]*//'
+ curl -I -H "Accept-Encoding: gzip" $OPTS "$url" | grep -q "Content-Encoding: gzip"
+ if [ "$?" == 0 ]
+ then
+ OPTS+=' -H "Accept-Encoding: gzip"'
+ GZIP="| gunzip"
+ fi
+ eval curl $OPTS "$url" $GZIP | sed -n -e 'H;${x;s!.*<head[^>]*>\(.*\)</head>.*!\1!I;tnext};b;:next;s!.*<title>\(.*\)</title>.*!\1!pI' | sed ':a;N;$!ba;s/\n//g' | sed -e 's/^[ \t]*//'
fi