Exemple #1
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
Exemple #2
0
def cmd_get_rating(filename: str) -> int:
    code, data = run_cmd(executable_exiftool(),
                         ["-xmp:Rating", "-s", "-s", "-s", filename])
    if code == 0:
        if data == '':
            return 0
        else:
            return int(data)
    else:
        return -1
Exemple #3
0
def cmd_get_picklabel(filename: str) -> int:
    code, data = run_cmd(executable_exiftool(),
                         ["-xmp:PickLabel", "-s", "-s", "-s", filename])
    if code == 0:
        if data == '':
            return 0
        else:
            return int(data)
    else:
        return -1
Exemple #4
0
def cmd_get_createdate(filename: str) -> str:
    #code, data = run_cmd(executable_exiftool(), ["-createdate", "-s", "-s", "-s", filename])
    code, data = run_cmd(executable_exiftool(),
                         ["-datetimeoriginal", "-s", "-s", "-s", filename])
    if code == 0:
        if data == '':
            return "00000000_000000"
        else:
            return data.strip().replace(':', '').replace(' ', '_')
    else:
        return None
Exemple #5
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
Exemple #6
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