Various playlist editor developments and fixes.
[dcpomatic.git] / hacks / filmsum
1 #!/usr/bin/python3
2
3 import sys
4 import bs4
5 import termcolor
6
7 inside = False
8 xml = ''
9 for l in sys.stdin.readlines():
10     if l.startswith('<Metadata>'):
11         inside = True
12     elif l.startswith('</Metadata'):
13         inside = False
14     if inside:
15         xml += l
16
17 def note(k, v, highlight=None):
18     if highlight is not None and highlight(v):
19         print('%20s: %s' % (k, termcolor.colored(v, 'white', 'on_red')));
20     else:
21         print('%20s: %s' % (k, v))
22
23 def bool_note(k, v, highlight=None):
24     v = 'yes' if v == 1 else 'no'
25     note(k, v, highlight)
26
27 def dcp_time(s):
28     global dcp_rate
29     raw = int(s.text)
30     f = raw * dcp_rate / 96000.0
31     s = f // dcp_rate
32     f -= s * dcp_rate
33     m = s // 60
34     s -= m * 60
35     h = m // 60
36     m -= h * 60
37     return '%s DCP_%02d:%02d:%02d.%02d' % (str(raw).ljust(8), h, m, s, f)
38
39 def content_time_from_frames(s, r):
40     raw = int(s.text)
41     f = raw
42     s = f // r
43     f -= s * r
44     m = s // 60
45     s -= m * 60
46     h = m // 60
47     m -= h * 60
48     return '%s Con_%02d:%02d:%02d.%02d' % (str(raw).ljust(8), h, m, s, f)
49
50 soup = bs4.BeautifulSoup(xml, 'xml')
51 note('Name', soup.Metadata.Name.text)
52 note('Container', soup.Metadata.Container.text)
53 note('J2K bandwidth', soup.Metadata.J2KBandwidth.text, lambda x: int(x) < 20000000 or int(x) > 235000000)
54 note('Video frame rate', soup.Metadata.VideoFrameRate.text, lambda x: int(x) not in [24, 25, 30])
55 dcp_rate = int(soup.Metadata.VideoFrameRate.text)
56 note('Audio channels', soup.Metadata.AudioChannels.text)
57 bool_note('3D', soup.Metadata.ThreeD.text, lambda x: not x)
58 bool_note('Encrypted', soup.Metadata.ThreeD.text, lambda x: not x)
59 reel_types = ['single', 'by-video', 'by-length']
60 note('Reel type', reel_types[int(soup.ReelType.text)])
61 for c in soup.Metadata.Playlist.children:
62     if isinstance(c, bs4.element.Tag):
63         print()
64         note('  Type', c.Type.text)
65         note('  Position', dcp_time(c.Position))
66         if c.VideoFrameRate:
67             note('  Video rate', c.VideoFrameRate.text)
68             note('  Video length', content_time_from_frames(c.VideoLength, float(c.VideoFrameRate.text)))
69         if c.AudioFrameRate:
70             note('  Audio rate', c.AudioFrameRate.text)
71         bool_note('  Reference video', c.ReferenceVideo, lambda x: not x)
72         bool_note('  Reference audio', c.ReferenceAudio, lambda x: not x)
73         bool_note('  Reference subtitle', c.ReferenceSubtitle, lambda x: not x)