Fixed exiftool to ignore unsupported file types, #615
This commit is contained in:
12
MANIFEST.in
12
MANIFEST.in
@@ -1,7 +1,7 @@
|
|||||||
include README.md
|
include osxphotos/*.json
|
||||||
include README.rst
|
include osxphotos/*.md
|
||||||
include osxphotos/templates/*
|
|
||||||
include osxphotos/phototemplate.tx
|
include osxphotos/phototemplate.tx
|
||||||
include osxphotos/phototemplate.md
|
include osxphotos/queries/*
|
||||||
include osxphotos/tutorial.md
|
include osxphotos/templates/*
|
||||||
include osxphotos/queries/*
|
include README.md
|
||||||
|
include README.rst
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
""" version info """
|
""" version info """
|
||||||
|
|
||||||
__version__ = "0.45.6"
|
__version__ = "0.45.7"
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import html
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import pathlib
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -19,11 +20,12 @@ from functools import lru_cache # pylint: disable=syntax-error
|
|||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"escape_str",
|
"escape_str",
|
||||||
"unescape_str",
|
"exiftool_can_write",
|
||||||
"terminate_exiftool",
|
|
||||||
"get_exiftool_path",
|
|
||||||
"ExifTool",
|
"ExifTool",
|
||||||
"ExifToolCaching",
|
"ExifToolCaching",
|
||||||
|
"get_exiftool_path",
|
||||||
|
"terminate_exiftool",
|
||||||
|
"unescape_str",
|
||||||
]
|
]
|
||||||
|
|
||||||
# exiftool -stay_open commands outputs this EOF marker after command is run
|
# exiftool -stay_open commands outputs this EOF marker after command is run
|
||||||
@@ -33,6 +35,24 @@ EXIFTOOL_STAYOPEN_EOF_LEN = len(EXIFTOOL_STAYOPEN_EOF)
|
|||||||
# list of exiftool processes to cleanup when exiting or when terminate is called
|
# list of exiftool processes to cleanup when exiting or when terminate is called
|
||||||
EXIFTOOL_PROCESSES = []
|
EXIFTOOL_PROCESSES = []
|
||||||
|
|
||||||
|
# exiftool supported file types, created by utils/exiftool_supported_types.py
|
||||||
|
EXIFTOOL_FILETYPES_JSON = "exiftool_filetypes.json"
|
||||||
|
with (pathlib.Path(__file__).parent / EXIFTOOL_FILETYPES_JSON).open("r") as f:
|
||||||
|
EXIFTOOL_SUPPORTED_FILETYPES = json.load(f)
|
||||||
|
|
||||||
|
|
||||||
|
def exiftool_can_write(suffix: str) -> bool:
|
||||||
|
"""Return True if exiftool supports writing to a file with the given suffix, otherwise False"""
|
||||||
|
if not suffix:
|
||||||
|
return False
|
||||||
|
suffix = suffix.lower()
|
||||||
|
if suffix[0] == ".":
|
||||||
|
suffix = suffix[1:]
|
||||||
|
return (
|
||||||
|
suffix in EXIFTOOL_SUPPORTED_FILETYPES
|
||||||
|
and EXIFTOOL_SUPPORTED_FILETYPES[suffix]["write"]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def escape_str(s):
|
def escape_str(s):
|
||||||
"""escape string for use with exiftool -E"""
|
"""escape string for use with exiftool -E"""
|
||||||
|
|||||||
4976
osxphotos/exiftool_filetypes.json
Normal file
4976
osxphotos/exiftool_filetypes.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
|
|
||||||
import dataclasses
|
import dataclasses
|
||||||
import glob
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
@@ -33,7 +32,7 @@ from ._constants import (
|
|||||||
)
|
)
|
||||||
from ._version import __version__
|
from ._version import __version__
|
||||||
from .datetime_utils import datetime_tz_to_utc
|
from .datetime_utils import datetime_tz_to_utc
|
||||||
from .exiftool import ExifTool
|
from .exiftool import ExifTool, exiftool_can_write
|
||||||
from .export_db import ExportDB_ABC, ExportDBNoOp
|
from .export_db import ExportDB_ABC, ExportDBNoOp
|
||||||
from .fileutil import FileUtil
|
from .fileutil import FileUtil
|
||||||
from .photokit import (
|
from .photokit import (
|
||||||
@@ -1260,11 +1259,20 @@ class PhotoExporter:
|
|||||||
|
|
||||||
exiftool_results = ExportResults()
|
exiftool_results = ExportResults()
|
||||||
|
|
||||||
|
# don't try to write if unsupported file type for exiftool
|
||||||
|
if not exiftool_can_write(os.path.splitext(src)[-1]):
|
||||||
|
exiftool_results.exiftool_warning.append(
|
||||||
|
(
|
||||||
|
dest,
|
||||||
|
f"Unsupported file type for exiftool, skipping exiftool for {dest}",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return exiftool_results
|
||||||
|
|
||||||
# determine if we need to write the exif metadata
|
# determine if we need to write the exif metadata
|
||||||
# if we are not updating, we always write
|
# if we are not updating, we always write
|
||||||
# else, need to check the database to determine if we need to write
|
# else, need to check the database to determine if we need to write
|
||||||
run_exiftool = not options.update
|
run_exiftool = not options.update
|
||||||
current_data = "foo"
|
|
||||||
if options.update:
|
if options.update:
|
||||||
files_are_different = False
|
files_are_different = False
|
||||||
old_data = export_db.get_exifdata_for_file(dest)
|
old_data = export_db.get_exifdata_for_file(dest)
|
||||||
|
|||||||
57
utils/exiftool_supported_types.py
Normal file
57
utils/exiftool_supported_types.py
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
"""Read the "Supported File Types" table from exiftool.org and build a json file from the table"""
|
||||||
|
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
url = "https://www.exiftool.org/"
|
||||||
|
json_file = "exiftool_filetypes.json"
|
||||||
|
|
||||||
|
html_content = requests.get(url).text
|
||||||
|
|
||||||
|
soup = BeautifulSoup(html_content, "html.parser")
|
||||||
|
|
||||||
|
# uncomment to see all table classes
|
||||||
|
# print("Classes of each table:")
|
||||||
|
# for table in soup.find_all("table"):
|
||||||
|
# print(table.get("class"))
|
||||||
|
|
||||||
|
# strip footnotes in <span> tags
|
||||||
|
for span_tag in soup.findAll("span"):
|
||||||
|
span_tag.replace_with("")
|
||||||
|
|
||||||
|
# find the table for Supported File Types
|
||||||
|
table = soup.find("table", class_="sticky tight sm bm")
|
||||||
|
|
||||||
|
# get table headers
|
||||||
|
table_headers = [tx.text.lower() for tx in table.find_all("th")]
|
||||||
|
|
||||||
|
# get table data
|
||||||
|
table_data = []
|
||||||
|
for tr in table.find_all("tr"):
|
||||||
|
if row := [td.text for td in tr.find_all("td")]:
|
||||||
|
table_data.append(row)
|
||||||
|
|
||||||
|
# make a dictionary of the table data
|
||||||
|
supported_filetypes = {}
|
||||||
|
for row in table_data:
|
||||||
|
row_dict = dict(zip(table_headers, row))
|
||||||
|
for key, value in row_dict.items():
|
||||||
|
if value == "-":
|
||||||
|
row_dict[key] = None
|
||||||
|
row_dict["file type"] = row_dict["file type"].split(",")
|
||||||
|
row_dict["file type"] = [ft.strip() for ft in row_dict["file type"]]
|
||||||
|
row_dict["read"] = "R" in row_dict["support"]
|
||||||
|
row_dict["write"] = "W" in row_dict["support"]
|
||||||
|
row_dict["create"] = "C" in row_dict["support"]
|
||||||
|
filetypes = [ft.lower() for ft in row_dict["file type"]]
|
||||||
|
for filetype in filetypes:
|
||||||
|
supported_filetypes[filetype] = {"extension": filetype, **row_dict}
|
||||||
|
|
||||||
|
with open(json_file, "w") as jsonfile:
|
||||||
|
print(f"Writing {json_file}...")
|
||||||
|
json.dump(supported_filetypes, jsonfile, indent=4)
|
||||||
Reference in New Issue
Block a user