#if 0 # $Id: riffinfo.py,v 1.33 2005/03/15 17:50:45 dischi Exp $ # $Log: riffinfo.py,v $ # Revision 1.33 2005/03/15 17:50:45 dischi # check for corrupt avi # # Revision 1.32 2005/03/04 17:41:29 dischi # handle broken avi files # # Revision 1.31 2004/12/13 10:19:07 dischi # more debug, support LIST > 20000 (new max is 80000) # # Revision 1.30 2004/08/25 16:18:14 dischi # detect aspect ratio # # Revision 1.29 2004/05/24 16:17:09 dischi # Small changes for future updates # # Revision 1.28 2004/01/31 12:23:46 dischi # remove bad chars from table (e.g. char 0 is True) # # Revision 1.27 2003/10/04 14:30:08 dischi # add audio delay for avi # # Revision 1.26 2003/07/10 11:18:11 the_krow # few more attributes added # # Revision 1.25 2003/07/07 21:36:44 dischi # make fps a float and round it to two digest after the comma # # Revision 1.24 2003/07/05 19:36:37 the_krow # length fixed # fps introduced # # Revision 1.23 2003/07/02 11:17:30 the_krow # language is now part of the table key # # Revision 1.22 2003/07/01 21:06:50 dischi # no need to import factory (and when, use "from mmpython import factory" # # Revision 1.21 2003/06/30 13:17:20 the_krow # o Refactored mediainfo into factory, synchronizedobject # o Parsers now register directly at mmpython not at mmpython.mediainfo # o use mmpython.Factory() instead of mmpython.mediainfo.get_singleton() # o Bugfix in PNG parser # o Renamed disc.AudioInfo into disc.AudioDiscInfo # o Renamed disc.DataInfo into disc.DataDiscInfo # # Revision 1.20 2003/06/23 20:48:11 the_krow # width + height fixes for OGM files # # Revision 1.19 2003/06/23 20:38:04 the_krow # Support for larger LIST chunks because some files did not work. # # Revision 1.18 2003/06/20 19:17:22 dischi # remove filename again and use file.name # # Revision 1.17 2003/06/20 19:05:56 dischi # scan for subtitles # # Revision 1.16 2003/06/20 15:29:42 the_krow # Metadata Mapping # # Revision 1.15 2003/06/20 14:43:57 the_krow # Putting Metadata into MediaInfo from AVIInfo Table # # Revision 1.14 2003/06/09 16:10:52 dischi # error handling # # Revision 1.13 2003/06/08 19:53:21 dischi # also give the filename to init for additional data tests # # Revision 1.12 2003/06/08 13:44:58 dischi # Changed all imports to use the complete mmpython path for mediainfo # # Revision 1.11 2003/06/08 13:11:38 dischi # removed print at the end and moved it into register # # Revision 1.10 2003/06/07 23:10:50 the_krow # Changed mp3 into new format. # # Revision 1.9 2003/06/07 22:30:22 the_krow # added new avinfo structure # # Revision 1.8 2003/06/07 21:48:47 the_krow # Added Copying info # started changing riffinfo to new AV stuff # # Revision 1.7 2003/05/13 12:31:43 the_krow # + Copyright Notice # # # MMPython - Media Metadata for Python # Copyright (C) 2003 Thomas Schueppel, Dirk Meyer # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MER- # CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # ----------------------------------------------------------------------- #endif import re import struct import string import fourcc # import factory import mmpython from mmpython import mediainfo # List of tags # http://kibus1.narod.ru/frames_eng.htm?sof/abcavi/infotags.htm # http://www.divx-digest.com/software/avitags_dll.html # File Format # http://www.taenam.co.kr/pds/documents/odmlff2.pdf _print = mediainfo._debug AVIINFO_tags = { 'title': 'INAM', 'artist': 'IART', 'product': 'IPRD', 'date': 'ICRD', 'comment': 'ICMT', 'language': 'ILNG', 'keywords': 'IKEY', 'trackno': 'IPRT', 'trackof': 'IFRM', 'producer': 'IPRO', 'writer': 'IWRI', 'genre': 'IGNR', 'copyright': 'ICOP', 'trackno': 'IPRT', 'trackof': 'IFRM', 'comment': 'ICMT', } class RiffInfo(mediainfo.AVInfo): def __init__(self,file): mediainfo.AVInfo.__init__(self) # read the header h = file.read(12) if h[:4] != "RIFF" and h[:4] != 'SDSS': self.valid = 0 return self.valid = 1 self.mime = 'application/x-wave' self.has_idx = False self.header = {} self.junkStart = None self.infoStart = None self.type = h[8:12] self.tag_map = { ('AVIINFO', 'en') : AVIINFO_tags } if self.type == 'AVI ': self.mime = 'video/avi' elif self.type == 'WAVE': self.mime = 'application/x-wave' try: while self.parseRIFFChunk(file): pass except IOError: if mediainfo.DEBUG: print 'error in file, stop parsing' self.find_subtitles(file.name) # Copy Metadata from tables into the main set of attributes for k in self.tag_map.keys(): map(lambda x:self.setitem(x,self.gettable(k[0],k[1]),self.tag_map[k][x]), self.tag_map[k].keys()) if not self.has_idx: _print('WARNING: avi has no index') self.corrupt = 1 self.keys.append('corrupt') def _extractHeaderString(self,h,offset,len): return h[offset:offset+len] def parseAVIH(self,t): retval = {} v = struct.unpack('> 16) / (r & 0xFFFF) retval['FrameAspectRatio'] = r if self.video: map(lambda v: setattr(v, 'aspect', r), self.video) return ( retval, v[0] ) def parseLIST(self,t): retval = {} i = 0 size = len(t) while i < size-8: # skip zero if ord(t[i]) == 0: i += 1 key = t[i:i+4] sz = 0 if key == 'LIST': sz = struct.unpack(' SUBLIST: len: %d, %d" % ( sz, i+4 )) i+=8 key = "LIST:"+t[i:i+4] value = self.parseLIST(t[i:i+sz]) _print("<-") if key == 'strl': for k in value.keys(): retval[k] = value[k] else: retval[key] = value i+=sz elif key == 'avih': _print("SUBAVIH") sz = struct.unpack(' self.junkSize - 8 ): raise "Too large" file.write( "LIST" + struct.pack('