Created
April 28, 2020 15:03
-
-
Save rubenarakelyan/c4772a50f8de86278ef3bb1ae979edd1 to your computer and use it in GitHub Desktop.
Move Lightroom CC original files into album-named folders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "sqlite3" | |
require "fileutils" | |
db = SQLite3::Database.new("database/catalog.db") | |
# Get list of albums | |
albums = {} | |
db.execute("select * from albums") do |album| | |
albums[album[1]] = album[3] | |
end | |
# Get list of assets | |
assets = {} | |
db.execute("select * from assets") do |asset| | |
date = asset[4].split("T")[0] | |
year = date.split("-")[0] | |
assets[asset[7]] = { id: asset[7], name: asset[5], old_path: "#{year}/#{date}/#{asset[5]}", new_path: nil } | |
end | |
# Get links between albums and assets | |
db.execute("select * from album_asset_v2") do |album_asset| | |
assets[album_asset[1]][:new_path] = "#{albums[album_asset[2]]}/#{assets[album_asset[1]][:name]}" | |
end | |
# Move all assets to the new path and print any that don't have an associated album | |
assets.each_pair do |_, asset| | |
puts "Asset at #{asset[:old_path]} does not have an album and will not be moved" and next if asset[:new_path].nil? | |
FileUtils.mv(asset[:old_path], asset[:new_path]) rescue Errno::ENOENT | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment