Skip to content

Instantly share code, notes, and snippets.

@stungeye
Last active November 25, 2022 10:15
Show Gist options
  • Save stungeye/e0897489fca28863c650fc33a95a11fb to your computer and use it in GitHub Desktop.
Save stungeye/e0897489fca28863c650fc33a95a11fb to your computer and use it in GitHub Desktop.
Export Flickr Photos To Google Photos Using Exiftool CLI

Backing Up All Photos from Flickr to Google Photos

  • Request an archive of your photos and metadata (json) from the "Your Flickr Data" section of your Flickr user account page.

  • Extract all provided zip files to a single folder with the JSON files unzip to a json subfolder.

  • Install exiftool, a command-line application for reading, writing and editing meta information in a wide variety of files..

  • Sort your Flickr photos into yearly folders by EXIF timestamp and set file-system timestamps from the command line:

    exiftool "-FileName<ModifyDate" "-FileName<CreateDate" -d "processed/%Y/%b_%d_%%f.%%e" "-FileModifyDate<ModifyDate" "-FileModifyDate<CreateDate#" *.jpg

  • Some of my files were incorrectly dated after this. Fix with exiftool. For example, if the correct date should have been 22 Aug 2004. Fixed by:

    • Renamed incorrectly dated files to Aug_22*.jpg.
    • Moved these files back to the photo export root folder.
    • touch -c -t 200408220500 Aug_22*.jpg
    • exiftool -v "-FileModifyDate>AllDates" Aug_22*.jpg
    • exiftool "-FileName<ModifyDate" "-FileName<CreateDate" -d "processed/%Y/%b_%d_%%f.%%e" "-FileModifyDate<ModifyDate" "-FileModifyDate<CreateDate#" Aug_22*.jpg

In my case 500+ files did not contain correct EXIF timestamps so weren't sorted into the processed folder. These files were fixed by pulling the imported date from the Flickr JSON files that came with the data export. The attached Ruby script performed the fix. The script assumes that the Flickr JSON files are in a json sub-folder. The script also moved all photos that came to Flickr from Instagram to a separate folder. After running this script the top exiftool command from above was run again to move the fixed files into the correct folders.

The final step was to upload all the photos to Google Photos.

EXIFTOOL Resources

require 'json'
all_jpg_files = Dir.glob "*.jpg"
all_jpg_files.each do |jpg_filename|
puts "Found: #{jpg_filename}"
jpg_number = jpg_filename.match(/(\d+)_o/)[1]
puts "Number: #{jpg_number}"
json_file = File.read("./json/photo_#{jpg_number}.json")
json_data = JSON.parse(json_file)
imported_date = json_data["date_imported"]
imported_stamp = imported_date.scan(/\d+/)[0...-1].join
puts "Imported date: #{imported_date}"
puts "Stamping with: #{imported_stamp}"
system("touch -c -t #{imported_stamp} #{jpg_filename}")
system("exiftool -overwrite_original -v \"-FileModifyDate>AllDates\" #{jpg_filename}")
# Instagram photos will be imported separately.
if json_data['tags'].any? { |meta| meta['tag'].include?('instagram') }
system("mv #{jpg_filename} ./instagram")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment