Created
September 1, 2013 20:20
-
-
Save bhollis/6407054 to your computer and use it in GitHub Desktop.
I hate how iMovie wants to move your files into its own directory structure, which is slow and wasteful. This script creates iMovie events as hardlinks to my own directory structure. Hardlinks are requires so that iMovie will let you mark favorites/rejected.
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
#!/usr/bin/env ruby | |
# Usage: imovie-event SRC [EVENT NAME] | |
# | |
# Creates an iMovie event for all the .MOV files at "SRC". | |
# | |
# For me, the iMovie Events folder and some other rules are hardcoded. | |
require 'fileutils' | |
IMOVIE_EVENTS = "/Volumes/Photo & Backup/iMovie Events.localized/" | |
src = ARGV.shift | |
event_name = ARGV.shift | |
# If it's a GoPro conversion folder, use the parent folder event_name | |
unless event_name | |
folder = File.basename(src) | |
if folder =~ /Converted/i # My convention for converted GoPro files | |
folder = File.basename(File.dirname(src)) | |
orig_dest = File.join(IMOVIE_EVENTS, folder) | |
if File.exist?(orig_dest) && !File.symlink?(orig_dest) | |
folder << " GoPro" | |
end | |
end | |
event_name = folder | |
end | |
dest = File.join(IMOVIE_EVENTS, event_name) | |
# I tried using symlinks, but iMovie won't let you mark | |
# favorites/rejected if you do that, so replace with hardlinks | |
if File.symlink? dest | |
File.delete dest | |
end | |
# Only look for MOV files - GoPro .MP4s need conversion | |
Dir.glob(File.join(src, "*.{mov,MOV}")) do |f| | |
next if File.directory?(f) | |
FileUtils.mkdir_p dest | |
dest_file = File.join(dest, File.basename(f)) | |
FileUtils.ln f, dest_file, verbose: true unless File.exist?(dest_file) | |
# Move over any previously-computed iMovie thumbnails from my | |
# symlinks experiment to save time. | |
thumbs = File.join(File.dirname(f), 'iMovie Thumbnails') | |
if File.exists? thumbs | |
FileUtils.mv thumbs, dest, verbose: true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment