Skip to content

Instantly share code, notes, and snippets.

@cdfmr
Last active January 25, 2018 10:43
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cdfmr/6606109 to your computer and use it in GitHub Desktop.
Save cdfmr/6606109 to your computer and use it in GitHub Desktop.
Download Panoramio pictures via user id
#!/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
@ptotal
Copy link

ptotal commented Jan 3, 2016

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!

@pcace
Copy link

pcace commented May 2, 2017

Totally works for me! Thank you so much for that solution!!!!

@elyobelyob
Copy link

elyobelyob commented May 31, 2017

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?

@elyobelyob
Copy link

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

@rudolphos
Copy link

rudolphos commented Jun 12, 2017

Thanks.. Very useful right now that they have disabled the API.
I'm using this on Win 10 Ubuntu Bash, and everything works.

@rudolphos
Copy link

The problem is though, the script can't properly name the files
image

image

@rudolphos
Copy link

@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
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment