-
Notifications
You must be signed in to change notification settings - Fork 19
/
mp4hash.py
75 lines (57 loc) · 1.46 KB
/
mp4hash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""MPEG-4 Selective Hashing Tool"""
import argparse
import hashlib
from pathlib import Path
from rich import print
from errors.mp4 import InvalidMP4Error
from fileio.mp4 import hash_mp4file
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description='Hashes an MPEG-4 except the "moov" and "mdat" portions using MD5.',
)
parser.add_argument(
dest='file',
metavar='FILE',
help='MPEG4 file',
)
parser.add_argument(
'-d', '--debug',
required=False,
action='store_true',
default=False,
help='Debug output',
)
parser.add_argument(
'-b', '--use-broken-algo',
required=False,
action='store_true',
default=False,
help='Use broken algorithm',
)
return parser.parse_args()
def main() -> None:
args = parse_args()
file_name = Path(args.file)
md5 = hashlib.md5()
hash = hash_mp4file(
md5,
file_name,
print=print if args.debug else None,
use_broken_algo=args.use_broken_algo,
)
print(f'{hash}\t*{file_name.name}')
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass
except InvalidMP4Error as ex:
print()
print(f"Invalid MPEG-4 file: {ex}")
print()
print()
except Exception as ex:
print()
print(f"Unexpected error: {ex}")
print()
print()