-
Notifications
You must be signed in to change notification settings - Fork 1
/
flickrGrabImage
executable file
·26 lines (26 loc) · 2.2 KB
/
flickrGrabImage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
#Grabs a single photo
#usage: ./flickrGrabImage username photoid api_key
USER="$1"
ID="$2"
#API_KEY=$3
API_KEY=`curl -s http://www.flickr.com/services/api/explore/?method=flickr.photos.licenses.getInfo|grep -o "api_key\"\:\"[0-9a-z]*\""|tr "\"" " "|awk '{print $NF}'`
echo "We're processing $ID"
wget -q -O $USER"-"$ID.html http://www.flickr.com/photos/$USER/$ID/
dataElement=`cat $USER"-"$ID.html|grep "Y.photo"|head -n1|tail -c +10|head -c -2`
imageUrl=`cat $USER"-"$ID.html|grep -oE "http://farm(.).static.flickr.com/.*/.*_o.jpg"|tail -n1`
if [ -z $imageUrl ]; then
imageUrl=`cat $USER"-"$ID.html|grep -oE "http://farm(.).static.flickr.com/.*/.*_b.jpg"|tail -n1`
fi
if [ -z $imageUrl ]; then
imageUrl=`cat $USER"-"$ID.html|grep -oE "http://farm(.).static.flickr.com/.*/.*_z.jpg"|tail -n1`
fi
echo "imageUrl: $imageUrl"
date_taken=`echo $dataElement|grep -oE "....-..-.. ..:..:.."|tr " " "_"`
curl -s "http://api.flickr.com/services/rest/?nojsoncallback=1&method=flickr.photos.getInfo&api_key=$API_KEY&photo_id=$ID&format=json"|ruby -e 'require "json";require "yaml"; puts YAML.dump(JSON.parse($stdin.gets))'>$USER"-"$ID"_"$date_taken.info.yaml
curl -s "http://api.flickr.com/services/rest/?nojsoncallback=1&method=flickr.photos.comments.getList&api_key=$API_KEY&photo_id=$ID&format=json"|ruby -e 'require "json";require "yaml"; puts YAML.dump(JSON.parse($stdin.gets))'>$USER"-"$ID"_"$date_taken.comments.yaml
curl -s "http://api.flickr.com/services/rest/?nojsoncallback=1&method=flickr.tags.getListPhoto&api_key=$API_KEY&photo_id=$ID&format=json"|ruby -e 'require "json";require "yaml"; puts YAML.dump(JSON.parse($stdin.gets))'>$USER"-"$ID"_"$date_taken.tags.yaml
curl -s "http://api.flickr.com/services/rest/?nojsoncallback=1&method=flickr.photos.people.getList&api_key=$API_KEY&photo_id=$ID&format=json"|ruby -e 'require "json";require "yaml"; puts YAML.dump(JSON.parse($stdin.gets))'>$USER"-"$ID"_"$date_taken.people.yaml
curl -s "http://api.flickr.com/services/rest/?nojsoncallback=1&method=flickr.photos.getExif&api_key=$API_KEY&photo_id=$ID&format=json"|ruby -e 'require "json";require "yaml"; puts YAML.dump(JSON.parse($stdin.gets))'>$USER"-"$ID"_"$date_taken.exif.yaml
wget -O "$USER"-"$ID"_"$date_taken.jpg" "$imageUrl"
cd ..