def add_finder_tag_for_path(path: str, tag: str) -> None: """Set a Finder tag for a given file or folder. :param path: The path of the file of folder to edit. :param tag: The tag name to set. """ if tag: mac_tag.add(tag, path) else: raise ValueError("Null tags are not valid")
def add_tag(tag, path, do_open=False): tag_file = os.path.join(path, STAGEFILE) with open(tag_file, 'w') as f: f.write(tag) if not USING_MAC: return mac_tag.add([tag], [path]) if do_open: open_dir(path)
def write_date(row): file_path = row[0] date_string = row[1] date_string_with_ca_timezone = date_string + '-07:00' file_extension_specific_flags = [] low = file_path.lower() print(f"{file_path} <= {date_string}") mac_tag.add('Pink', file_path) failures = [] # special processing for videos -- the et flags are much longer, pyexiftool kept complaining with parsing/formatting errors. just using subprocess instead if low.endswith('mp4') or low.endswith('mov'): retcode = subprocess.call(['exiftool', '-overwrite_original', '-m', *[u'-%s=%s' % (tag, date_string) for tag in mov_tags], '-QuickTime:Keywords=guessed_date', file_path]) if retcode != 0: return [file_path, retcode] else: return if low.endswith('jpeg') or low.endswith('jpg'): file_extension_specific_flags.append('-AllDates={}'.format(date_string).encode('utf-8')) elif low.endswith('png'): file_extension_specific_flags.append('-{}={}'.format(png_tag, date_string_with_ca_timezone).encode('utf-8')) elif low.endswith('tif'): date_object = datetime.datetime.strptime(date_string, DATE_FORMAT_STRING) file_extension_specific_flags += [ '-{}={}'.format(tif_date_tag, datetime.datetime.strftime(date_object, TIF_DATE_FORMAT_STRING)).encode('utf-8'), '-{}={}-07:00'.format(tif_time_tag, datetime.datetime.strftime(date_object, TIF_TIME_FORMAT_STRING)).encode('utf-8') ] elif low.endswith('gif'): print(f"GIF no-op!!! {file_path}") # can't figure out if apple reads EXIF from a GIF. Going to manually edit the few gifs I have return else: assert(False), row[0] with exiftool.ExifTool() as et: GUESSED_DATE = 'guessed_date' ret = et.execute( *(['-overwrite_original'.encode('utf-8')] + file_extension_specific_flags + [f"-IPTC:Keywords={GUESSED_DATE}".encode('utf-8'), f"-XMP:Subject={GUESSED_DATE}".encode('utf-8'), file_path.encode('utf-8')]) ) print(ret) if b'error' in ret: return [file_path, ret]
#!/usr/bin/env python # -*- coding: utf-8 -*- import mac_tag tags = ["Red", "Blue"] path = [__file__] mac_tag.add(tags, path) mac_tag.remove(["Red"], path) mac_tag.remove(["*"], path) tags = mac_tag.get(path) print(tags)