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