change disc size determination and tweak dual layer growisofs arguments
[enigma2.git] / lib / python / Plugins / Extensions / DVDBurn / DVDProject.py
index fe09642bde47a88044daa28e993beecc6acd0406..9a3bd64c6895707cb384c42bb60aa3bfa4a2a54e 100644 (file)
@@ -1,9 +1,39 @@
 from Tools.Directories import fileExists
+from Components.config import config, ConfigSubsection, ConfigInteger, ConfigText, ConfigSelection, getConfigListEntry, ConfigSequence, ConfigSubList
 
+class ConfigColor(ConfigSequence):
+       def __init__(self, default = [128,128,128]):
+               ConfigSequence.__init__(self, seperator = "#", limits = [(0,255),(0,255),(0,255)], default = default)
+
+class ConfigFilename(ConfigText):
+       def __init__(self):
+               ConfigText.__init__(self, default = "", fixed_size = True, visible_width = False)
+
+       def getMulti(self, selected):
+               filename = (self.text.rstrip("/").rsplit("/",1))[1].encode("utf-8")[:40] + " "
+               if self.allmarked:
+                       mark = range(0, len(filename))
+               else:
+                       mark = [filename]
+               return ("mtext"[1-selected:], filename, mark)
+       
 class DVDProject:
+       MAX_SL = 4370
+       MAX_DL = 7950
        def __init__(self):
                self.titles = [ ]
                self.target = None
+               self.settings = ConfigSubsection()
+               self.settings.name = ConfigText(fixed_size = False, visible_width = 40)
+               self.settings.authormode = ConfigSelection(choices = [("menu_linked", _("Linked titles with a DVD menu")), ("just_linked", _("Direct playback of linked titles without menu")), ("menu_seperate", _("Seperate titles with a main menu")), ("data_ts", _("Dreambox format data DVD (HDTV compatible)"))])
+               self.settings.titlesetmode = ConfigSelection(choices = [("single", _("Simple titleset (compatibility for legacy players)")), ("multi", _("Complex (allows mixing audio tracks and aspects)"))], default="multi")
+               self.settings.output = ConfigSelection(choices = [("iso", _("Create DVD-ISO")), ("dvd", _("Burn DVD"))])
+               self.settings.isopath = ConfigText(fixed_size = False, visible_width = 40)
+               self.settings.dataformat = ConfigSelection(choices = [("iso9660_1", ("ISO9660 Level 1")), ("iso9660_4", ("ISO9660 version 2")), ("udf", ("UDF"))])
+               self.settings.menutemplate = ConfigFilename()
+               self.settings.vmgm = ConfigFilename()
+               self.filekeys = ["vmgm", "isopath", "menutemplate"]
+               self.menutemplate = MenuTemplate()
 
        def addService(self, service):
                import DVDTitle
@@ -13,97 +43,152 @@ class DVDProject:
                return title
 
        def saveProject(self, path):
-               import xml.dom.minidom
-               from Tools.XMLTools import elementsWithTag, mergeText, stringToXML
+               from Tools.XMLTools import stringToXML
                list = []
                list.append('<?xml version="1.0" encoding="utf-8" ?>\n')
                list.append('<DreamDVDBurnerProject>\n')
-               list.append('\t<project')
-               list.append(' name="' + self.name + '"')
-               list.append(' vmgm="' + self.vmgm + '"')
-               list.append(' />\n')
-               list.append('\t<menu')
-               list.append('\tuse="' + str(self.menu) + '"\n')
-               list.append('\tbg="' + self.menubg + '"\n')
-               list.append('\t\taudio="' + self.menuaudio + '"\n')
-               list.append('\t\tcolor_button="' + str(self.color_button) + '"\n')
-               list.append('\t\tcolor_highlight="' + str(self.color_highlight) + '"\n')
-               list.append('\t\tcolor_headline="' + str(self.color_headline) + '"\n')
-               list.append('\t\tfont_face="' + self.font_face + '"\n')
-               list.append('\t\tfont_size="' + str(self.font_size) + '"\n')
-               list.append('\t\tspace_left="' + str(self.space_left) + '"\n')
-               list.append('\t\tspace_top="' + str(self.space_top) + '"\n')
-               list.append('\t\tspace_rows="' + str(self.space_rows) + '"')
-               list.append(' />\n')
-               list.append('\t<titles')
-               list.append(' link="' + str(self.linktitles) + '"')
-               list.append(' />\n')
+               list.append('\t<settings ')
+               for key, val in self.settings.dict().iteritems():
+                       list.append( key + '="' + str(val.getValue()) + '" ' )
+               list.append('/>\n')
+               list.append('\t<titles>\n')
                for title in self.titles:
-                       list.append('\t\t<path>')
+                       list.append('\t\t<title>\n')
+                       list.append('\t\t\t<path>')
                        list.append(stringToXML(title.source.getPath()))
                        list.append('</path>\n')
+                       list.append('\t\t\t<properties ')
+                       audiotracks = []
+                       for key, val in title.properties.dict().iteritems():
+                               if type(val) is ConfigSubList:
+                                       audiotracks.append('\t\t\t<audiotracks>\n')
+                                       for audiotrack in val:
+                                               audiotracks.append('\t\t\t\t<audiotrack ')
+                                               for subkey, subval in audiotrack.dict().iteritems():
+                                                       audiotracks.append( subkey + '="' + str(subval.getValue()) + '" ' )
+                                               audiotracks.append(' />\n')
+                                       audiotracks.append('\t\t\t</audiotracks>\n')
+                               else:
+                                       list.append( key + '="' + str(val.getValue()) + '" ' )
+                       list.append('/>\n')
+                       for line in audiotracks:
+                               list.append(line)
+                       list.append('\t\t</title>\n')
                list.append('\t</titles>\n')
                list.append('</DreamDVDBurnerProject>\n')
 
+               name = self.settings.name.getValue()
                i = 0
-               filename = path + "/" + self.name + ".ddvdp.xml"
+               filename = path + name + ".ddvdp.xml"
                while fileExists(filename):
                        i = i+1
-                       filename = path + "/" + self.name + str(i).zfill(3) + ".ddvdp.xml"
-                               
-               file = open(filename, "w")
-               for x in list:
-                       file.write(x)
-               file.close()
+                       filename = path + name + str(i).zfill(3) + ".ddvdp.xml"
+               try:    
+                       file = open(filename, "w")
+                       for x in list:
+                               file.write(x)
+                       file.close()
+               except:
+                       return False
+               return filename
+
+       def load(self, filename):
+               ret = self.loadProject(filename)
+               if ret:
+                       ret = self.menutemplate.loadTemplate(self.settings.menutemplate.getValue())
+                       self.error += self.menutemplate.error
+               return ret
 
        def loadProject(self, filename):
                import xml.dom.minidom
-               print "[loadProject]", filename
                try:
-                 if not fileExists(filename):
-                       self.error = "file not found!"
-                       raise AttributeError
-                 else:
-                       self.error = ""
-                 file = open(filename, "r")
-                 data = file.read().decode("utf-8").replace('&',"&amp;").encode("ascii",'xmlcharrefreplace')
-                 file.close()
-                 projectfiledom = xml.dom.minidom.parseString(data)
-                 for project in projectfiledom.childNodes[0].childNodes:
-                   if project.nodeType == xml.dom.minidom.Element.nodeType:
-                     if project.tagName == 'project':
-                       self.name = project.getAttribute("name").encode("utf-8")
-                       self.vmgm = project.getAttribute("vmgm").encode("utf-8")
-                     if project.tagName == 'menu':
-                       self.menu = eval(project.getAttribute("use"))
-                       self.menubg = project.getAttribute("bg").encode("utf-8")
-                       self.menuaudio = project.getAttribute("audio").encode("utf-8")  
-                       # tuples with R, G, B values
-                       self.color_button = eval(project.getAttribute("color_button"))
-                       self.color_highlight = eval(project.getAttribute("color_highlight"))
-                       self.color_headline = eval(project.getAttribute("color_headline"))
-                       self.font_face = project.getAttribute("font_face").encode("utf-8")
-                       # tuple with three pixel sizes ( headline, title, subtitle )
-                       self.font_size = eval(project.getAttribute("font_size"))
-                       # please supply even numbers for all dimensions
-                       self.space_left = int(project.getAttribute("space_left"))
-                       self.space_top = int(project.getAttribute("space_top"))
-                       self.space_rows = int(project.getAttribute("space_rows"))
-                     if project.tagName == 'titles':
-                       self.linktitles = eval(project.getAttribute("link"))
-                 if not fileExists(self.vmgm):
-                       self.error += "\nvmgm '%s' not found" % self.vmgm
-                 if not fileExists(self.menubg):
-                       self.error += "\nmenu background '%s' not found" % self.menubg
-                 if not fileExists(self.menuaudio):
-                       self.error += "\nmenu audio '%s' not found" % self.menuaudio
-                 if not fileExists(self.font_face):
-                       self.error += "\nmenu font '%s' not found" % self.font_face
-                 print "len(self.error):", len(self.error)
-                 if len(self.error):
-                       raise AttributeError
-               except:
-                       print "len(self.error):, error", len(self.error), len(self.error)
-                       self.error = ("error parsing project xml file '%s'" % filename) + self.error
+                       if not fileExists(filename):
+                               self.error = "xml file not found!"
+                               raise AttributeError
+                       else:
+                               self.error = ""
+                       file = open(filename, "r")
+                       data = file.read().decode("utf-8").replace('&',"&amp;").encode("ascii",'xmlcharrefreplace')
+                       file.close()
+                       projectfiledom = xml.dom.minidom.parseString(data)
+                       for project in projectfiledom.childNodes[0].childNodes:
+                         if project.nodeType == xml.dom.minidom.Element.nodeType:
+                           if project.tagName == 'settings':
+                               i = 0
+                               if project.attributes.length < len(self.settings.dict())-1:
+                                       self.error = "project attributes missing"
+                                       raise AttributeError
+                               while i < project.attributes.length:
+                                       item = project.attributes.item(i)
+                                       key = item.name.encode("utf-8")
+                                       try:
+                                               val = eval(item.nodeValue)
+                                       except (NameError, SyntaxError):
+                                               val = item.nodeValue.encode("utf-8")
+                                       try:
+                                               self.settings.dict()[key].setValue(val)
+                                       except (KeyError):
+                                               self.error = "unknown attribute '%s'" % (key)
+                                               raise AttributeError
+                                       i += 1
+                       for key in self.filekeys:
+                               val = self.settings.dict()[key].getValue()
+                               if not fileExists(val):
+                                       self.error += "\n%s '%s' not found" % (key, val)
+                       if len(self.error):
+                               raise AttributeError
+               except AttributeError:
+                       self.error += (" in project '%s'") % (filename)
                        return False
                return True
+
+       def getSize(self):
+               totalsize = 0
+               for title in self.titles:
+                       totalsize += title.estimatedDiskspace
+               return totalsize
+
+       size = property(getSize)
+
+class MenuTemplate(DVDProject):
+       def __init__(self):
+               self.settings = ConfigSubsection()
+               self.settings.titleformat = ConfigText(fixed_size = False, visible_width = 40)
+               self.settings.subtitleformat = ConfigText(fixed_size = False, visible_width = 40)
+               self.settings.menubg = ConfigFilename()
+               self.settings.menuaudio = ConfigFilename()
+               self.settings.dimensions = ConfigSequence(seperator = ',', default = [576,720], limits = [(352,720),(480,576)])
+               self.settings.rows = ConfigInteger(default = 4, limits = (1, 10))
+               self.settings.cols = ConfigInteger(default = 1, limits = (1, 4))
+               self.settings.color_headline = ConfigColor()
+               self.settings.color_headline = ConfigColor()
+               self.settings.color_highlight = ConfigColor()
+               self.settings.color_button = ConfigColor()
+               self.settings.fontface_headline = ConfigFilename()
+               self.settings.fontface_title = ConfigFilename()
+               self.settings.fontface_subtitle = ConfigFilename()
+               self.settings.fontsize_headline = ConfigInteger(default = 46, limits = (0, 199))
+               self.settings.fontsize_title = ConfigInteger(default = 24, limits = (0, 199))
+               self.settings.fontsize_subtitle = ConfigInteger(default = 14, limits = (0, 199))
+               self.settings.margin_top = ConfigInteger(default = 120, limits = (0, 500))
+               self.settings.margin_bottom = ConfigInteger(default = 40, limits = (0, 500))
+               self.settings.margin_left = ConfigInteger(default = 56, limits = (0, 500))
+               self.settings.margin_right = ConfigInteger(default = 56, limits = (0, 500))
+               self.settings.space_rows = ConfigInteger(default = 32, limits = (0, 500))
+               self.settings.space_cols = ConfigInteger(default = 24, limits = (0, 500))
+               self.settings.prev_page_text = ConfigText(default = "<<<", fixed_size = False)
+               self.settings.next_page_text = ConfigText(default = ">>>", fixed_size = False)
+               self.settings.offset_headline = ConfigSequence(seperator = ',', default = [0,0], limits = [(-1,500),(-1,500)])
+               self.settings.offset_title = ConfigSequence(seperator = ',', default = [0,0], limits = [(-1,500),(-1,500)])
+               self.settings.offset_subtitle = ConfigSequence(seperator = ',', default = [20,0], limits = [(-1,500),(-1,500)])
+               self.settings.offset_thumb = ConfigSequence(seperator = ',', default = [40,0], limits = [(-1,500),(-1,500)])
+               self.settings.thumb_size = ConfigSequence(seperator = ',', default = [200,158], limits = [(0,576),(-1,720)])
+               self.settings.thumb_border = ConfigInteger(default = 2, limits = (0, 20))
+               self.filekeys = ["menubg", "menuaudio", "fontface_headline", "fontface_title", "fontface_subtitle"]
+               from TitleProperties import languageChoices
+               self.settings.menulang = ConfigSelection(choices = languageChoices.choices, default=languageChoices.choices[1][0])
+
+       def loadTemplate(self, filename):
+               ret = DVDProject.loadProject(self, filename)
+               DVDProject.error = self.error
+               return ret