Skip to content

Instantly share code, notes, and snippets.

@stecman
Last active February 20, 2020 16:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stecman/6dfd9563c86c993c8351d0e3d223101d to your computer and use it in GitHub Desktop.
Save stecman/6dfd9563c86c993c8351d0e3d223101d to your computer and use it in GitHub Desktop.
Hacked together script to automate organising film scans
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