fix possible crash on mediainfo parsing
[enigma2.git] / lib / python / Plugins / Extensions / DVDBurn / DVDTitle.py
1 class DVDTitle:
2         def __init__(self):
3                 self.cuesheet = [ ]
4                 self.source = None
5                 self.name = ""
6                 self.descr = ""
7                 self.filesize = 0
8                 self.estimatedDiskspace = 0
9                 self.inputfile = ""
10                 self.cutlist = [ ]
11                 self.chaptermarks = [ ]
12                 self.audiotracks = [ ]
13                 self.timeCreate = None
14                 self.sVideoType = -1
15
16         def addService(self, service):
17                 from os import path
18                 from enigma import eServiceCenter, iServiceInformation
19                 from ServiceReference import ServiceReference
20                 from time import localtime, time
21                 self.source = service
22                 serviceHandler = eServiceCenter.getInstance()
23                 info = serviceHandler.info(service)
24                 self.descr = info and " " + info.getInfoString(service, iServiceInformation.sDescription) or ""
25                 sTimeCreate = info.getInfo(service, iServiceInformation.sTimeCreate)
26                 if sTimeCreate > 1:
27                         self.timeCreate = localtime(sTimeCreate)
28                 serviceref = ServiceReference(info.getInfoString(service, iServiceInformation.sServiceref))
29                 self.name = info and info.getName(service) or "Title" + t.descr
30                 self.channel = serviceref.getServiceName()
31                 self.inputfile = service.getPath()
32                 self.filesize = path.getsize(self.inputfile)
33                 self.estimatedDiskspace = self.filesize
34                 self.length = info.getLength(service)
35
36         def produceFinalCuesheet(self):
37                 CUT_TYPE_IN = 0
38                 CUT_TYPE_OUT = 1
39                 CUT_TYPE_MARK = 2
40                 CUT_TYPE_LAST = 3
41
42                 accumulated_in = 0
43                 accumulated_at = 0
44                 last_in = 0
45
46                 self.cutlist = [ ]
47                 self.chaptermarks = [ ]
48
49                 # our demuxer expects *strictly* IN,OUT lists.
50                 currently_in = not any(type == CUT_TYPE_IN for pts, type in self.cuesheet)
51                 if currently_in:
52                         self.cutlist.append(0) # emulate "in" at first          
53
54                 for (pts, type) in self.cuesheet:
55                         #print "pts=", pts, "type=", type, "accumulated_in=", accumulated_in, "accumulated_at=", accumulated_at, "last_in=", last_in
56                         if type == CUT_TYPE_IN and not currently_in:
57                                 self.cutlist.append(pts)
58                                 last_in = pts
59                                 currently_in = True
60
61                         if type == CUT_TYPE_OUT and currently_in:
62                                 self.cutlist.append(pts)
63
64                                 # accumulate the segment
65                                 accumulated_in += pts - last_in 
66                                 accumulated_at = pts
67                                 currently_in = False
68
69                         if type == CUT_TYPE_MARK and currently_in:
70                                 # relocate chaptermark against "in" time. This is not 100% accurate,
71                                 # as the in/out points are not.
72                                 reloc_pts = pts - last_in + accumulated_in
73                                 self.chaptermarks.append(reloc_pts)
74                                 
75                 if len(self.cutlist) > 1:
76                         part = accumulated_in / (self.length*90000.0)
77                         usedsize = int ( part * self.filesize )
78                         self.estimatedDiskspace = usedsize
79                         self.length = accumulated_in / 90000
80
81         def produceAutoChapter(self, minutes):
82                 if len(self.chaptermarks) < 1:
83                         chapterpts = self.cutlist[0]
84                         while chapterpts < self.length*90000:
85                                 chapterpts += 90000 * 60 * minutes
86                                 self.chaptermarks.append(chapterpts)