Skip to content

Commit c55ff44

Browse files
committed
Replace libmat2 with modified version #10
1 parent ed84a11 commit c55ff44

File tree

8 files changed

+1020
-5
lines changed

8 files changed

+1020
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,4 @@ name = "metadata_remover"
33
version = "1.6"
44
description = "Tool for removing metadata from images and videos"
55
license = {file = "LICENSE.txt"}
6-
readme = "README.md"
7-
8-
dependencies = [
9-
"mat2"
10-
]
6+
readme = "README.md"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
import enum
3+
import importlib
4+
from typing import Dict, Optional, Union
5+
6+
# A set of extension that aren't supported, despite matching a supported mimetype
7+
UNSUPPORTED_EXTENSIONS = {
8+
'.asc',
9+
'.bat',
10+
'.brf',
11+
'.c',
12+
'.h',
13+
'.ksh',
14+
'.pl',
15+
'.pot',
16+
'.rdf',
17+
'.srt',
18+
'.wsdl',
19+
'.xpdl',
20+
'.xsd',
21+
'.xsl',
22+
}
23+
24+
DEPENDENCIES = {
25+
'Mutagen': {
26+
'module': 'mutagen',
27+
'required': True,
28+
},
29+
}
30+
31+
32+
def check_dependencies() -> Dict[str, Dict[str, bool]]:
33+
ret = dict() # type: Dict[str, dict]
34+
35+
for key, value in DEPENDENCIES.items():
36+
ret[key] = {
37+
'found': True,
38+
'required': value['required'],
39+
}
40+
try:
41+
importlib.import_module(value['module']) # type: ignore
42+
except ImportError: # pragma: no cover
43+
ret[key]['found'] = False
44+
45+
46+
return ret
47+
48+
49+
@enum.unique
50+
class UnknownMemberPolicy(enum.Enum):
51+
ABORT = 'abort'
52+
OMIT = 'omit'
53+
KEEP = 'keep'
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import abc
2+
import os
3+
import re
4+
from typing import Set, Dict, Union
5+
6+
assert Set # make pyflakes happy
7+
8+
9+
class AbstractParser(abc.ABC):
10+
""" This is the base class of every parser.
11+
It might yield `ValueError` on instantiation on invalid files,
12+
and `RuntimeError` when something went wrong in `remove_all`.
13+
"""
14+
meta_list = set() # type: Set[str]
15+
mimetypes = set() # type: Set[str]
16+
17+
def __init__(self, filename: str) -> None:
18+
"""
19+
:raises ValueError: Raised upon an invalid file
20+
"""
21+
if re.search('^[a-z0-9./]', filename) is None:
22+
# Some parsers are calling external binaries,
23+
# this prevents shell command injections
24+
filename = os.path.join('.', filename)
25+
26+
self.filename = filename
27+
fname, extension = os.path.splitext(filename)
28+
29+
# Special case for tar.gz, tar.bz2, … files
30+
if fname.endswith('.tar') and len(fname) > 4:
31+
fname, extension = fname[:-4], '.tar' + extension
32+
33+
self.output_filename = fname + '.cleaned' + extension
34+
self.lightweight_cleaning = False
35+
self.sandbox = True
36+
37+
@abc.abstractmethod
38+
def get_meta(self) -> Dict[str, Union[str, dict]]:
39+
"""Return all the metadata of the current file"""
40+
41+
@abc.abstractmethod
42+
def remove_all(self) -> bool:
43+
"""
44+
Remove all the metadata of the current file
45+
46+
:raises RuntimeError: Raised if the cleaning process went wrong.
47+
"""

0 commit comments

Comments
 (0)