Coverage for pyguymer3/image/load_EXIF2.py: 8%

13 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-08 18:47 +0000

1#!/usr/bin/env python3 

2 

3# Define function ... 

4def load_EXIF2( 

5 fname, 

6 /, 

7 *, 

8 compressed = False, 

9 exiftoolPath = None, 

10 timeout = 60.0, 

11): 

12 # Import standard modules ... 

13 import json 

14 import shutil 

15 import subprocess 

16 

17 # ************************************************************************** 

18 

19 # Try to find the paths if the user did not provide them ... 

20 if exiftoolPath is None: 

21 exiftoolPath = shutil.which("exiftool") 

22 assert exiftoolPath is not None, "\"exiftool\" is not installed" 

23 

24 # Create "exiftool" command ... 

25 cmd = [ 

26 exiftoolPath, 

27 "-api", "largefilesupport=1", 

28 "-json", 

29 ] 

30 if compressed: 

31 cmd += [ 

32 "-zip", 

33 ] 

34 cmd += [ 

35 "-coordFormat", "%+.12f", 

36 "-dateFormat", "%Y-%m-%dT%H:%M:%S.%.6f", # should be the same as datetime.isoformat(sep = "T", timespec = "microseconds") 

37 "-groupNames", 

38 "-struct", 

39 "--printConv", 

40 fname, 

41 ] 

42 

43 # Run "exiftool" and load it as JSON ... 

44 # NOTE: Don't merge standard out and standard error together as the result 

45 # will probably not be valid JSON if standard error is not empty. 

46 ans = json.loads( 

47 subprocess.run( 

48 cmd, 

49 check = True, 

50 encoding = "utf-8", 

51 stderr = subprocess.DEVNULL, 

52 stdout = subprocess.PIPE, 

53 timeout = timeout, 

54 ).stdout 

55 )[0] 

56 

57 # Return answer ... 

58 return ans