Skip to content

Commit

Permalink
Merge pull request #434 from yajrendrag/pr-ignore_files_based_on_meta…
Browse files Browse the repository at this point in the history
…data

[ignore_files_based_on_metadata] 0.0.5
  • Loading branch information
Josh5 authored Jan 1, 2025
2 parents e24c556 + da46ee1 commit 35db98e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
7 changes: 6 additions & 1 deletion source/ignore_files_based_on_metadata/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

**<span style="color:#56adda">0.0.5</span>**
- add subtitle format section
- add audio mime type to the plugin
- make the stream search for disallowed values apply to all stream types and not just video

**<span style="color:#56adda">0.0.4</span>**
- generalized use of stream tags for audio and video streams too
- generalize tag inclusion to video and audio streams too

**<span style="color:#56adda">0.0.3</span>**
- add test to check attachment streams tags
Expand Down
2 changes: 1 addition & 1 deletion source/ignore_files_based_on_metadata/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"on_library_management_file_test": 1
},
"tags": "library file test",
"version": "0.0.4"
"version": "0.0.5"
}
13 changes: 10 additions & 3 deletions source/ignore_files_based_on_metadata/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def file_has_disallowed_metadata(path, disallowed_metadata, metadata_value):
"""

# initialize Probe
probe_data=Probe(logger, allowed_mimetypes=['video'])
probe_data=Probe(logger, allowed_mimetypes=['video', 'audio'])

# Get stream data from probe
if probe_data.file(path):
Expand All @@ -80,7 +80,7 @@ def file_has_disallowed_metadata(path, disallowed_metadata, metadata_value):
return True

# Check if stream or format components contain disallowed metadata
streams = [probe_streams[i] for i in range(0, len(probe_streams)) if "codec_type" in probe_streams[i] and probe_streams[i]["codec_type"] == "video"]
streams = [probe_streams[i] for i in range(0, len(probe_streams)) if "codec_type" in probe_streams[i] and probe_streams[i]["codec_type"] in ["video", 'audio', 'attachment', 'subtitle']]
file_has_disallowed_metadata = [streams[i] for i in range(0, len(streams)) if disallowed_metadata in streams[i] and metadata_value in streams[i][disallowed_metadata]]
probe_format_d = {k:v for (k, v) in probe_format.items() if type(v) is dict}
probe_format_kv = {k:v for (k, v) in probe_format.items() if type(v) is not dict}
Expand All @@ -96,6 +96,13 @@ def file_has_disallowed_metadata(path, disallowed_metadata, metadata_value):
except KeyError:
file_has_disallowed_metadata_ast = ""

subtitle_streams = [probe_streams[i] for i in range(0, len(probe_streams)) if "codec_type" in probe_streams[i] and probe_streams[i]["codec_type"] == "subtitle"]
try:
probe_ss_tags_kv = {k:v for i in range(0, len(attachment_streams)) for (k, v) in attachment_streams[i]["tags"].items() if type(v) is not dict}
file_has_disallowed_metadata_sst = [(k, v) for (k, v) in probe_ss_tags_kv.items() if (disallowed_metadata in k.lower() and metadata_value in v)]
except KeyError:
file_has_disallowed_metadata_sst = ""

video_streams = [probe_streams[i] for i in range(0, len(probe_streams)) if "codec_type" in probe_streams[i] and probe_streams[i]["codec_type"] == "video"]
try:
probe_vs_tags_kv = {k:v for i in range(0, len(video_streams)) for (k, v) in video_streams[i]["tags"].items() if type(v) is not dict}
Expand All @@ -110,7 +117,7 @@ def file_has_disallowed_metadata(path, disallowed_metadata, metadata_value):
except KeyError:
file_has_disallowed_metadata_aust = ""

if file_has_disallowed_metadata or file_has_disallowed_metadata_fmt or file_has_disallowed_metadata_ast or file_has_disallowed_metadata_vst or file_has_disallowed_metadata_aust:
if file_has_disallowed_metadata or file_has_disallowed_metadata_fmt or file_has_disallowed_metadata_ast or file_has_disallowed_metadata_sst or file_has_disallowed_metadata_vst or file_has_disallowed_metadata_aust:
logger.debug("File '{}' contains disallowed metadata '{}': '{}'.".format(path, disallowed_metadata, metadata_value))
return True

Expand Down

0 comments on commit 35db98e

Please sign in to comment.