using this as reference ...
import subprocess
import os
import json
class ExifTool(object):
sentinel = "{ready}\n"
def __init__(self, executable="/usr/bin/exiftool"):
self.executable = executable
def __enter__(self):
self.process = subprocess.Popen(
[self.executable, "-stay_open", "True", "-@", "-"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
return self
def __exit__(self, exc_type, exc_value, traceback):
self.process.stdin.write("-stay_open\nFalse\n")
self.process.stdin.flush()
def execute(self, *args):
args = args + ("-execute\n",)
self.process.stdin.write(str.join("\n", args))
self.process.stdin.flush()
output = ""
fd = self.process.stdout.fileno()
while not output.endswith(self.sentinel):
output += os.read(fd, 4096)
return output[:-len(self.sentinel)]
def get_metadata(self, *filenames):
return json.loads(self.execute("-G", "-j", "-n", *filenames))
... return follow ERROR using Python 3.8.10 and IPYTHON;
" AttributeError Traceback (most recent
call last) in
56
57 e = ExifTool()
---> 58 e.load_metadata_lookup('/u02/RECOVERY/')
in load_metadata_lookup(self, locDir)
51 '\n FILELOC > ', FileLoc, '\n')
52
---> 53 self.get_metadata(FileLoc)
54
55
in get_metadata(self, FileLoc)
38
39 def get_metadata(self, FileLoc):
---> 40 return json.loads(self.execute("-G", "-j", "-n", FileLoc))
41
42
in execute(self, *args)
28 def execute(self, *args):
29 args = args + ("-execute\n",)
---> 30 self.process.stdin.write(str.join("\n", args))
31 self.process.stdin.flush()
32 output = ""
AttributeError: 'ExifTool' object has no attribute 'process'
...
then with some modifications ... SUCCESS!!! ...
modified and adaptations using
[https://stackoverflow.com/users/279627/sven-marnach]
#!/usr/local/bin/python3
#! -*- coding: utf-8-mb4 -*-
from __future__ import absolute_import
import sys
import os
import subprocess
import json
headers_infos = """
.:.
.:. box33 | systems | platform |
.:. [ Renan Moura ]
.:. [ ver.: 9.1.2-b ]
.:.
"""
class ExifTool(object):
sentinel = "{ready}\n"
def __init__(self):
self.executable = "/usr/bin/exiftool"
self.metadata_lookup = {}
def __exit__(self, exc_type, exc_value, traceback):
self.process.stdin.write("-stay_open\nFalse\n")
self.process.stdin.flush()
def execute(self, *args):
self.process = subprocess.Popen([self.executable, "-stay_open", "True", "-@", "-"],
universal_newlines = True ,
stdin = subprocess.PIPE ,
stdout = subprocess.PIPE ,
stderr = subprocess.STDOUT
)
args = (args + ("-execute\n",))
self.process.stdin.write(str.join("\n", args))
self.process.stdin.flush()
output = ""
fd = self.process.stdout.fileno()
while not output.endswith(self.sentinel):
output += os.read(fd, 4096).decode('utf-8')
return output[:-len(self.sentinel)]
def get_metadata(self, *FileLoc):
return json.loads(self.execute("-G", "-j", "-n", *FileLoc))
def load_metadata_lookup(self, locDir):
self.metadata_lookup = {}
for dirname, dirnames, filenames in os.walk(locDir):
for filename in filenames:
FileLoc=(dirname + '/' + filename)
print( '\n FILENAME > ', filename,
'\n DIRNAMES > ', dirnames,
'\n DIRNAME > ', dirname,
'\n FILELOC > ', FileLoc, '\n')
self.metadata_lookup = self.get_metadata(FileLoc)
print(json.dumps(self.metadata_lookup, indent=3))
e = ExifTool()
e.load_metadata_lookup('/u02/RECOVERY/')
... NOTE
this code ll from "/u02/RECOVERY/" ... directory find and execute on every document found ...
hope this could help u ...