Various testing tweaks.
[libdcp.git] / test / ref / make.py
1 #!/usr/bin/python
2
3 import os
4 import sys
5 import fileinput
6 from lxml import etree
7
8 def replace(l, a, b):
9     return l.replace(a, b)
10
11 assetmap_namespace = 'http://www.smpte-ra.org/schemas/429-9/2007/AM'
12 cpl_namespace = 'http://www.smpte-ra.org/schemas/429-7/2006/CPL'
13
14 wanted_cpl_id = 'df0e4141-13c3-4a7a-bef8-b5a04fcbc4bb'
15 wanted_pkl_id = '8e293965-f8ad-48c6-971d-261b01f65cdb'
16 wanted_assetmap_id = '18be072e-5a0f-44e1-b2eb-c8a52ae12789'
17 wanted_video_mxf_id = '81fb54df-e1bf-4647-8788-ea7ba154375b'
18 wanted_audio_mxf_id = 'c38bdd62-ce03-4988-8603-195f134207c7'
19
20 os.system('rm -rf DCP')
21 os.mkdir('DCP')
22 os.system('opendcp_mxf -i j2c -o DCP/video.mxf -r 24')
23 os.system('opendcp_mxf -i wav -o DCP/audio.mxf -r 24')
24 os.system('opendcp_xml --reel DCP/video.mxf DCP/audio.mxf -k feature -t "A Test DCP" -a "A Test DCP"')
25 os.system('mv *.xml DCP')
26
27 cpl_id = None
28 pkl_id = None
29 assetmap_id = None
30
31 for r, d, f in os.walk('DCP'):
32     for n in f:
33         if n.endswith('cpl.xml'):
34             cpl_id = n[0:-8]
35         elif n.endswith('pkl.xml'):
36             pkl_id = n[0:-8]
37
38 os.rename('DCP/%s_cpl.xml' % cpl_id, 'DCP/%s_cpl.xml' % wanted_cpl_id)
39 os.rename('DCP/%s_pkl.xml' % pkl_id, 'DCP/%s_pkl.xml' % wanted_pkl_id)
40
41 xml = etree.parse('DCP/ASSETMAP.xml')
42 assetmap_id = xml.getroot().find('{%s}Id' % assetmap_namespace).text
43 assetmap_id = assetmap_id.replace('urn:uuid:', '')
44
45 def cpl_name(s):
46     return '{%s}%s' % (cpl_namespace, s)
47
48 xml = etree.parse('DCP/%s_cpl.xml' % wanted_cpl_id)
49
50 video_mxf_id = xml.getroot().find(cpl_name('ReelList')).    \
51                              find(cpl_name('Reel')).        \
52                              find(cpl_name('AssetList')).   \
53                              find(cpl_name('MainPicture')). \
54                              find(cpl_name('Id')).text
55 video_mxf_id = video_mxf_id.replace('urn:uuid:', '')
56
57 audio_mxf_id = xml.getroot().find(cpl_name('ReelList')).    \
58                              find(cpl_name('Reel')).        \
59                              find(cpl_name('AssetList')).   \
60                              find(cpl_name('MainSound')). \
61                              find(cpl_name('Id')).text
62 audio_mxf_id = audio_mxf_id.replace('urn:uuid:', '')
63
64 for r, d, f in os.walk('DCP'):
65     for n in f:
66         if n.endswith('.xml'):
67             for line in fileinput.input(os.path.join(r, n), inplace = 1):
68                 line = replace(line, cpl_id, wanted_cpl_id)
69                 line = replace(line, pkl_id, wanted_pkl_id)
70                 line = replace(line, assetmap_id, wanted_assetmap_id)
71                 line = replace(line, video_mxf_id, wanted_video_mxf_id)
72                 line = replace(line, audio_mxf_id, wanted_audio_mxf_id)
73                 print line,
74                 
75