1 from Components.config import config, ConfigSubsection, ConfigSubList, ConfigInteger, ConfigText, ConfigSelection, getConfigListEntry, ConfigSequence, ConfigYesNo
4 class ConfigFixedText(ConfigText):
5 def __init__(self, text, visible_width=60):
6 ConfigText.__init__(self, default = text, fixed_size = True, visible_width = visible_width)
7 def handleKey(self, key):
11 def __init__(self, project):
12 self.properties = ConfigSubsection()
13 self.properties.menutitle = ConfigText(fixed_size = False, visible_width = 80)
14 self.properties.menusubtitle = ConfigText(fixed_size = False, visible_width = 80)
15 self.properties.aspect = ConfigSelection(choices = [("4:3", _("4:3")), ("16:9", _("16:9"))])
16 self.properties.widescreen = ConfigSelection(choices = [("nopanscan", "nopanscan"), ("noletterbox", "noletterbox")])
17 self.properties.autochapter = ConfigInteger(default = 0, limits = (0, 60))
18 self.properties.audiotracks = ConfigSubList()
19 self.DVBname = _("Title")
20 self.DVBdescr = _("Description")
21 self.DVBchannel = _("Channel")
25 self.estimatedDiskspace = 0
28 self.chaptermarks = [ ]
29 self.timeCreate = None
31 self.project = project
34 def addService(self, service):
36 from enigma import eServiceCenter, iServiceInformation
37 from ServiceReference import ServiceReference
38 from time import localtime, time
40 serviceHandler = eServiceCenter.getInstance()
41 info = serviceHandler.info(service)
42 sDescr = info and info.getInfoString(service, iServiceInformation.sDescription) or ""
43 self.DVBdescr = sDescr
44 sTimeCreate = info.getInfo(service, iServiceInformation.sTimeCreate)
46 self.timeCreate = localtime(sTimeCreate)
47 serviceref = ServiceReference(info.getInfoString(service, iServiceInformation.sServiceref))
48 name = info and info.getName(service) or "Title" + sDescr
50 self.DVBchannel = serviceref.getServiceName()
51 self.inputfile = service.getPath()
52 self.filesize = path.getsize(self.inputfile)
53 self.estimatedDiskspace = self.filesize
54 self.length = info.getLength(service)
56 def addFile(self, filename):
57 from enigma import eServiceReference
58 ref = eServiceReference(1, 0, filename)
60 self.project.session.openWithCallback(self.titleEditDone, TitleCutter.CutlistReader, self)
62 def titleEditDone(self, cutlist):
63 self.initDVDmenuText(len(self.project.titles))
64 self.cuesheet = cutlist
65 self.produceFinalCuesheet()
67 def initDVDmenuText(self, track):
68 s = self.project.menutemplate.settings
69 self.properties.menutitle.setValue(self.formatDVDmenuText(s.titleformat.getValue(), track))
70 self.properties.menusubtitle.setValue(self.formatDVDmenuText(s.subtitleformat.getValue(), track))
72 def formatDVDmenuText(self, template, track):
73 template = template.replace("$i", str(track))
74 template = template.replace("$t", self.DVBname)
75 template = template.replace("$d", self.DVBdescr)
76 template = template.replace("$c", str(len(self.chaptermarks)+1))
77 template = template.replace("$f", self.inputfile)
78 template = template.replace("$C", self.DVBchannel)
80 #if template.find("$A") >= 0:
81 from TitleProperties import languageChoices
83 for audiotrack in self.properties.audiotracks:
84 active = audiotrack.active.getValue()
86 trackstring = audiotrack.format.getValue()
87 language = audiotrack.language.getValue()
88 if languageChoices.langdict.has_key(language):
89 trackstring += ' (' + languageChoices.langdict[language] + ')'
90 audiolist.append(trackstring)
91 audiostring = ', '.join(audiolist)
92 template = template.replace("$A", audiostring)
94 if template.find("$l") >= 0:
96 lengthstring = "%d:%02d:%02d" % (l/3600, l%3600/60, l%60)
97 template = template.replace("$l", lengthstring)
99 template = template.replace("$Y", str(self.timeCreate[0]))
100 template = template.replace("$M", str(self.timeCreate[1]))
101 template = template.replace("$D", str(self.timeCreate[2]))
102 timestring = "%d:%02d" % (self.timeCreate[3], self.timeCreate[4])
103 template = template.replace("$T", timestring)
105 template = template.replace("$Y", "").replace("$M", "").replace("$D", "").replace("$T", "")
108 def produceFinalCuesheet(self):
119 self.chaptermarks = [ ]
121 # our demuxer expects *strictly* IN,OUT lists.
122 currently_in = not any(type == CUT_TYPE_IN for pts, type in self.cuesheet)
124 self.cutlist.append(0) # emulate "in" at first
126 for (pts, type) in self.cuesheet:
127 #print "pts=", pts, "type=", type, "accumulated_in=", accumulated_in, "accumulated_at=", accumulated_at, "last_in=", last_in
128 if type == CUT_TYPE_IN and not currently_in:
129 self.cutlist.append(pts)
133 if type == CUT_TYPE_OUT and currently_in:
134 self.cutlist.append(pts)
136 # accumulate the segment
137 accumulated_in += pts - last_in
141 if type == CUT_TYPE_MARK and currently_in:
142 # relocate chaptermark against "in" time. This is not 100% accurate,
143 # as the in/out points are not.
144 reloc_pts = pts - last_in + accumulated_in
145 self.chaptermarks.append(reloc_pts)
147 if len(self.cutlist) > 1:
148 part = accumulated_in / (self.length*90000.0)
149 usedsize = int ( part * self.filesize )
150 self.estimatedDiskspace = usedsize
151 self.length = accumulated_in / 90000
153 def getChapterMarks(self, template="$h:$m:$s.$t"):
156 minutes = self.properties.autochapter.getValue()
157 if len(self.chaptermarks) < 1 and minutes > 0:
159 while chapterpts < (self.length-60*minutes)*90000:
160 chapterpts += 90000 * 60 * minutes
161 chapters.append(chapterpts)
163 chapters = self.chaptermarks
165 timestring = template.replace("$h", str(p / (90000 * 3600)))
166 timestring = timestring.replace("$m", ("%02d" % (p % (90000 * 3600) / (90000 * 60))))
167 timestring = timestring.replace("$s", ("%02d" % (p % (90000 * 60) / 90000)))
168 timestring = timestring.replace("$t", ("%03d" % ((p % 90000) / 90)))
169 timestamps.append(timestring)