Skip to content

Instantly share code, notes, and snippets.

@rayslava
Created October 5, 2015 13:54
Show Gist options
  • Save rayslava/628e6ce27a378541c00d to your computer and use it in GitHub Desktop.
Save rayslava/628e6ce27a378541c00d to your computer and use it in GitHub Desktop.
View image by link
function instagram {
local image_url=`curl -s -k -L --socks5 'localhost:9050' "$1" | grep 'og:image' | sed -e 's/.*content="//;s/".*//'`
echo $image_url
curl -s -k --socks5 'localhost:9050' "$image_url" | feh -
}
function twitter {
local image_url=`curl -s -k -L "$1" | grep '"og:image"' | sed -e 's/.*content="//;s/".*//'`
echo $image_url
curl -s -k --socks5 'localhost:9050' "$image_url" | feh -
}
function img {
# Get content type
local content_type=$(curl -m 3 -L -s -D - "$1" -o /dev/null | grep -i "content-type:" | sed -e 's/.*:[[:space:]]\+\([[:alnum:]\/]\)/\1/');
if ( [[ ${content_type} == "" ]] || [[ $? != 0 ]] ) {
content_type=$(curl -m 20 --socks5 'localhost:9050' -L -s -D - "$1" -o /dev/null \
| grep -i "content-type:" | sed -e 's/.*:[[:space:]]\+\([[:alnum:]\/]\)/\1/');
}
if ( [[ x${content_type} =~ x"image/.*" ]] ) {
curl -s -L "$1" | feh -
return 0;
};
# If it's not image
if ( [[ x$content_type =~ x"text/html.*" ]] ) {
# Parse page
if ( [[ $1 =~ ".*instagram.*" ]] ) {
instagram $1
return 0;
};
if ( [[ $1 =~ ".*twitter.*" ]] ) {
twitter $1
return 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment