[DVDBurn] usability improvements: title list layout, bottom info area, consistency...
[enigma2.git] / lib / python / Plugins / Extensions / DVDBurn / DVDTitle.py
index 1ada9ce27a3cf1a25c9645e96d365ce515b65927..6dff00d62772c3554b908d7061bae41cf24dcd7f 100644 (file)
@@ -1,4 +1,5 @@
 from Components.config import config, ConfigSubsection, ConfigSubList, ConfigInteger, ConfigText, ConfigSelection, getConfigListEntry, ConfigSequence, ConfigYesNo
+import TitleCutter
 
 class ConfigFixedText(ConfigText):
        def __init__(self, text, visible_width=60):
@@ -6,21 +7,18 @@ class ConfigFixedText(ConfigText):
        def handleKey(self, key):
                pass
 
-class ConfigActiveTrack(ConfigYesNo):
-       def __init__(self, default = True):
-               ConfigYesNo.__init__(self, default)
-
 class DVDTitle:
-       def __init__(self):
+       def __init__(self, project):
                self.properties = ConfigSubsection()
                self.properties.menutitle = ConfigText(fixed_size = False, visible_width = 80)
                self.properties.menusubtitle = ConfigText(fixed_size = False, visible_width = 80)
+               self.properties.aspect = ConfigSelection(choices = [("4:3", _("4:3")), ("16:9", _("16:9"))])
+               self.properties.widescreen = ConfigSelection(choices = [("nopanscan", "nopanscan"), ("noletterbox", "noletterbox")])
+               self.properties.autochapter = ConfigInteger(default = 0, limits = (0, 60))
+               self.properties.audiotracks = ConfigSubList()
                self.DVBname = _("Title")
                self.DVBdescr = _("Description")
                self.DVBchannel = _("Channel")
-               self.properties.aspect = ConfigSelection(choices = [("4:3", "4:3"), ("16:9", "16:9")])
-               self.properties.widescreen = ConfigSelection(choices = [("nopanscan", "nopanscan"), ("noletterbox", "noletterbox")])
-               self.properties.audiotracks = ConfigSubList()
                self.cuesheet = [ ]
                self.source = None
                self.filesize = 0
@@ -30,6 +28,8 @@ class DVDTitle:
                self.chaptermarks = [ ]
                self.timeCreate = None
                self.VideoType = -1
+               self.project = project
+               self.length = 0
 
        def addService(self, service):
                from os import path
@@ -39,7 +39,7 @@ class DVDTitle:
                self.source = service
                serviceHandler = eServiceCenter.getInstance()
                info = serviceHandler.info(service)
-               sDescr = info and " " + info.getInfoString(service, iServiceInformation.sDescription) or ""
+               sDescr = info and info.getInfoString(service, iServiceInformation.sDescription) or ""
                self.DVBdescr = sDescr
                sTimeCreate = info.getInfo(service, iServiceInformation.sTimeCreate)
                if sTimeCreate > 1:
@@ -52,13 +52,24 @@ class DVDTitle:
                self.filesize = path.getsize(self.inputfile)
                self.estimatedDiskspace = self.filesize
                self.length = info.getLength(service)
+                                               
+       def addFile(self, filename):
+               from enigma import eServiceReference
+               ref = eServiceReference(1, 0, filename)
+               self.addService(ref)
+               self.project.session.openWithCallback(self.titleEditDone, TitleCutter.CutlistReader, self)
+       
+       def titleEditDone(self, cutlist):
+               self.initDVDmenuText(len(self.project.titles))
+               self.cuesheet = cutlist
+               self.produceFinalCuesheet()
 
-       def initDVDmenuText(self, project, track):
-               self.properties.menutitle.setValue(self.formatDVDmenuText(project.settings.titleformat.getValue(), track))
-               self.properties.menusubtitle.setValue(self.formatDVDmenuText(project.settings.subtitleformat.getValue(), track))
+       def initDVDmenuText(self, track):
+               s = self.project.menutemplate.settings
+               self.properties.menutitle.setValue(self.formatDVDmenuText(s.titleformat.getValue(), track))
+               self.properties.menusubtitle.setValue(self.formatDVDmenuText(s.subtitleformat.getValue(), track))
 
        def formatDVDmenuText(self, template, track):
-               properties = self.properties
                template = template.replace("$i", str(track))
                template = template.replace("$t", self.DVBname)
                template = template.replace("$d", self.DVBdescr)
@@ -79,7 +90,7 @@ class DVDTitle:
                                audiolist.append(trackstring)
                audiostring = ', '.join(audiolist)
                template = template.replace("$A", audiostring)
-               
+
                if template.find("$l") >= 0:
                        l = self.length
                        lengthstring = "%d:%02d:%02d" % (l/3600, l%3600/60, l%60)
@@ -93,7 +104,7 @@ class DVDTitle:
                else:
                        template = template.replace("$Y", "").replace("$M", "").replace("$D", "").replace("$T", "")
                return template
-       
+
        def produceFinalCuesheet(self):
                CUT_TYPE_IN = 0
                CUT_TYPE_OUT = 1
@@ -139,19 +150,21 @@ class DVDTitle:
                        self.estimatedDiskspace = usedsize
                        self.length = accumulated_in / 90000
 
-       def produceAutoChapter(self, minutes):
-               if len(self.chaptermarks) < 1:
-                       chapterpts = self.cutlist[0]
-                       while chapterpts < self.length*90000:
+       def getChapterMarks(self, template="$h:$m:$s.$t"):
+               timestamps = [ ]
+               chapters = [ ]
+               minutes = self.properties.autochapter.getValue()
+               if len(self.chaptermarks) < 1 and minutes > 0:
+                       chapterpts = 0
+                       while chapterpts < (self.length-60*minutes)*90000:
                                chapterpts += 90000 * 60 * minutes
-                               self.chaptermarks.append(chapterpts)
-
-       def getChapterMarks(self):
-               timestamps = []
-               for p in self.chaptermarks:
-                       h = p / (90000 * 3600)
-                       m = p % (90000 * 3600) / (90000 * 60)
-                       s = p % (90000 * 60) / 90000
-                       ms = (p % 90000) / 90
-                       timestamps.append("%d:%02d:%02d.%03d" % (h, m, s, ms))
+                               chapters.append(chapterpts)
+               else:
+                       chapters = self.chaptermarks
+               for p in chapters:
+                       timestring = template.replace("$h", str(p / (90000 * 3600)))
+                       timestring = timestring.replace("$m", ("%02d" % (p % (90000 * 3600) / (90000 * 60))))
+                       timestring = timestring.replace("$s", ("%02d" % (p % (90000 * 60) / 90000)))
+                       timestring = timestring.replace("$t", ("%03d" % ((p % 90000) / 90)))
+                       timestamps.append(timestring)
                return timestamps
\ No newline at end of file