From f2fb938c798f0493248049204b32b87afd7c178c Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Sat, 2 May 2015 18:45:31 +0100 Subject: Add support for gzip compression --- title.bash | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'title.bash') 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 ' where 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!.*]*>\(.*\).*!\1!I;tnext};b;:next;s!.*\(.*\).*!\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!.*]*>\(.*\).*!\1!I;tnext};b;:next;s!.*\(.*\).*!\1!pI' | sed ':a;N;$!ba;s/\n//g' | sed -e 's/^[ \t]*//' fi -- cgit v1.2.3