-
-
Save cdfmr/6606109 to your computer and use it in GitHub Desktop.
#!/bin/sh | |
delay=0 | |
timeout=10 | |
retry=2 | |
usage() | |
{ | |
echo "Usage: `basename $0` userid" | |
exit 1 | |
} | |
[ $# -ne 1 ] && usage | |
global_index=1 | |
page=1 | |
while true ; do | |
echo "[INFO] Processing page $page" | |
wget -q -O .tmp http://www.panoramio.com/user/$1?photo_page=$page | |
if [ $? -ne 0 ] ; then | |
echo "[WARNING] Can not get content of page $page" | |
break | |
fi | |
if [ -z "$total" ] ; then | |
total=`grep -iE '<a href="\/user\/.*\/stats' .tmp | head -n 1 | sed 's/.*stats">//;s/<.*//'` | |
fi | |
imgs=`grep -ioE '<a href="\/photo\/[0-9]*"$' .tmp | sed 's/.*\///;s/"//'` | |
alts=`grep -ioE '^ >..*<\/a>$' .tmp | sed 's/<.*//;s/.*>//'` | |
index=1 | |
for img in $imgs ; do | |
url=http://static.panoramio.com/photos/original/$img.jpg | |
alt=`{ for alt in $alts ; do echo $alt ; done } | head -n $index | tail -n 1` | |
file=`echo $global_index | awk '{printf "%03d", $0}'`_$alt.jpg | |
index=$((index+1)) | |
global_index=$((global_index+1)) | |
if [ -f $file ] ; then | |
continue | |
fi | |
echo "[INFO] Downloading $url" | |
wget -q --tries=$retry --timeout=$timeout -O "$file" "$url" | |
if [ $? -ne 0 ] ; then | |
rm -f "$file" | |
echo "[WARNING] Failed to download $url to $file" | |
fi | |
sleep $delay | |
done | |
if [ $global_index -gt $total ] ; then | |
break | |
fi | |
page=$((page+1)) | |
done | |
rm -f .tmp | |
exit 0 |
Totally works for me! Thank you so much for that solution!!!!
I'd love to fix the filename to add a time and date but also the full alt as a file name.
My alts and filenames are mixing up.
Back story, I'm trying to save someone's history after his funeral and this is my first example of history disappearing. (Will Flickr disappear also at some point?!)
Could the filename be something like 2016-01-01T00:00:00Z-went_into_the_wild.jpg? Converting the alt text into file friendly would be amazing and getting the full alt into the filename.
How can I help?
Personally, this was an improvement to the filenames immediately.
//alts=grep -ioE '^ >..*<\/a>$' .tmp | sed 's/<.*//;s/.*>//'
alts=grep -ioE '^ >..*<\/a>$' .tmp | sed -e 's/[^A-Za-z0-9._-]/_/g'
Still plenty of room for improvement.
Nick
Thanks.. Very useful right now that they have disabled the API.
I'm using this on Win 10 Ubuntu Bash, and everything works.
@elyobelyob I tried this line
alts=grep -ioE '^ >..*<\/a>$' .tmp | sed -e 's/[^A-Za-z0-9._-]/_/g'
But instead of the original naming, it names files just with numbers and no text
Hi, this script seems great but it keeps counting pages but never starts downloading, could you please tell me why it does it?
Many thanks!