[Pyparsing] Dealing with blocks in different order
Brought to you by:
ptmcg
From: mlist @dslextreme.c. <ml...@ds...> - 2015-04-20 19:37:22
|
I have everything I need to parse a file defined, but I am running in to a problem. The main part of the file consists of different blocks (see below) and the blocks can be in different order or not even there. I am not sure how to deal with this. For example, it could be [video block] [audio block] or [audio block] [video block] or [video block] [audio block] [audio block] or any permutation of the above. Here is the sample text Track ID 1 soun (Audio) Enabled Not self-contained Format soun/aac 48000 Hz aac FormatFlags: 0x00000000 Bytes/Pkt: 0 Frames/Pkt: 1024 Bytes/Frame: 0 Chan/Frame: 2 Bits/Chan: 0 Reserved: 0x00000000 ChannelLayout: Stereo (L R) Media Timescale: 48000 Duration: 240640/48000 00:00:05.013 MinSampleDuration: 1024/48000 AdvanceDecodeDelta: 0/48000 00:00:00.000 Num data bytes: 80213 Est. data rate: 127.999 kbps Nominal framerate: 46.875 fps 235 samples Track volume: 1 Included in auto selection. Language code <und> Dimensions: 0 x 0 Track Matrix: 1.0 0.0 0.0 / 0.0 1.0 0.0 / 0.0 0.0 1.0 1 edit: Media start 0/48000 00:00:00.000 dur 3000/600 00:00:05.000 Track start 0/600 00:00:00.000 dur 3000/600 00:00:05.000 Track ID 2 vide (Video) Enabled Not self-contained Format vide/avc1 dimensions: video 1920 x 1080, presentation: 1920 x 1080 (pixelAspect+clean), cleanAperture: 1920 x 1080 @ 0,0 (originTopLeft) Media Timescale: 600 Duration: 3003/600 00:00:05.005 MinSampleDuration: 20/600 AdvanceDecodeDelta: 21/600 00:00:00.035 Num data bytes: 6555892 Est. data rate: 10.479 Mbps Nominal framerate: 29.970 fps 150 samples Frame Reordering Required Included in auto selection. Language code <und> Dimensions: 1920 x 1080 CleanAperture: 1920 x 1080 ProductionAperture: 1920 x 1080 EncodedPixels: 1920 x 1080 Track Matrix: 1.0 0.0 0.0 / 0.0 1.0 0.0 / 0.0 0.0 1.0 1 edit: Media start 0/600 00:00:00.000 dur 3000/600 00:00:05.000 Track start 0/600 00:00:00.000 dur 3000/600 00:00:05.000 And here is what my code looks like: # Audio Block self.audio_track_info = Group( self.track_id + self.audio_track_format + self.channel_layout + self.media_timescale + self.track_data + self.audio_track_volume + self.included + self.audio_track_dimensions + OneOrMore(self.edits).setResultsName('edits')).setResultsName('audio_track') # Video Block self.video_track_info = Group(self.track_id + self.video_track_format + self.media_timescale + self.track_data + self.included + self.video_track_dimensions + OneOrMore(self.edits).setResultsName('edits')).setResultsName('video_track') self.tracks = Group(ZeroOrMore(self.video_track_info)) + Group(ZeroOrMore(self.audio_track_info)).setResultsName('tracks') I am using parseString on the text and this only returns the audio block and not the video block. How do I fix this? |