diff --git a/README.md b/README.md index 199b13c5..6ef85a9e 100644 --- a/README.md +++ b/README.md @@ -367,7 +367,8 @@ contain a brace symbol ('{' or '}'). If you do not specify a default value and the template substitution has no value, '_' (underscore) will be used as the default value. For example, in the -above example, this would result in '2020/_/photoname.jpg' if address was null. +above example, this would result in '2020/_/photoname.jpg' if address was +null. Substitution Description {name} Current filename of the photo @@ -391,6 +392,18 @@ Substitution Description creation time {created.doy} 3-digit day of year (e.g Julian day) of file creation time, starting from 1 (zero padded) +{created.hour} 2-digit hour of the file creation time +{created.min} 2-digit minute of the file creation time +{created.sec} 2-digit second of the file creation time +{created.strftime} Apply strftime template to file creation + date/time. Should be used in form + {created.strftime,TEMPLATE} where TEMPLATE + is a valid strftime template, e.g. + {created.strftime,%Y-%U} would result in + year-week number of year: '2020-23'. If used + with no template will return null value. See + https://strftime.org/ for help on strftime + templates. {modified.date} Photo's modification date in ISO format, e.g. '2020-03-22' {modified.year} 4-digit year of file modification time @@ -406,6 +419,9 @@ Substitution Description {modified.doy} 3-digit day of year (e.g Julian day) of file modification time, starting from 1 (zero padded) +{modified.hour} 2-digit hour of the file modification time +{modified.min} 2-digit minute of the file modification time +{modified.sec} 2-digit second of the file modification time {place.name} Place name from the photo's reverse geolocation data, as displayed in Photos {place.country_code} The ISO country code from the photo's diff --git a/osxphotos/_version.py b/osxphotos/_version.py index c39cba68..ec950c4c 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.29.15" +__version__ = "0.29.16" diff --git a/osxphotos/photoinfo/photoinfo.py b/osxphotos/photoinfo/photoinfo.py index 75651b5f..26a07d71 100644 --- a/osxphotos/photoinfo/photoinfo.py +++ b/osxphotos/photoinfo/photoinfo.py @@ -637,6 +637,9 @@ class PhotoInfo: none_str: a str to use if template field renders to None, default is "_". path_sep: a single character str to use as path separator when joining fields like folder_album; if not provided, defaults to os.path.sep + + Returns: + ([rendered_strings], [unmatched]): tuple of list of rendered strings and list of unmatched template values """ template = PhotoTemplate(self) return template.render(template_str, none_str, path_sep) diff --git a/osxphotos/phototemplate.py b/osxphotos/phototemplate.py index 233f2402..6d345c7a 100644 --- a/osxphotos/phototemplate.py +++ b/osxphotos/phototemplate.py @@ -38,6 +38,11 @@ TEMPLATE_SUBSTITUTIONS = { "{created.hour}": "2-digit hour of the file creation time", "{created.min}": "2-digit minute of the file creation time", "{created.sec}": "2-digit second of the file creation time", + "{created.strftime}": "Apply strftime template to file creation date/time. Should be used in form " + + "{created.strftime,TEMPLATE} where TEMPLATE is a valid strftime template, e.g. " + + "{created.strftime,%Y-%U} would result in year-week number of year: '2020-23'. " + + "If used with no template will return null value. " + + "See https://strftime.org/ for help on strftime templates.", "{modified.date}": "Photo's modification date in ISO format, e.g. '2020-03-22'", "{modified.year}": "4-digit year of file modification time", "{modified.yy}": "2-digit year of file modification time", @@ -49,6 +54,11 @@ TEMPLATE_SUBSTITUTIONS = { "{modified.hour}": "2-digit hour of the file modification time", "{modified.min}": "2-digit minute of the file modification time", "{modified.sec}": "2-digit second of the file modification time", + # "{modified.strftime}": "Apply strftime template to file modification date/time. Should be used in form " + # + "{modified.strftime,TEMPLATE} where TEMPLATE is a valid strftime template, e.g. " + # + "{modified.strftime,%Y-%U} would result in year-week number of year: '2020-23'. " + # + "If used with no template will return null value. " + # + "See https://strftime.org/ for help on strftime templates.", "{place.name}": "Place name from the photo's reverse geolocation data, as displayed in Photos", "{place.country_code}": "The ISO country code from the photo's reverse geolocation data", "{place.name.country}": "Country name from the photo's reverse geolocation data", @@ -93,10 +103,17 @@ class PhotoTemplate: self.photo = photo def render(self, template, none_str="_", path_sep=None): - """ render a filename or directory template + """ Render a filename or directory template + + Args: template: str template none_str: str to use default for None values, default is '_' - path_sep: optional character to use as path separator, default is os.path.sep """ + path_sep: optional character to use as path separator, default is os.path.sep + + Returns: + ([rendered_strings], [unmatched]): tuple of list of rendered strings and list of unmatched template values + """ + if path_sep is None: path_sep = os.path.sep elif path_sep is not None and len(path_sep) != 1: @@ -113,7 +130,7 @@ class PhotoTemplate: # regex to find {template_field,optional_default} in strings # for explanation of regex see https://regex101.com/r/4JJg42/1 # pylint: disable=anomalous-backslash-in-string - regex = r"(?