#!/usr/bin/env ruby | |
# Usage: dedup-imovie-library LIBRARY ORIGINALS | |
# | |
# Goes through an iMovie 10 library and replaces all the "Original Media" with | |
# hardlinks to the actual original media, in order to conserve disk space. Note | |
# that because they're hardlinks, if you copy the originals and the iMovie event | |
# to a new disk, you'll end up with two copies again and will have to re-run this | |
# tool. | |
# | |
# This assumes you've already imported the files into iMovie and waited for them | |
# all to be copied. | |
# | |
# This also assumes movie files in LIBRARY have unique matches in ORIGINALS with | |
# the same filename! | |
require 'fileutils' | |
library = ARGV.shift | |
originals = ARGV.shift | |
fail "Library #{library} does not exist" unless library && File.exist?(library) | |
fail "Originals folder #{originals} does not exist" unless originals && File.exist?(originals) | |
# For each original file in the imovie library | |
Dir.glob(File.join(library, '**', 'Original Media', '*')) do |library_file| | |
next unless File.file? library_file | |
# Skip it if we've already replaced it with a hardlink | |
next if File.stat(library_file).nlink > 1 | |
original = Dir.glob(File.join(originals, '**', File.basename(library_file))).first | |
next unless original | |
puts "Linking #{library_file} => #{original}" | |
FileUtils.rm_f library_file, verbose: true | |
FileUtils.ln original, library_file, verbose: true | |
end |
This comment has been minimized.
This comment has been minimized.
You have to run |
This comment has been minimized.
This comment has been minimized.
Hi, I had the same problem above but fixed it by using I have a folder with all my GoPro files imported by GoPro Studio Importer, this puts them into subfolders within the GoPro folder. My question is, can I use this code to scan through all the subfolders? If not is there an easy change to the code to allow this. Sorry, I don't know Ruby at all. Thanks, Stu. |
This comment has been minimized.
This comment has been minimized.
Thanks for the code, I'm very happy to use it. I made 3 modifications:
|
This comment has been minimized.
This comment has been minimized.
Great script! I'm a fairly new Mac user and was blown away when I discovered that iMovie copies files into its library. I'm currently on a one year trip and hard disk space is at an absolute premium. With tons of GoPro footage sitting duplicated on my drive, I was not a happy camper. I wanted to add a safety feature to the script though. You can check it out here: https://gist.github.com/aardvarkk/9206a4eb5d5e78e5dbc0#file-dedup-imovie-library All I did was add a check that the file contents are the same. This way, you won't accidentally delete/link a file that happens to have the same name as another. It will slow the entire process down, obviously, so maybe you'd want to add a switch or something... but for me I'd rather it be as safe as possible and I don't mind the hit to the speed. Great work on this script. A tip of the hat to you, and a wag of the finger to Apple for wasting half of my hard disk with duplicated videos! |
This comment has been minimized.
This comment has been minimized.
Thanks for this! I noticed that iMovie saves its files as https://gist.github.com/swrobel/1fa71ea870a4d0feac2a6ca93b5e36eb |
This comment has been minimized.
This comment has been minimized.
I am running MacOS 10.14.4 and I am getting the following error: I am thinking it is because I do not have 'fileutils' installed. Can someone offer some help on how on how to install 'fileutils' or in the alternative advise if I am off-base and the problem is something else? Thanks. CG |
This comment has been minimized.
This comment has been minimized.
I adapted it to Python here. I also used symlinks, assumed the iMovie library and the originals folder is organized by event name, and included projects to skip in case you are working on them. |
This comment has been minimized.
This comment has been minimized.
@miguelmorin do you encounter these issues described in his original post? He discuss the use of hard link versus symbolic link.
https://benhollis.net/blog/2014/06/28/hard-linking-videos-to-save-space-in-your-imovie-library/ |
This comment has been minimized.
This comment has been minimized.
@dingzeyuli No, I haven't, although to be sure I run the deduplication only after I am done with a project to save space. Maybe just make a backup and try it? |
This comment has been minimized.
This comment has been minimized.
Great script thanks. For me the problem was that i dont have it the original files in one place. so i should to copy firstable the file by adding these line and voila it works great! Thank you very much! |
This comment has been minimized.
This comment has been minimized.
Hi guys, |
This comment has been minimized.
This comment has been minimized.
Doesn't Time Machine back up hard links as separate files? https://superuser.com/a/836655/93066 This would be a no-go in that case, especially if symlinks work just as well. |
This comment has been minimized.
This comment has been minimized.
I can not give definitive answers, but approximated answers at least:
|
This comment has been minimized.
This comment has been minimized.
What about an existing tool like rdfind? e.g.
(remove It will also let you use hard links if you're so inclined ;) |
This comment has been minimized.
This is a great looking concept, but I am struggling to get it to work for me.
Based on your post about this script:
http://benhollis.net/blog/2014/06/28/hard-linking-videos-to-save-space-in-your-imovie-library/
I got the impression the script should be saved to the ~/Movies directory. I saved the script as "dedup-imovie-library" with no file extension using TextEdit.
When I run the terminal command however, I get the following message:
-bash: dedup-imovie-library: command not found
Can you please help me to understand where I'm going wrong here?
Thanks so much for offering a great script to fix yet another one of Apple's poorly designed architectures.