additional service information for DVD menu and fixes
[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.timeCreate = None
13
14         def addService(self, service):
15                 from os import path
16                 from enigma import eServiceCenter, iServiceInformation
17                 from ServiceReference import ServiceReference
18                 from time import localtime, time
19                 self.source = service
20                 serviceHandler = eServiceCenter.getInstance()
21                 info = serviceHandler.info(service)
22                 self.descr = info and " " + info.getInfoString(service, iServiceInformation.sDescription) or ""
23                 sTimeCreate = info.getInfo(service, iServiceInformation.sTimeCreate)
24                 if sTimeCreate > 1:
25                         self.timeCreate = localtime(sTimeCreate)
26                 serviceref = ServiceReference(info.getInfoString(service, iServiceInformation.sServiceref))
27                 self.name = info and info.getName(service) or "Title" + t.descr
28                 self.channel = serviceref.getServiceName()
29                 self.inputfile = service.getPath()
30                 self.filesize = path.getsize(self.inputfile)
31                 self.estimatedDiskspace = self.filesize
32                 self.length = info.getLength(service)
33
34         def produceFinalCuesheet(self):
35                 print "[produceFinalCuesheet] >>> ", self.inputfile, self.cuesheet
36
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                 print "cutlist =", self.cutlist, "chaptermarks =", self.chaptermarks, "accumulated_in =", accumulated_in
76
77                 if len(self.cutlist) > 1:
78                         part = accumulated_in / (self.length*90000.0)
79                         usedsize = int ( part * self.filesize )
80                         print "part=", part, "filesize=", self.filesize, "estimatedDiskspace=", usedsize
81                         self.estimatedDiskspace = usedsize
82                         self.length = accumulated_in / 90000