[4] | 1 | #if 0 |
---|
| 2 | # $Id: realinfo.py,v 1.6 2003/07/02 09:09:41 the_krow Exp $ |
---|
| 3 | # $Log: realinfo.py,v $ |
---|
| 4 | # Revision 1.6 2003/07/02 09:09:41 the_krow |
---|
| 5 | # i18n stuff added to AVI |
---|
| 6 | # some debug outputs removed |
---|
| 7 | # |
---|
| 8 | # Revision 1.5 2003/06/30 13:17:20 the_krow |
---|
| 9 | # o Refactored mediainfo into factory, synchronizedobject |
---|
| 10 | # o Parsers now register directly at mmpython not at mmpython.mediainfo |
---|
| 11 | # o use mmpython.Factory() instead of mmpython.mediainfo.get_singleton() |
---|
| 12 | # o Bugfix in PNG parser |
---|
| 13 | # o Renamed disc.AudioInfo into disc.AudioDiscInfo |
---|
| 14 | # o Renamed disc.DataInfo into disc.DataDiscInfo |
---|
| 15 | # |
---|
| 16 | # Revision 1.4 2003/06/29 11:59:35 dischi |
---|
| 17 | # make some debug silent |
---|
| 18 | # |
---|
| 19 | # Revision 1.3 2003/06/20 19:17:22 dischi |
---|
| 20 | # remove filename again and use file.name |
---|
| 21 | # |
---|
| 22 | # Revision 1.2 2003/06/12 18:53:19 the_krow |
---|
| 23 | # OGM detection added. |
---|
| 24 | # .ram is a valid extension to real files |
---|
| 25 | # |
---|
| 26 | # Revision 1.1 2003/06/12 14:43:22 the_krow |
---|
| 27 | # Realmedia file parsing. Title, Artist, Copyright work. Couldn't find |
---|
| 28 | # many technical parameters to retrieve. |
---|
| 29 | # Some initial QT parsing |
---|
| 30 | # added Real to __init__.py |
---|
| 31 | # |
---|
| 32 | # |
---|
| 33 | # |
---|
| 34 | # MMPython - Media Metadata for Python |
---|
| 35 | # Copyright (C) 2003 Thomas Schueppel |
---|
| 36 | # |
---|
| 37 | # This program is free software; you can redistribute it and/or modify |
---|
| 38 | # it under the terms of the GNU General Public License as published by |
---|
| 39 | # the Free Software Foundation; either version 2 of the License, or |
---|
| 40 | # (at your option) any later version. |
---|
| 41 | # |
---|
| 42 | # This program is distributed in the hope that it will be useful, but |
---|
| 43 | # WITHOUT ANY WARRANTY; without even the implied warranty of MER- |
---|
| 44 | # CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
| 45 | # Public License for more details. |
---|
| 46 | # |
---|
| 47 | # You should have received a copy of the GNU General Public License along |
---|
| 48 | # with this program; if not, write to the Free Software Foundation, Inc., |
---|
| 49 | # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 50 | # |
---|
| 51 | # ----------------------------------------------------------------------- |
---|
| 52 | #endif |
---|
| 53 | |
---|
| 54 | import struct |
---|
| 55 | import string |
---|
| 56 | |
---|
| 57 | from mmpython import mediainfo |
---|
| 58 | import mmpython |
---|
| 59 | |
---|
| 60 | # http://www.pcisys.net/~melanson/codecs/rmff.htm |
---|
| 61 | # http://www.pcisys.net/~melanson/codecs/ |
---|
| 62 | |
---|
| 63 | _print = mediainfo._debug |
---|
| 64 | |
---|
| 65 | class RealInfo(mediainfo.AVInfo): |
---|
| 66 | def __init__(self,file): |
---|
| 67 | mediainfo.AVInfo.__init__(self) |
---|
| 68 | self.context = 'video' |
---|
| 69 | self.valid = 0 |
---|
| 70 | self.mime = 'video/real' |
---|
| 71 | self.type = 'Real Video' |
---|
| 72 | h = file.read(10) |
---|
| 73 | (object_id,object_size,object_version) = struct.unpack('>4sIH',h) |
---|
| 74 | if object_id == '.RMF': |
---|
| 75 | self.valid = 1 |
---|
| 76 | else: |
---|
| 77 | return |
---|
| 78 | file_version, num_headers = struct.unpack('>II', file.read(8)) |
---|
| 79 | _print("size: %d, ver: %d, headers: %d" % (object_size, file_version,num_headers)) |
---|
| 80 | for i in range(0,num_headers): |
---|
| 81 | (object_id,object_size,object_version) = struct.unpack('>4sIH',file.read(10)) |
---|
| 82 | self._read_header(object_id, file.read(object_size-10)) |
---|
| 83 | _print("%s [%d]" % (object_id,object_size-10)) |
---|
| 84 | # Read all the following headers |
---|
| 85 | |
---|
| 86 | def _read_header(self,object_id,s): |
---|
| 87 | if object_id == 'PROP': |
---|
| 88 | prop = struct.unpack('>9IHH', s) |
---|
| 89 | _print(prop) |
---|
| 90 | if object_id == 'MDPR': |
---|
| 91 | mdpr = struct.unpack('>H7I', s[:30]) |
---|
| 92 | _print(mdpr) |
---|
| 93 | self.length = mdpr[7]/1000 |
---|
| 94 | (stream_name_size,) = struct.unpack('>B', s[30:31]) |
---|
| 95 | stream_name = s[31:31+stream_name_size] |
---|
| 96 | pos = 31+stream_name_size |
---|
| 97 | (mime_type_size,) = struct.unpack('>B', s[pos:pos+1]) |
---|
| 98 | mime = s[pos+1:pos+1+mime_type_size] |
---|
| 99 | pos += mime_type_size+1 |
---|
| 100 | (type_specific_len,) = struct.unpack('>I', s[pos:pos+4]) |
---|
| 101 | type_specific = s[pos+4:pos+4+type_specific_len] |
---|
| 102 | pos += 4+type_specific_len |
---|
| 103 | if mime[:5] == 'audio': |
---|
| 104 | ai = mediainfo.AudioInfo() |
---|
| 105 | ai.id = mdpr[0] |
---|
| 106 | ai.bitrate = mdpr[2] |
---|
| 107 | self.audio.append(ai) |
---|
| 108 | elif mime[:5] == 'video': |
---|
| 109 | vi = mediainfo.VideoInfo() |
---|
| 110 | vi.id = mdpr[0] |
---|
| 111 | vi.bitrate = mdpr[2] |
---|
| 112 | self.video.append(vi) |
---|
| 113 | else: |
---|
| 114 | _print("Unknown: %s" % mime) |
---|
| 115 | if object_id == 'CONT': |
---|
| 116 | pos = 0 |
---|
| 117 | (title_len,) = struct.unpack('>H', s[pos:pos+2]) |
---|
| 118 | self.title = s[2:title_len+2] |
---|
| 119 | pos += title_len+2 |
---|
| 120 | (author_len,) = struct.unpack('>H', s[pos:pos+2]) |
---|
| 121 | self.artist = s[pos+2:pos+author_len+2] |
---|
| 122 | pos += author_len+2 |
---|
| 123 | (copyright_len,) = struct.unpack('>H', s[pos:pos+2]) |
---|
| 124 | self.copyright = s[pos+2:pos+copyright_len+2] |
---|
| 125 | pos += copyright_len+2 |
---|
| 126 | (comment_len,) = struct.unpack('>H', s[pos:pos+2]) |
---|
| 127 | self.comment = s[pos+2:pos+comment_len+2] |
---|
| 128 | |
---|
| 129 | mmpython.registertype( 'video/real', ('rm', 'ra', 'ram'), mediainfo.TYPE_AV, RealInfo ) |
---|