#!/bin/bash # grickr # Todd Slater # Revised 30 May 2007 # Finds flickr images in a google reader feed and downloads the original image # Requires: grep, curl, wget # set up variables # where to store all pics and working files baseDir="$HOME/flickr" # cookie file - the 7dayzq8m below is random, yours will differ cookies="$HOME/.mozilla/firefox/7dayzq8m.default/cookies.txt" # feed file feedfile=${baseDir}/starred # feed url (you could probably substitute any feed, though not tested) feedurl="http://www.google.com/reader/atom/user/your_user_id/state/com.google/starred" # no need to edit beyond this point # store all pic url's masterlist=${baseDir}/master # all pictures that exist, all sessions goodlist=${baseDir}/goodlist # pictures that exist, current session badlist=${baseDir}/badlist # pictures that are unavailable, all sessions cd $baseDir # fetch feed curl -b "$cookies" -o "$feedfile" "$feedurl" # find all flickr pics and rewrite url to get original size # then, test if pic is available and write to appropriate list for file in `grep -o -E "http://farm1.static.flickr.com/[0-9]{2,}/[[:alnum:]]{9}_[[:alnum:]]{10}_[mo].jpg" "$feedfile"|sed s/_m/_o/g` do curl -I "$file" | grep "HTTP/1.0 200 OK" && echo "$file" >> $goodlist || echo "$file" >> $badlist.tmp done # for unavailable pics, let's try to find a big version # and write to appropriate list, but not if we've already # downloaded it due to multiple links/enclosures in the feed while read line do bigVersion=`echo "$line" | sed s/_o.jpg/_b.jpg/` dupepart=`echo "$line" | cut -b 36-44` if [ ! `grep "$dupepart" $goodlist` ] ; then curl -I "$bigVersion" | grep "HTTP/1.0 200 OK" && echo "$bigVersion" >> $goodlist fi done<$badlist.tmp # ok, got list of available pics, let's fetch them # using wget for its noclobber goodness wget -nc -i $goodlist # combine recent list and master list, check for dupes cat $goodlist >> $masterlist sort $masterlist | uniq > $masterlist.$$ mv $masterlist.$$ $masterlist # combine recent bad with master bad list, check for dupes cat $badlist.tmp >> $badlist sort $badlist | uniq > $badlist.$$ mv $badlist.$$ $badlist # clean up temp files rm -f $feedfile rm -f $goodlist rm -f $badlist.tmp