Esempio n. 1
0
def rename(dry_run: bool, any_name: bool = False) -> None:
    print("# PROC: RENAME")
    if not is_raw_folder():
        msg_raw_folder_flag_not_found()
    else:
        # rename CANON files, template: IMG_NNNN.JPG
        # rename OLYMPUS PEN files, template: PNNNNNNN.JPG , PCNNNNNN.JPG , PANNNNNN.JPG
        # rename PENTAX, template IMGPNNNN.JPG
        # rename OTHER, template DSCNNNNN.JPG
        # rename OTHER, template DSCFNNNN.JPG
        # rename OTHER, template DSC_NNNN.JPG
        jpg_files: List[str] = find_jpg_files('..')
        for jpg_file in jpg_files:
            if any_name \
                    or re.match(r'IMG_\d\d\d\d\.JPG$', os.path.basename(jpg_file)) \
                    or re.match(r'P\d\d\d\d\d\d\d\.JPG$', os.path.basename(jpg_file)) \
                    or re.match(r'PC\d\d\d\d\d\d\.JPG$', os.path.basename(jpg_file)) \
                    or re.match(r'PA\d\d\d\d\d\d\.JPG$', os.path.basename(jpg_file)) \
                    or re.match(r'PB\d\d\d\d\d\d\.JPG$', os.path.basename(jpg_file)) \
                    or re.match(r'DSC\d\d\d\d\d\.JPG$', os.path.basename(jpg_file)) \
                    or re.match(r'DSCN\d\d\d\d\.JPG$', os.path.basename(jpg_file)) \
                    or re.match(r'DSCF\d\d\d\d\.JPG$', os.path.basename(jpg_file)) \
                    or re.match(r'DSC_\d\d\d\d\.JPG$', os.path.basename(jpg_file)) \
                    or re.match(r'IMGP\d\d\d\d\.JPG$', os.path.basename(jpg_file)):
                raw_file = find_raw_for_jpg(jpg_file)
                xmp_file = find_xmp_for_jpg(jpg_file)
                prefix = cmd_get_createdate(jpg_file)
                if not prefix:
                    print("# (!) '%s' problems..." % (jpg_file, ))
                    continue
                if jpg_file:
                    new_jpg_file = os.path.dirname(
                        jpg_file) + "/" + prefix + "_" + os.path.basename(
                            jpg_file)
                    if not dry_run:
                        os.rename(jpg_file, new_jpg_file)
                    print("# (>) '%s' -> '%s'" % (
                        jpg_file,
                        new_jpg_file,
                    ))
                if raw_file:
                    new_raw_file = os.path.dirname(
                        raw_file) + "/" + prefix + "_" + os.path.basename(
                            raw_file)
                    if not dry_run:
                        os.rename(raw_file, new_raw_file)
                    print("# (>) '%s' -> '%s'" % (
                        raw_file,
                        new_raw_file,
                    ))
                if xmp_file:
                    new_xmp_file = os.path.dirname(
                        xmp_file) + "/" + prefix + "_" + os.path.basename(
                            xmp_file)
                    if not dry_run:
                        os.rename(xmp_file, new_xmp_file)
                    print("# (>) '%s' -> '%s'" % (
                        xmp_file,
                        new_xmp_file,
                    ))
Esempio n. 2
0
def build_notags(input_xmp_files: List[str] = [],
                 acceptable_rating: List[int] = [5]):
    print("# PROC: BUILD WITH TAGS")
    if not is_raw_folder():
        msg_raw_folder_flag_not_found()
    else:
        output_dir = "processed-with-tags-%dx%d" % (
            MAX_WIDTH,
            MAX_HEIGHT,
        )
        if not os.path.exists(output_dir):
            os.makedirs(output_dir, exist_ok=True)

        if input_xmp_files:
            xmp_files = input_xmp_files
        else:
            xmp_files = find_xmp_files('.')

        for xmp_file in xmp_files:
            raw_file = find_raw_for_xmp(xmp_file, ".")
            jpg_file = find_jpg_for_xmp(xmp_file, "..")
            if raw_file is None or jpg_file is None:
                print("# (!) build '%s' failed, jpg or raw file not found" %
                      (xmp_file))
                continue
            dst_jpg_file = "./" + output_dir + "/" + os.path.basename(jpg_file)
            rating = cmd_get_rating(xmp_file)
            msg_file_rating(xmp_file, rating)
            if rating not in acceptable_rating:
                continue
            code, _ = run_cmd(executable_darktable_cli(), [
                raw_file, xmp_file,
                dst_jpg_file.lower(), "--width",
                str(MAX_WIDTH), "--height",
                str(MAX_HEIGHT), "--core", "--conf",
                "plugins/imageio/format/jpeg/quality=%d" % (JPG_QUALITY, )
            ])
            if code != 0:
                continue
            os.rename(dst_jpg_file.lower(), dst_jpg_file)
            code, _ = run_cmd(executable_exiftool(),
                              ["-overwrite_original", "-all=", dst_jpg_file])
            if code != 0:
                continue
            # copy metadata from the original jpeg file
            # exiftool -overwrite_original -TagsFromFile ../${1%%.*}.${JPG_EXT}  "-all:all>all:all" ${DST_PATH}/${1%%.*}.${JPG_EXT}
            # exiftool -overwrite_original -TagsFromFile ../${1%%.*}.${JPG_EXT}
            #          -gps:all -model -make -lensmodel -iso -fnumber -exposuretime
            #          -apterture -focallength -datetimeoriginal -modifydate
            #          -creatdate ${DST_PATH}/${1%%.*}.${JPG_EXT}
            code, _ = run_cmd(executable_exiftool(), [
                "-overwrite_original", "-TagsFromFile", jpg_file, "-gps:all",
                "-model", "-make", "-lensmodel", "-iso", "-fnumber",
                "-exposuretime", "-apterture", "-focallength",
                "-datetimeoriginal", "-modifydate", "-creatdate", "-by-line",
                "-Artist", "-CopyrightNotice", "-Copyright", "-XMP-cc:License",
                dst_jpg_file
            ])
            if code != 0:
                continue
Esempio n. 3
0
def mark_raw_as_done() -> None:
    print("# PROC: MARK RAW FOLDER AS DONE")
    if not is_raw_folder():
        msg_raw_folder_flag_not_found()
    else:
        if not create_done_folder_flag():
            print("# (!) '%s' creation failed" % (const_done_folder_flag()))
            sys.exit(1)
        print("# (=) done!")
Esempio n. 4
0
def build_notags(input_xmp_files: List[str] = [], acceptable_rating: List[int] = [5]):
    print("# PROC: BUILD NOTAGS")
    if not is_raw_folder():
        msg_raw_folder_flag_not_found()
    else:
        output_dir = "processed-notags-%dx%d" % (MAX_WIDTH, MAX_HEIGHT,)
        if not os.path.exists(output_dir):
            os.makedirs(output_dir, exist_ok=True)
            
        if input_xmp_files:
            xmp_files = input_xmp_files
        else:
            xmp_files = find_xmp_files('.')

        for xmp_file in xmp_files:
            raw_file = find_raw_for_xmp(xmp_file, ".")
            jpg_file = find_jpg_for_xmp(xmp_file, "..")
            if raw_file is None or jpg_file is None:
                print("# (!) build '%s' failed, jpg or raw file not found" % (xmp_file))
                continue
            dst_jpg_file = "./" + output_dir + "/" + os.path.basename(jpg_file)
            rating = cmd_get_rating(xmp_file)
            msg_file_rating(xmp_file, rating)
            if rating not in acceptable_rating:
                continue
            code, _ = run_cmd(executable_darktable_cli(), [
                              raw_file,
                              xmp_file,
                              dst_jpg_file.lower(),
                              "--width",
                              str(MAX_WIDTH),
                              "--height",
                              str(MAX_HEIGHT),
                              "--core",
                              "--conf",
                              "plugins/imageio/format/jpeg/quality=%d" % (JPG_QUALITY,)])
            if code != 0:
                continue
            os.rename(dst_jpg_file.lower(), dst_jpg_file)
            code, _ = run_cmd(executable_exiftool(), [
                              "-overwrite_original",
                              "-all=",
                              dst_jpg_file])
            if code != 0:
                continue
Esempio n. 5
0
def move_to_trash(dry_run: bool, move_pick_labels: List[int] = [1]) -> None:
    print("# PROC: MOVE TO TRASH")
    if not is_raw_folder():
        msg_raw_folder_flag_not_found()
    else:
        root_path, sub_path = find_root_dir()
        trash_path = os.path.join(root_path, 'Trash', sub_path)
        if not root_path or not sub_path:
            print('# ERROR: NO ROOT PATH FOUND (".root")')
        if not os.path.exists(trash_path):
            if not dry_run:
                os.makedirs(trash_path, exist_ok=True)
        for jpg_file in find_jpg_files('..'):
            pick_label = cmd_get_picklabel(jpg_file)
            msg_file_pick_label(jpg_file, pick_label)
            if pick_label in move_pick_labels:
                new_jpg_file = os.path.join(trash_path, jpg_file)
                if not dry_run:
                    os.rename(jpg_file, new_jpg_file)
                print("# (>) '%s' -> '%s'" % (
                    jpg_file,
                    new_jpg_file,
                ))

                raw_file = find_raw_for_jpg(jpg_file, '.')
                if raw_file:
                    new_raw_file = os.path.join(trash_path, raw_file)
                    if not dry_run:
                        os.rename(raw_file, new_raw_file)
                    print("# (>) '%s' -> '%s'" % (
                        raw_file,
                        new_raw_file,
                    ))

                xmp_file = find_xmp_for_jpg(jpg_file, '.')
                if xmp_file:
                    new_xmp_file = os.path.join(trash_path, xmp_file)
                    if not dry_run:
                        os.rename(xmp_file, new_xmp_file)
                    print("# (>) '%s' -> '%s'" % (
                        xmp_file,
                        new_xmp_file,
                    ))
Esempio n. 6
0
def open_in_darktable(acceptable_pick_labels: List[int] = [2, 3]):
    print("# PROC: OPEN IN DARKTABLE")
    if not is_raw_folder():
        msg_raw_folder_flag_not_found()
    else:
        raw_files: List[str] = []
        for jpg_file in find_jpg_files('..'):
            pick_label = cmd_get_picklabel(jpg_file)
            msg_file_pick_label(jpg_file, pick_label)
            if pick_label in acceptable_pick_labels:
                raw_file = find_raw_for_jpg(jpg_file, '.')
                if raw_file is None:
                    print("# (!) '%s' does not have a RAW file" % (jpg_file, ))
                else:
                    raw_files.append(raw_file)
        if not raw_files:
            print("# (=) nothing to open")
        else:
            print("%s %s" % (executable_darktable(), ' '.join(raw_files)))
Esempio n. 7
0
def build_release(input_xmp_files: List[str] = [],
                  acceptable_rating: List[int] = [5]):
    print("# PROC: BUILD RELEASE")
    if not is_raw_folder():
        msg_raw_folder_flag_not_found()
    else:
        output_dir = "processed-release"
        if not os.path.exists(output_dir):
            os.makedirs(output_dir, exist_ok=True)

        if input_xmp_files:
            xmp_files = input_xmp_files
        else:
            xmp_files = find_xmp_files('.')

        for xmp_file in xmp_files:
            raw_file = find_raw_for_xmp(xmp_file, ".")
            jpg_file = find_jpg_for_xmp(xmp_file, "..")
            if raw_file is None or jpg_file is None:
                print("# (!) build '%s' failed, jpg or raw file not found" %
                      (xmp_file))
                continue
            dst_jpg_file = "./" + output_dir + "/" + os.path.basename(jpg_file)
            rating = cmd_get_rating(xmp_file)
            msg_file_rating(xmp_file, rating)
            if rating not in acceptable_rating:
                continue
            # convert to jpeg
            code, _ = run_cmd(executable_darktable_cli(), [
                raw_file, xmp_file,
                dst_jpg_file.lower(), "--core", "--conf",
                "plugins/imageio/format/jpeg/quality=%d" % (JPG_QUALITY, )
            ])
            if code != 0:
                continue
            # rename to original name
            os.rename(dst_jpg_file.lower(), dst_jpg_file)
            # remove rating from the jpeg file, because the darktable-cli create it, but i don't need it!
            # exiftool -overwrite_original -rating=0 -IFD0:Rating=0 -xmp:Rating=0 -IFD0:RatingPercent=0 -xmp:RatingPercent=0 ${DST_PATH}/${1%%.*}.${JPG_EXT}
            code, _ = run_cmd(executable_exiftool(), [
                "-overwrite_original", "-rating=0", "-IFD0:Rating=0",
                "-xmp:Rating=0", "-IFD0:RatingPercent=0",
                "-xmp:RatingPercent=0", dst_jpg_file
            ])
            if code != 0:
                continue
            # exiftool -overwrite_original -rating= -IFD0:Rating= -xmp:Rating= -IFD0:RatingPercent= -xmp:RatingPercent= ${DST_PATH}/${1%%.*}.${JPG_EXT}
            code, _ = run_cmd(executable_exiftool(), [
                "-overwrite_original", "-rating=", "-IFD0:Rating=",
                "-xmp:Rating=", "-IFD0:RatingPercent=", "-xmp:RatingPercent=",
                dst_jpg_file
            ])
            if code != 0:
                continue
            # copy metadata from the original jpeg file
            # exiftool -overwrite_original -TagsFromFile ../${1%%.*}.${JPG_EXT}  "-all:all>all:all" ${DST_PATH}/${1%%.*}.${JPG_EXT}
            code, _ = run_cmd(executable_exiftool(), [
                "-overwrite_original", "-TagsFromFile", jpg_file,
                "-all:all>all:all", dst_jpg_file
            ])
            if code != 0:
                continue
            # mark photo as PickLabel=3 (green flag)
            #exiftool -overwrite_original -orientation= -xmp:PickLabel=3 ${DST_PATH}/${1%%.*}.${JPG_EXT}
            code, _ = run_cmd(executable_exiftool(), [
                "-overwrite_original", "-orientation=", "-xmp:PickLabel=3",
                dst_jpg_file
            ])
            if code != 0:
                continue