Skip to content

Instantly share code, notes, and snippets.

@erinaceous
Created November 21, 2013 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erinaceous/7591232 to your computer and use it in GitHub Desktop.
Save erinaceous/7591232 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Based on
# http://blog.jamiek.it/2010/06/linux-flickr-downloader-script.html
# Searches flickr for all publicly available photos whos title/description/tags
# match the string passed to it.
# Downloads original-size images where possible, medium-size images otherwise.
# (Downloads into your current working directory)
# To get your API Key and Secret create a Flickr App at:
# http://www.flickr.com/services/apps/create/apply/
APIKey=''
Secret=''
# Note that *all* parameters in URI must be in alphabetical order, so this may
# not work
# for your method/parameters as is
Method='flickr.photos.search'
Search=$(echo $1 | sed 's/ /%20/g')
Params="content_type=1&extra=original_format,url_o&media=photos&sort=relevance&text=$Search"
# Image size: _s small square, _t thumbnail, _m small, none medium, _b large, _o
# original
Size="_o"
IFS='\
'
Page=1
Pages=1
while [ $Page -le $Pages ]
do
URI="api_key=$APIKey&method=$Method&page=$Page&per_page=2&$Params"
echo "http://api.flickr.com/services/rest/?$URI"
for f in $(curl "http://api.flickr.com/services/rest/?$URI")
do
echo $f
echo
TempPages=$(echo $f | awk '/<photos/ {print $3}')
if [ $TempPages ]
then
Pages=$(echo $TempPages | sed '~s/\(pages=\|"\)//g')
fi
INFO_URL=$(echo $f | awk '/id=/ {print "http://api.flickr.com/services/rest/?api_key='$APIKey'&method=flickr.photos.getInfo&photo_"$2}' | tr -d '"')
ORIGINAL_SECRET=$(curl $INFO_URL | grep -P -o "originalsecret=\"\d+\"" | cut -d '"' -f 2 | tr -d '"')
URL=$(echo $f | awk '/id=/ {print "http://farm"$6".static.flickr.com/"$5"/"$2"_"$4}')
if [ $URL ]
then
URL=$(echo $URL | sed '~s/\(farm=\|server=\|secret=\|id=\|"\)//g')".jpg"
if [ $ORIGINAL_SECRET ]
then
URL=$(echo $URL | cut -d '_' -f1)"_"$ORIGINAL_SECRET"_o.jpg"
fi
wget $URL
fi
done
Page=$(($Page + 1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment