-
-
Save stecman/6dfd9563c86c993c8351d0e3d223101d to your computer and use it in GitHub Desktop.
Hacked together script to automate organising film scans
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
import glob | |
import os | |
import subprocess | |
INPUT_DIR = '/Volumes/EOS_DIGITAL/DCIM/100CANON' | |
OUTPUT_DIR = '/Volumes/EOS_DIGITAL/DCIM/Photos/' | |
def collect_images(firstIndex, lastIndex, dir): | |
""" Collect files between the passed indexes (inclusive) """ | |
found = [] | |
for index in range(firstIndex, lastIndex + 1): | |
name = '_MG_%s.CR2' % str(index).zfill(4) | |
path = os.path.join(INPUT_DIR, name) | |
if os.path.isfile(path): | |
found.append(name) | |
return found | |
folder_names = {} | |
processed_count = 0 | |
def process(firstIndex, lastIndex, year, name, notes=None): | |
global folder_names, processed_count | |
processed_count += lastIndex - firstIndex | |
if name in folder_names: | |
raise Exception('The folder name \'%s\' is already used. Aborting' % name) | |
folder_names[name] = True | |
files = collect_images(firstIndex, lastIndex, INPUT_DIR) | |
if len(files) == 0: | |
print('Nothing found between index %d and %d' % (firstIndex, lastIndex)) | |
print(name) | |
outDir = os.path.join(OUTPUT_DIR, str(year), name) | |
notesFile = os.path.join(outDir, 'notes.md') | |
# Process if files are found or the directory already exists (notes update) | |
if len(files) or os.path.exists(outDir): | |
subprocess.check_call(['mkdir', '-p', outDir]) | |
if notes is not None: | |
with open(notesFile, 'w') as fd: | |
fd.write(notes) | |
for imageName in files: | |
src = os.path.join(INPUT_DIR, imageName) | |
dest = os.path.join(outDir, imageName) | |
print('Moving %s to %s' % (src, dest)) | |
os.rename(src, dest) | |
process( | |
8367, 8387, | |
year='unknown', | |
name='Roll 1 (ID 2478)', | |
notes=''' | |
Kodak GC 800 | |
Taken on a disposable camera | |
Rowing | |
''' | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment