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