From 8738ae963afc784fcef76de6bcebf277a58379ab Mon Sep 17 00:00:00 2001 From: Bernhard Bliem Date: Fri, 18 Jan 2019 03:55:19 +0200 Subject: [PATCH 1/3] Added option for keeping print conversion active. For some tags, disabling print conversion (as was the default before) would not make much sense. For example, if print conversion is deactivated, the value of the Composite:LensID tag could be reported as something like "8D 44 5C 8E 34 3C 8F 0E". It is doubtful whether this is useful here, as we would then need to look up what this means in a table supplied with exiftool. We would probably like the human-readable value, which is in this case "AF-S DX Zoom-Nikkor 18-70mm f/3.5-4.5G IF-ED". Disabling print conversion makes sense for a lot of tags (e.g., it's nicer to get as the exposure time not the string "1/2" but the number 0.5). In such cases, even if we enable print conversion, we can disable it for individual tags by appending a # symbol to the tag name. --- exiftool.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/exiftool.py b/exiftool.py index 8a11daa..2376abc 100644 --- a/exiftool.py +++ b/exiftool.py @@ -115,6 +115,11 @@ def fsencode(filename): class ExifTool(object): """Run the `exiftool` command-line tool and communicate to it. + The argument ``print_conversion`` determines whether exiftool should + perform print conversion, which prints values in a human-readable way but + may be slower. If print conversion is enabled, appending ``#`` to a tag + name disables the print conversion for this particular tag. + You can pass the file name of the ``exiftool`` executable as an argument to the constructor. The default value ``exiftool`` will only work if the executable is in your ``PATH``. @@ -148,7 +153,8 @@ class ExifTool(object): associated with a running subprocess. """ - def __init__(self, executable_=None): + def __init__(self, executable_=None, print_conversion=False): + self.print_conversion = print_conversion if executable_ is None: self.executable = executable else: @@ -158,18 +164,20 @@ def __init__(self, executable_=None): def start(self): """Start an ``exiftool`` process in batch mode for this instance. - This method will issue a ``UserWarning`` if the subprocess is - already running. The process is started with the ``-G`` and - ``-n`` as common arguments, which are automatically included - in every command you run with :py:meth:`execute()`. + This method will issue a ``UserWarning`` if the subprocess is already + running. The process is started with ``-G`` (and, if print conversion + was disabled, ``-n``) as common arguments, which are automatically + included in every command you run with :py:meth:`execute()`. """ if self.running: warnings.warn("ExifTool already running; doing nothing.") return + command = [self.executable, "-stay_open", "True", "-@", "-", "-common_args", "-G"] + if not self.print_conversion: + command.append("-n") with open(os.devnull, "w") as devnull: self._process = subprocess.Popen( - [self.executable, "-stay_open", "True", "-@", "-", - "-common_args", "-G", "-n"], + command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=devnull) self.running = True From ca0c50a430cc2ec609cc812cd05771b0d168970d Mon Sep 17 00:00:00 2001 From: Bernhard Bliem Date: Sat, 9 Feb 2019 00:58:43 +0200 Subject: [PATCH 2/3] Updated version number --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 03e9436..194957f 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ from distutils.core import setup setup(name="PyExifTool", - version="0.1", + version="0.1-bbliem", description="Python wrapper for exiftool", license="GPLv3+", author="Sven Marnach", From 82e3f14f87ef284a08e690e6e618323067636809 Mon Sep 17 00:00:00 2001 From: Bernhard Bliem Date: Sat, 5 Jun 2021 13:22:38 +0300 Subject: [PATCH 3/3] Made version number PEP 440 compliant --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 194957f..928de3e 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ from distutils.core import setup setup(name="PyExifTool", - version="0.1-bbliem", + version="0.2", description="Python wrapper for exiftool", license="GPLv3+", author="Sven Marnach",