Skip to content

Bash script to automatically download photos given photo query ID (User ID not required)

Notifications You must be signed in to change notification settings

ceciliavision/flickr_get_img

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flickr_get_img

Bash script to automatically download photos given Flickr photo query ID (User ID not required). Note that the current version of Flickr API allows users to extract urls of different sizes of photos while doing query, so you probably don't need this script if you want to do query from scratch. This script is used when you already have, while only have the photo IDs, and would like to download the original photos.

Originally written to extract Flickr photos in dataset Dubrovnik6K (http://www.cs.cornell.edu/projects/p2f/), a subset of SFM data.

Data from the original webiste doesn't include the images but only Flickr user ID and photo ID. The script follows the instruction of the Dubrovnik6K dataset usage (available in the link above), and automatically downloads all images with known focal length.

Usage

The only argument is the list file. An example list file is included in this directory. It's also a shortened version of the original list file of the original Dubrovnik6K dataset. Simply type in the shell:

      bash extract_img.sh list.db.txt

Brief explanation using wget , grep and sed to search in the webpage source

The main idea is to search for the target photo link in the source. In our case, we search for the string "Download the Large 1024 size of this photo", which is the next line to the photo link to be downloaded. The query string could be replaced by any other string for your purpose. The following grep command returns us the line of string right before the query string:

      grep -B 1 "Download the Large 1024 size of this photo"

Then I get: <a href="https://c1.staticflickr.com/3/xxx/xxxxxx.jpg"> and I want to extract only the photo link from this string. Basically I want to get rid of strings in front of =" and after ">

'sed' is a stream editor. s/.*="// searches for everything before =" and replace it with //, empty string. 's/">//' searches for "> and replace it with empty string. Then what's remained would be the image link: https://c1.staticflickr.com/3/xxx/xxxxxx.jpg

      sed -e 's/.*="//' -e 's/">//'`

Then we could use wget -O ./output_dir image_link_get_from_above to save the image to a desired directory (and file name).

About

Bash script to automatically download photos given photo query ID (User ID not required)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages