@@ -91,17 +91,10 @@ def main():
9191
9292 # get the label of the last Claim
9393 parent_claim = get_xmp_tag (raw_bytes )
94- print ('parent_claim: ' , parent_claim )
9594
9695 # get App11 marker segment headers
9796 app11_headers = get_app11_marker_segment_headers (raw_bytes )
9897 has_app11_headers = True if len (app11_headers ) > 0 else False
99- if has_app11_headers :
100- print ('Find App11 marker segments' )
101- for i in range (1 , len (app11_headers ) + 1 ):
102- print ('\t {0}' .format (app11_headers [i ]))
103- else :
104- print ('No existing App11 marker segment.' )
10598
10699 # create CAI metadata
107100 assertions = []
@@ -124,23 +117,31 @@ def main():
124117 else :
125118 key = []
126119
127- # create a new Store
128- cai_store = CaiStore (label = store_label ,
129- assertions = assertions ,
130- recorder = recorder ,
131- parent_claim = parent_claim ,
132- key = key )
133120 if has_app11_headers :
121+ # generate acquisition assertion
122+ acquisition_assertion = {
123+ 'dc:format' : 'image/jpeg' ,
124+ 'dc:title' : os .path .basename (args .inject ),
125+ 'dcterms:provenance' : parent_claim ,
126+ 'stRef:DocumentID' : 'xmp:fakeid:39afb1d3-7f8c-44e6-b771-85e0d9adb377' ,
127+ 'stRef:InstanceID' : 'xmp:fakeid:10c04858-d3fd-4e2c-8947-7f1e29d62fbe' ,
128+ 'thumbnail' : 'self#jumbf=cai/{}/cai.assertions/cai.acquisition.thumbnail.jpeg' .format (store_label )
129+ }
130+ assertions .append (create_json_superbox (
131+ content = json_to_bytes (acquisition_assertion ),
132+ label = 'cai.acquisition_1' ))
133+
134+ # create a new Store
135+ cai_store = CaiStore (label = store_label ,
136+ assertions = assertions ,
137+ recorder = recorder ,
138+ parent_claim = parent_claim ,
139+ key = key )
140+
134141 # get last segment header information
135142 header_number = len (app11_headers )
136- last_le = app11_headers [header_number ]['le' ]
137143 last_en = app11_headers [header_number ]['en' ]
138- last_z = app11_headers [header_number ]['z' ]
139144 last_lbox = app11_headers [header_number ]['lbox' ]
140- last_tbox = app11_headers [header_number ]['tbox' ]
141- last_offset = app11_headers [header_number ]['offset' ]
142- print ('Last Le: {0}, En: {1}, Z: {2}, LBox: {3}, TBox: {4}, offset: {5}' .format (
143- last_le , last_en , last_z , last_lbox , last_tbox , last_offset ))
144145
145146 # re-construct Claim Block payload
146147 claim_block_payload = bytearray ()
@@ -149,93 +150,19 @@ def main():
149150 payload_end = payload_start + (app11_headers [i ]['le' ] - 18 )
150151 payload = raw_bytes [payload_start : payload_end ]
151152 claim_block_payload += payload
152- print ('Claim Block payload size (Description/Content Boxes): {}' .format (len (claim_block_payload )))
153-
154- print ('Claim Block' )
155- print ('\t Superbox' )
156- print ('\t \t LBox: {0}, TBox: {1}' .format (last_lbox , last_tbox ))
157-
158- print ('\t Description Box' )
159- offset_d = 0
160- lbox_d = int .from_bytes (claim_block_payload [offset_d : offset_d + 4 ], byteorder = 'big' )
161- tbox_d = claim_block_payload [offset_d + 4 : offset_d + 8 ].decode ('utf-8' )
162- print ('\t \t offset: {}' .format (offset_d ))
163- print ('\t \t LBox: {0}, TBox: {1}' .format (lbox_d , tbox_d ))
164- print ('\t \t Type: {}' .format (claim_block_payload [offset_d + 8 : offset_d + 24 ].hex ()))
165- print ('\t \t Toggles: {}' .format (claim_block_payload [offset_d + 24 : offset_d + 25 ].hex ()))
166- print ('\t \t Label: {}' .format (claim_block_payload [offset_d + 25 : lbox_d ].decode ('utf-8' )))
167-
168- print ('\t Content Box (Stores)' )
169- print ('\t \t Store #1' )
170- print ('\t \t Superbox' )
171- offset_s = lbox_d
172- lbox_s = int .from_bytes (claim_block_payload [offset_s : offset_s + 4 ], byteorder = 'big' )
173- tbox_s = claim_block_payload [offset_s + 4 : offset_s + 8 ].decode ('utf-8' )
174- print ('\t \t \t offset: {}' .format (offset_s ))
175- print ('\t \t \t LBox: {0}, TBox: {1}' .format (lbox_s , tbox_s ))
176- print ('\t \t Description Box' )
177- offset_d = offset_s + 8
178- lbox_d = int .from_bytes (claim_block_payload [offset_d : offset_d + 4 ], byteorder = 'big' )
179- tbox_d = claim_block_payload [offset_d + 4 : offset_d + 8 ].decode ('utf-8' )
180- print ('\t \t \t offset: {}' .format (offset_d ))
181- print ('\t \t \t LBox: {0}, TBox: {1}' .format (lbox_d , tbox_d ))
182- print ('\t \t \t Type: {}' .format (claim_block_payload [offset_d + 8 : offset_d + 24 ].hex ()))
183- print ('\t \t \t Toggles: {}' .format (claim_block_payload [offset_d + 24 : offset_d + 25 ].hex ()))
184- print ('\t \t \t Label: {}' .format (claim_block_payload [offset_d + 25 : offset_d + lbox_d ].decode ('utf-8' )))
185- print ('\t \t Content Box' )
186- offset_c = offset_d + lbox_d
187- lbox_c = int .from_bytes (claim_block_payload [offset_c : offset_c + 4 ], byteorder = 'big' )
188- tbox_c = claim_block_payload [offset_c + 4 : offset_c + 8 ].decode ('utf-8' )
189- print ('\t \t \t offset: {}' .format (offset_c ))
190- print ('\t \t \t LBox: {0}, TBox: {1}' .format (lbox_c , tbox_c ))
191- print ('\t \t \t Type: {}' .format (claim_block_payload [offset_c + 8 : offset_c + 24 ].hex ()))
192-
193- print ('\t \t Store #2' )
194- print ('\t \t Superbox' )
195- offset_s = offset_s + lbox_s
196- lbox_s = int .from_bytes (claim_block_payload [offset_s : offset_s + 4 ], byteorder = 'big' )
197- tbox_s = claim_block_payload [offset_s + 4 : offset_s + 8 ].decode ('utf-8' )
198- print ('\t \t \t offset: {}' .format (offset_s ))
199- print ('\t \t \t LBox: {0}, TBox: {1}' .format (lbox_s , tbox_s ))
200- print ('\t \t Description Box' )
201- offset_d = offset_s + 8
202- lbox_d = int .from_bytes (claim_block_payload [offset_d : offset_d + 4 ], byteorder = 'big' )
203- tbox_d = claim_block_payload [offset_d + 4 : offset_d + 8 ].decode ('utf-8' )
204- print ('\t \t \t offset: {}' .format (offset_d ))
205- print ('\t \t \t LBox: {0}, TBox: {1}' .format (lbox_d , tbox_d ))
206- print ('\t \t \t Type: {}' .format (claim_block_payload [offset_d + 8 : offset_d + 24 ].hex ()))
207- print ('\t \t \t Toggles: {}' .format (claim_block_payload [offset_d + 24 : offset_d + 25 ].hex ()))
208- print ('\t \t \t Label: {}' .format (claim_block_payload [offset_d + 25 : offset_d + lbox_d ].decode ('utf-8' )))
209-
210- print ('\t \t Store #3 (newly created)' )
211- print ('\t \t Superbox' )
212153 store_bytes = cai_store .convert_bytes ()
213- offset_s = 0
214- lbox_s = int .from_bytes (store_bytes [offset_s : offset_s + 4 ], byteorder = 'big' )
215- tbox_s = store_bytes [offset_s + 4 : offset_s + 8 ].decode ('utf-8' )
216- print ('\t \t \t offset: {}' .format (offset_s ))
217- print ('\t \t \t LBox: {0}, TBox: {1}' .format (lbox_s , tbox_s ))
218- print ('\t \t Description Box' )
219- offset_d = offset_s + 8
220- lbox_d = int .from_bytes (store_bytes [offset_d : offset_d + 4 ], byteorder = 'big' )
221- tbox_d = store_bytes [offset_d + 4 : offset_d + 8 ].decode ('utf-8' )
222- print ('\t \t \t LBox: {0}, TBox: {1}' .format (lbox_d , tbox_d ))
223- print ('\t \t \t Type: {}' .format (store_bytes [offset_d + 8 : offset_d + 24 ].hex ()))
224- print ('\t \t \t Toggles: {}' .format (store_bytes [offset_d + 24 : offset_d + 25 ].hex ()))
225- print ('\t \t \t Label: {}' .format (store_bytes [offset_d + 25 : offset_d + lbox_d ].decode ('utf-8' )))
226154
227155 # append new Store bytes
228156 updated_claim_block_payload = claim_block_payload + store_bytes
229157 updated_lbox = last_lbox + len (store_bytes )
230- #updated_tbox = last_tbox
231158 updated_claim_block_bytes = updated_lbox .to_bytes (4 , byteorder = 'big' ) + b'jumb' + updated_claim_block_payload
232159 updated_app11_segment = App11Box (en = last_en )
233160 updated_app11_segment .payload = updated_claim_block_bytes
234161
235162 update_range_s = app11_headers [1 ]['offset' ]
236163 update_range_e = app11_headers [1 ]['offset' ] + last_lbox + 16
237- print ('Update range: {0} - {1}' .format (update_range_s , update_range_e ))
238164
165+ # save CAI-injected media
239166 if len (args .inject ) > 0 :
240167 fname , fext = os .path .splitext (args .inject )
241168 fpath = fname + '-cai' + fext
@@ -244,13 +171,20 @@ def main():
244171 cai_data_bytes = insert_xmp_key (data_bytes , store_label = store_label )
245172 f .write (cai_data_bytes )
246173 else :
174+ # create a new Store
175+ cai_store = CaiStore (label = store_label ,
176+ assertions = assertions ,
177+ recorder = recorder ,
178+ parent_claim = parent_claim ,
179+ key = key )
180+
247181 # create a new Claim Block Box
248182 cai_claim_block = CaiClaimBlock ()
249183 cai_claim_block .content_boxes .append (cai_store )
250184 cai_segment = App11Box ()
251185 cai_segment .payload = cai_claim_block .convert_bytes ()
252186
253- # inject CAI metadata
187+ # save CAI-injected media
254188 if len (args .inject ) > 0 :
255189 fname , fext = os .path .splitext (args .inject )
256190 fpath = fname + '-cai' + fext
@@ -259,12 +193,10 @@ def main():
259193 cai_data_bytes = insert_xmp_key (data_bytes , store_label = store_label )
260194 f .write (cai_data_bytes )
261195
262- # output CAI metadata
263- #if len(args.output) == 0:
264- # print(cai_segment.convert_bytes().hex())
265- #else:
266- # with open(args.output, 'w') as f:
267- # f.write(cai_segment.convert_bytes().hex())
196+ # save CAI metadata
197+ if len (args .output ) > 0 :
198+ with open (args .output , 'w' ) as f :
199+ f .write (cai_segment .convert_bytes ().hex ())
268200
269201
270202if __name__ == "__main__" :
0 commit comments