-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmc_test.py
66 lines (48 loc) · 2.18 KB
/
mc_test.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
"""
Script loops over folders even subfolders looking for WAV files,
first checking the BEXT to see if it's a DAT if not then
it validates against a MediaConch policy, in this case "Audio-AMI-WAV.xml".
"""
import glob
import os
from mediaconch import *
from pymediainfo import MediaInfo
from pprint import pprint
MC = MediaConch()
# Add MediaConch policy
MC.add_policy("./ArchivematicaPolicies/Audio-AMI-WAV.xml")
# Set display format (optional, default to xml)
MC.set_format(Format.text)
for filename in glob.iglob('./validationFiles/**', recursive=True):
# filter dirs
if os.path.isfile(filename):
# look for WAV files
if filename.endswith(".wav"):
# What about DAT files? How do we know if it was a DAT?
media_info = MediaInfo.parse(filename)
#print(type(media_info))
for trackobj in media_info.tracks:
#print(type(trackobj))
track = trackobj.to_data()
if track["track_type"] == "General":
if trackobj.encoding_settings:
if "DAT" in trackobj.encoding_settings:
#print(track["encoding_settings"])
print(filename + " is a DAT file!")
# insert MC policy info here
else:
print(filename + " is not a DAT file!")
file_id = MC.add_file(filename)
# Display report
# print(MC.get_report(file_id))
report = MC.get_report(file_id)
# print(type(report))
if "Outcome: fail" in report:
print("Fail " + filename)
# save report with WAV filename saved in same directory as WAV file
with open(filename + "-FailReport.txt", "w") as text_file:
text_file.write(report)
else:
print("Pass")
else:
print("No encoding info available")