/
check-resolution-tags
executable file
·35 lines (28 loc) · 1.24 KB
/
check-resolution-tags
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
#!/usr/bin/env python3
"""Check media file names for resolution tags (.720p. etc.)"""
from pymediainfo import MediaInfo
import argparse
parser = argparse.ArgumentParser(description='Check media file names for resolution tags')
parser.add_argument('filename', nargs='+', help='media file name(s)')
args = parser.parse_args()
for fn in args.filename:
try:
media_info = MediaInfo.parse(fn)
tracks = (track for track in media_info.tracks if track.track_type == 'Video')
for track in tracks:
if track.height in [720, 1080, 2160]:
desired_tag = '.%dp.' % track.height
elif track.width == 1280 and 576 < track.height <= 720:
desired_tag = '.%dp.' % 720
elif track.width == 1920 and 720 < track.height <= 1080:
desired_tag = '.%dp.' % 1080
elif track.height > 576:
print('{} has strange dimensions of {}x{}'.format(fn, track.width, track.height))
continue
else:
continue
if desired_tag not in fn:
print('{} should have "{}" resolution tag'.format(fn, desired_tag))
except FileNotFoundError as e:
print("File not found: {}".format(fn))
# vim:tw=120: