<s> """<STR_LIT>""" <EOL> from . structops import str_to_uint32 , uint32_to_str <EOL> class MP4FilterError ( BaseException ) : <EOL> "<STR_LIT>" <EOL> class MP4Filter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , filename = None , data = None ) : <EOL> self . filename = filename <EOL> if filename is not None : <EOL> self . data = open ( filename , "<STR_LIT:rb>" ) . read ( ) <EOL> else : <EOL> self . data = data <EOL> self . emsg = None <EOL> self . output = "<STR_LIT>" <EOL> self . top_level_boxes_to_parse = [ ] <EOL> self . composite_boxes_to_parse = [ ] <EOL> self . next_phase_data = { } <EOL> self . nr_iterations_done = <NUM_LIT:0> <EOL> def check_box ( self , data ) : <EOL> "<STR_LIT>" <EOL> size = str_to_uint32 ( data [ : <NUM_LIT:4> ] ) <EOL> boxtype = data [ <NUM_LIT:4> : <NUM_LIT:8> ] <EOL> return ( size , boxtype ) <EOL> def filter ( self ) : <EOL> "<STR_LIT>" <EOL> self . output = "<STR_LIT>" <EOL> pos = <NUM_LIT:0> <EOL> while pos < len ( self . data ) : <EOL> size , boxtype = self . check_box ( self . data [ pos : pos + <NUM_LIT:8> ] ) <EOL> boxdata = self . data [ pos : pos + size ] <EOL> if boxtype in self . top_level_boxes_to_parse : <EOL> self . output += self . filter_box ( boxtype , boxdata , len ( self . output ) ) <EOL> else : <EOL> self . output += boxdata <EOL> pos += size <EOL> if self . next_phase_data : <EOL> self . nr_iterations_done += <NUM_LIT:1> <EOL> self . data = self . output <EOL> self . output = self . filter ( ) <EOL> self . finalize ( ) <EOL> return self . output <EOL> def filter_box ( self , boxtype , data , file_pos , path = "<STR_LIT>" ) : <EOL> "<STR_LIT>" <EOL> if boxtype == "<STR_LIT>" : <EOL> self . moof_start = file_pos <EOL> elif boxtype == "<STR_LIT>" : <EOL> self . mdat_start = file_pos <EOL> if path == "<STR_LIT>" : <EOL> path = boxtype <EOL> else : <EOL> path = "<STR_LIT>" % ( path , boxtype ) <EOL> if boxtype in self . composite_boxes_to_parse : <EOL> output = data [ : <NUM_LIT:8> ] <EOL> pos = <NUM_LIT:8> <EOL> while pos < len ( data ) : <EOL> child_size , child_box_type = self . check_box ( data [ pos : pos + <NUM_LIT:8> ] ) <EOL> output_child_box = self . filter_box ( child_box_type , data [ pos : pos + child_size ] , file_pos + pos , path ) <EOL> output += output_child_box <EOL> pos += child_size <EOL> if len ( output ) != len ( data ) : <EOL> output = uint32_to_str ( len ( output ) ) + output [ <NUM_LIT:4> : ] <EOL> else : <EOL> method_name = "<STR_LIT>" % boxtype <EOL> method = getattr ( self , method_name , None ) <EOL> if method is not None : <EOL> output = method ( data ) <EOL> else : <EOL> output = data <EOL> return output <EOL> def finalize ( self ) : <EOL> "<STR_LIT>" <EOL> pass </s>
