1 | #if 0 /* |
---|
2 | # ----------------------------------------------------------------------- |
---|
3 | # vcdinfo.py - parse vcd track informations from cue/bin files |
---|
4 | # ----------------------------------------------------------------------- |
---|
5 | # $Id: vcdinfo.py,v 1.7 2004/06/25 13:20:34 dischi Exp $ |
---|
6 | # |
---|
7 | # $Log: vcdinfo.py,v $ |
---|
8 | # Revision 1.7 2004/06/25 13:20:34 dischi |
---|
9 | # FreeBSD patches |
---|
10 | # |
---|
11 | # Revision 1.6 2003/06/30 13:17:20 the_krow |
---|
12 | # o Refactored mediainfo into factory, synchronizedobject |
---|
13 | # o Parsers now register directly at mmpython not at mmpython.mediainfo |
---|
14 | # o use mmpython.Factory() instead of mmpython.mediainfo.get_singleton() |
---|
15 | # o Bugfix in PNG parser |
---|
16 | # o Renamed disc.AudioInfo into disc.AudioDiscInfo |
---|
17 | # o Renamed disc.DataInfo into disc.DataDiscInfo |
---|
18 | # |
---|
19 | # Revision 1.5 2003/06/29 11:59:55 dischi |
---|
20 | # bugfix |
---|
21 | # |
---|
22 | # Revision 1.4 2003/06/20 19:17:22 dischi |
---|
23 | # remove filename again and use file.name |
---|
24 | # |
---|
25 | # Revision 1.3 2003/06/10 11:17:39 the_krow |
---|
26 | # - OGG Fixes |
---|
27 | # - changed one DiscInfo reference in vcdinfo I missed before |
---|
28 | # |
---|
29 | # Revision 1.2 2003/06/10 10:56:54 the_krow |
---|
30 | # - Build try-except blocks around disc imports to make it run on platforms |
---|
31 | # not compiling / running the C extensions. |
---|
32 | # - moved DiscInfo class to disc module |
---|
33 | # - changed video.VcdInfo to be derived from CollectionInfo instead of |
---|
34 | # DiskInfo so it can be used without the cdrom extensions which are |
---|
35 | # hopefully not needed for bin-files. |
---|
36 | # |
---|
37 | # Revision 1.1 2003/06/09 16:09:18 dischi |
---|
38 | # first version of a cue/bin vcd parser |
---|
39 | # |
---|
40 | # |
---|
41 | # ----------------------------------------------------------------------- |
---|
42 | # Copyright (C) 2003 Thomas Schueppel, Dirk Meyer |
---|
43 | # |
---|
44 | # This program is free software; you can redistribute it and/or modify |
---|
45 | # it under the terms of the GNU General Public License as published by |
---|
46 | # the Free Software Foundation; either version 2 of the License, or |
---|
47 | # (at your option) any later version. |
---|
48 | # |
---|
49 | # This program is distributed in the hope that it will be useful, but |
---|
50 | # WITHOUT ANY WARRANTY; without even the implied warranty of MER- |
---|
51 | # CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
52 | # Public License for more details. |
---|
53 | # |
---|
54 | # You should have received a copy of the GNU General Public License along |
---|
55 | # with this program; if not, write to the Free Software Foundation, Inc., |
---|
56 | # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
57 | # |
---|
58 | # ----------------------------------------------------------------------- */ |
---|
59 | #endif |
---|
60 | |
---|
61 | |
---|
62 | from mmpython import mediainfo |
---|
63 | import mmpython |
---|
64 | import os |
---|
65 | |
---|
66 | class VCDInfo(mediainfo.CollectionInfo): |
---|
67 | def __init__(self, file): |
---|
68 | mediainfo.CollectionInfo.__init__(self) |
---|
69 | self.context = 'video' |
---|
70 | self.offset = 0 |
---|
71 | self.valid = self.isVCD(file) |
---|
72 | self.mime = 'video/vcd' |
---|
73 | self.type = 'vcd video' |
---|
74 | |
---|
75 | def isVCD(self, file): |
---|
76 | type = None |
---|
77 | |
---|
78 | buffer = file.readline() |
---|
79 | |
---|
80 | if not buffer[:6] == 'FILE "': |
---|
81 | return 0 |
---|
82 | |
---|
83 | bin = os.path.join(os.path.dirname(file.name), buffer[6:buffer[6:].find('"')+6]) |
---|
84 | if not os.path.isfile(bin): |
---|
85 | return 0 |
---|
86 | |
---|
87 | # At this point this really is a cue/bin disc |
---|
88 | |
---|
89 | # brute force reading of the bin to find out if it is a VCD |
---|
90 | f = open(bin,'rb') |
---|
91 | f.seek(32768, 0) |
---|
92 | buffer = f.read(60000) |
---|
93 | f.close() |
---|
94 | |
---|
95 | if buffer.find('SVCD') > 0 and buffer.find('TRACKS.SVD') > 0 and \ |
---|
96 | buffer.find('ENTRIES.SVD') > 0: |
---|
97 | type = 'SVCD' |
---|
98 | |
---|
99 | elif buffer.find('INFO.VCD') > 0 and buffer.find('ENTRIES.VCD') > 0: |
---|
100 | type = 'VCD' |
---|
101 | |
---|
102 | else: |
---|
103 | return 0 |
---|
104 | |
---|
105 | counter = 0 |
---|
106 | while 1: |
---|
107 | buffer = file.readline() |
---|
108 | if not len(buffer): |
---|
109 | return 1 |
---|
110 | if buffer[:8] == ' TRACK ': |
---|
111 | counter += 1 |
---|
112 | # the first track is the directory, that doesn't count |
---|
113 | if counter > 1: |
---|
114 | vi = mediainfo.VideoInfo() |
---|
115 | if type == 'VCD': |
---|
116 | vi.codec = 'MPEG1' |
---|
117 | else: |
---|
118 | vi.codec = 'MPEG2' |
---|
119 | self.tracks.append(vi) |
---|
120 | |
---|
121 | |
---|
122 | mmpython.registertype( 'video/vcd', ('cue',), mediainfo.TYPE_AV, VCDInfo ) |
---|