Manually copying pictures for local copy feature

Hi All,

I have been abroad for a while and recently returned. Switched back on my NAS and copied all new pictures to it (±200gb). Took several hours and now I am wondering if there is any way to copy/structure my original local files so that I do not need to spend several more hours to let darktable make a local copy of what is already there.

I was thinking that I might be able to write a small script to copy and rename the pictures so that darktable would consider them local copies. From the docs I understand where the copies are made and it mentions that is uses a md5 hash of the path. But if i do an “echo ‘path/to/file.cr2’ | md5sum” (with or without -n flag for echo) I get a different hash than the one in the file darktable created. Possibly something to do with the fact that the NAS is mounted over NFS?

Has anyone played around with something similar or happens to know how darktable calculates the hash?

Never mind. Seems I made a mistake. For who ever ends up looking for the same:

“echo -n /mnt/2019/Lac Kivu/IMG_6405.CR2 | md5sum” results in
“851067991956d03a26273103d92f5250”
Darktable local copy name “img-851067991956d03a26273103d92f5250.CR2”

So seems feasible.

Script, use at own risk:

#! /usr/bin/python3

import os
import shutil
import hashlib

""" Note that the directory hierarchies for local and remote image collections under the below paths must be the same."""
picture_path = "/home/frank/Pictures/2020"  # Directory to start scanning for local images
remote_base_path = "/mnt/2020"  # Directory where remote library images live
darktable_cache_path = "/home/frank/.cache/darktable"
picture_extension = ".CR2"

for (p,d,f) in os.walk(picture_path):
    for filename in f:
        if filename.endswith(picture_extension):  # Filter out non image files
            r = os.path.relpath(p,  picture_path)  # relative path of the current scanning directory
            hash_path = os.path.join(remote_base_path, r,  filename)  # Calculated path of remote dir to use for hash
            md5 = hashlib.md5(hash_path.encode('utf-8')).hexdigest()  # MD5 hash value of remote path
            local_copy_name = f'img-{md5}{picture_extension}'  # Filename as darktable expects it to be
            #  Add your own logic to copy
            src = os.path.join(p,  filename)
            dst = os.path.join(darktable_cache_path, local_copy_name)
            print(f"Copying from {src}")
            print(f"Copying to {dst}")
            #shutil.copyfile(src, dst)