+ self.args += ["-rf", self.job.workspace]
+ self.weighting = 10
+
+class CheckDiskspaceTask(Task):
+ def __init__(self, job):
+ Task.__init__(self, job, "Checking free space")
+ totalsize = 0 # require an extra safety 50 MB
+ maxsize = 0
+ for title in job.project.titles:
+ titlesize = title.estimatedDiskspace
+ if titlesize > maxsize: maxsize = titlesize
+ totalsize += titlesize
+ diskSpaceNeeded = totalsize + maxsize
+ job.estimateddvdsize = totalsize / 1024 / 1024
+ totalsize += 50*1024*1024 # require an extra safety 50 MB
+ self.global_preconditions.append(DiskspacePrecondition(diskSpaceNeeded))
+ self.weighting = 5
+
+ def run(self, callback):
+ failed_preconditions = self.checkPreconditions(True) + self.checkPreconditions(False)
+ if len(failed_preconditions):
+ callback(self, failed_preconditions)
+ return
+ self.callback = callback
+ Task.processFinished(self, 0)
+
+class PreviewTask(Task):
+ def __init__(self, job, path):
+ Task.__init__(self, job, "Preview")
+ self.postconditions.append(PreviewTaskPostcondition())
+ self.job = job
+ self.path = path
+ self.weighting = 10
+
+ def run(self, callback):
+ self.callback = callback
+ if self.job.menupreview:
+ self.previewProject()
+ else:
+ from Tools import Notifications
+ Notifications.AddNotificationWithCallback(self.previewCB, MessageBox, _("Do you want to preview this DVD before burning?"), timeout = 60, default = False)
+
+ def abort(self):
+ self.finish(aborted = True)
+
+ def previewCB(self, answer):
+ if answer == True:
+ self.previewProject()
+ else:
+ self.closedCB(True)
+
+ def playerClosed(self):
+ if self.job.menupreview:
+ self.closedCB(True)
+ else:
+ from Tools import Notifications
+ Notifications.AddNotificationWithCallback(self.closedCB, MessageBox, _("Do you want to burn this collection to DVD medium?") )
+
+ def closedCB(self, answer):
+ if answer == True:
+ Task.processFinished(self, 0)
+ else:
+ Task.processFinished(self, 1)
+
+ def previewProject(self):
+ from Plugins.Extensions.DVDPlayer.plugin import DVDPlayer
+ self.job.project.session.openWithCallback(self.playerClosed, DVDPlayer, dvd_filelist= [ self.path ])
+
+class PreviewTaskPostcondition(Condition):
+ def check(self, task):
+ return task.returncode == 0
+
+ def getErrorMessage(self, task):
+ return "Cancel"
+
+class ImagingPostcondition(Condition):
+ def check(self, task):
+ return task.returncode == 0
+
+ def getErrorMessage(self, task):
+ return _("Failed") + ": python-imaging"
+
+class ImagePrepareTask(Task):
+ def __init__(self, job):
+ Task.__init__(self, job, _("please wait, loading picture..."))
+ self.postconditions.append(ImagingPostcondition())
+ self.weighting = 20
+ self.job = job
+ self.Menus = job.Menus
+
+ def run(self, callback):
+ self.callback = callback
+ # we are doing it this weird way so that the TaskView Screen actually pops up before the spinner comes
+ from enigma import eTimer
+ self.delayTimer = eTimer()
+ self.delayTimer.callback.append(self.conduct)
+ self.delayTimer.start(10,1)
+
+ def conduct(self):
+ try:
+ from ImageFont import truetype
+ from Image import open as Image_open
+ s = self.job.project.settings
+ self.Menus.im_bg_orig = Image_open(s.menubg.getValue())
+ if self.Menus.im_bg_orig.size != (self.Menus.imgwidth, self.Menus.imgheight):
+ self.Menus.im_bg_orig = self.Menus.im_bg_orig.resize((720, 576))
+ self.Menus.fontsizes = s.font_size.getValue()
+ fontface = s.font_face.getValue()
+ self.Menus.fonts = [truetype(fontface, self.Menus.fontsizes[0]), truetype(fontface, self.Menus.fontsizes[1]), truetype(fontface, self.Menus.fontsizes[2])]
+ Task.processFinished(self, 0)
+ except:
+ Task.processFinished(self, 1)
+
+class MenuImageTask(Task):
+ def __init__(self, job, menu_count, spuxmlfilename, menubgpngfilename, highlightpngfilename):
+ Task.__init__(self, job, "Create Menu %d Image" % menu_count)
+ self.postconditions.append(ImagingPostcondition())
+ self.weighting = 10
+ self.job = job
+ self.Menus = job.Menus
+ self.menu_count = menu_count
+ self.spuxmlfilename = spuxmlfilename
+ self.menubgpngfilename = menubgpngfilename
+ self.highlightpngfilename = highlightpngfilename
+
+ def run(self, callback):
+ self.callback = callback
+ try:
+ import ImageDraw, Image, os
+ s = self.job.project.settings
+ fonts = self.Menus.fonts
+ im_bg = self.Menus.im_bg_orig.copy()
+ im_high = Image.new("P", (self.Menus.imgwidth, self.Menus.imgheight), 0)
+ im_high.putpalette(self.Menus.spu_palette)
+ draw_bg = ImageDraw.Draw(im_bg)
+ draw_high = ImageDraw.Draw(im_high)
+ if self.menu_count == 1:
+ headline = s.name.getValue().decode("utf-8")
+ textsize = draw_bg.textsize(headline, font=fonts[0])
+ if textsize[0] > self.Menus.imgwidth:
+ offset = (0 , 20)
+ else:
+ offset = (((self.Menus.imgwidth-textsize[0]) / 2) , 20)
+ draw_bg.text(offset, headline, fill=self.Menus.color_headline, font=fonts[0])
+ spuxml = """<?xml version="1.0" encoding="utf-8"?>
+ <subpictures>
+ <stream>
+ <spu
+ highlight="%s"
+ transparent="%02x%02x%02x"
+ start="00:00:00.00"
+ force="yes" >""" % (self.highlightpngfilename, self.Menus.spu_palette[0], self.Menus.spu_palette[1], self.Menus.spu_palette[2])
+ s_top, s_rows, s_left = s.space.getValue()
+ rowheight = (self.Menus.fontsizes[1]+self.Menus.fontsizes[2]+s_rows)
+ menu_start_title = (self.menu_count-1)*self.job.titles_per_menu + 1
+ menu_end_title = (self.menu_count)*self.job.titles_per_menu + 1
+ nr_titles = len(self.job.project.titles)
+ if menu_end_title > nr_titles:
+ menu_end_title = nr_titles+1
+ menu_i = 0
+ for title_no in range( menu_start_title , menu_end_title ):
+ menu_i += 1
+ title = self.job.project.titles[title_no-1]
+ top = s_top + ( menu_i * rowheight )
+ titleText = title.formatDVDmenuText(s.titleformat.getValue(), title_no).decode("utf-8")
+ draw_bg.text((s_left,top), titleText, fill=self.Menus.color_button, font=fonts[1])
+ draw_high.text((s_left,top), titleText, fill=1, font=self.Menus.fonts[1])
+ subtitleText = title.formatDVDmenuText(s.subtitleformat.getValue(), title_no).decode("utf-8")
+ draw_bg.text((s_left,top+36), subtitleText, fill=self.Menus.color_button, font=fonts[2])
+ bottom = top+rowheight
+ if bottom > self.Menus.imgheight:
+ bottom = self.Menus.imgheight
+ spuxml += """
+ <button name="button%s" x0="%d" x1="%d" y0="%d" y1="%d"/>""" % (str(title_no).zfill(2),s_left,self.Menus.imgwidth,top,bottom )
+ if self.menu_count < self.job.nr_menus:
+ next_page_text = ">>>"
+ textsize = draw_bg.textsize(next_page_text, font=fonts[1])
+ offset = ( self.Menus.imgwidth-textsize[0]-2*s_left, s_top + ( self.job.titles_per_menu * rowheight ) )
+ draw_bg.text(offset, next_page_text, fill=self.Menus.color_button, font=fonts[1])
+ draw_high.text(offset, next_page_text, fill=1, font=fonts[1])
+ spuxml += """
+ <button name="button_next" x0="%d" x1="%d" y0="%d" y1="%d"/>""" % (offset[0],offset[0]+textsize[0],offset[1],offset[1]+textsize[1])
+ if self.menu_count > 1:
+ prev_page_text = "<<<"
+ textsize = draw_bg.textsize(prev_page_text, font=fonts[1])
+ offset = ( 2*s_left, s_top + ( self.job.titles_per_menu * rowheight ) )
+ draw_bg.text(offset, prev_page_text, fill=self.Menus.color_button, font=fonts[1])
+ draw_high.text(offset, prev_page_text, fill=1, font=fonts[1])
+ spuxml += """
+ <button name="button_prev" x0="%d" x1="%d" y0="%d" y1="%d"/>""" % (offset[0],offset[0]+textsize[0],offset[1],offset[1]+textsize[1])
+ del draw_bg
+ del draw_high
+ fd=open(self.menubgpngfilename,"w")
+ im_bg.save(fd,"PNG")
+ fd.close()
+ fd=open(self.highlightpngfilename,"w")
+ im_high.save(fd,"PNG")
+ fd.close()
+ spuxml += """
+ </spu>
+ </stream>
+ </subpictures>"""
+
+ f = open(self.spuxmlfilename, "w")
+ f.write(spuxml)
+ f.close()
+ Task.processFinished(self, 0)
+ except:
+ Task.processFinished(self, 1)
+
+class Menus:
+ def __init__(self, job):
+ self.job = job
+ job.Menus = self
+
+ s = self.job.project.settings
+
+ self.imgwidth = 720
+ self.imgheight = 576
+
+ self.color_headline = tuple(s.color_headline.getValue())
+ self.color_button = tuple(s.color_button.getValue())
+ self.color_highlight = tuple(s.color_highlight.getValue())
+ self.spu_palette = [ 0x60, 0x60, 0x60 ] + s.color_highlight.getValue()
+
+ ImagePrepareTask(job)
+ nr_titles = len(job.project.titles)
+ if nr_titles < 6:
+ job.titles_per_menu = 5
+ else:
+ job.titles_per_menu = 4
+ job.nr_menus = ((nr_titles+job.titles_per_menu-1)/job.titles_per_menu)
+
+ #a new menu_count every 4 titles (1,2,3,4->1 ; 5,6,7,8->2 etc.)
+ for menu_count in range(1 , job.nr_menus+1):
+ num = str(menu_count)
+ spuxmlfilename = job.workspace+"/spumux"+num+".xml"
+ menubgpngfilename = job.workspace+"/dvd_menubg"+num+".png"
+ highlightpngfilename = job.workspace+"/dvd_highlight"+num+".png"
+ MenuImageTask(job, menu_count, spuxmlfilename, menubgpngfilename, highlightpngfilename)
+ png2yuvTask(job, menubgpngfilename, job.workspace+"/dvdmenubg"+num+".yuv")
+ menubgm2vfilename = job.workspace+"/dvdmenubg"+num+".mv2"
+ mpeg2encTask(job, job.workspace+"/dvdmenubg"+num+".yuv", menubgm2vfilename)
+ menubgmpgfilename = job.workspace+"/dvdmenubg"+num+".mpg"
+ menuaudiofilename = s.menuaudio.getValue()
+ MplexTask(job, outputfile=menubgmpgfilename, inputfiles = [menubgm2vfilename, menuaudiofilename], weighting = 20)
+ menuoutputfilename = job.workspace+"/dvdmenu"+num+".mpg"
+ spumuxTask(job, spuxmlfilename, menubgmpgfilename, menuoutputfilename)
+
+def CreateAuthoringXML_singleset(job):
+ nr_titles = len(job.project.titles)
+ mode = job.project.settings.authormode.getValue()
+ authorxml = []
+ authorxml.append('<?xml version="1.0" encoding="utf-8"?>\n')
+ authorxml.append(' <dvdauthor dest="' + (job.workspace+"/dvd") + '">\n')
+ authorxml.append(' <vmgm>\n')
+ authorxml.append(' <menus>\n')
+ authorxml.append(' <pgc>\n')
+ authorxml.append(' <vob file="' + job.project.settings.vmgm.getValue() + '" />\n', )
+ if mode.startswith("menu"):
+ authorxml.append(' <post> jump titleset 1 menu; </post>\n')
+ else:
+ authorxml.append(' <post> jump title 1; </post>\n')
+ authorxml.append(' </pgc>\n')
+ authorxml.append(' </menus>\n')
+ authorxml.append(' </vmgm>\n')
+ authorxml.append(' <titleset>\n')
+ if mode.startswith("menu"):
+ authorxml.append(' <menus>\n')
+ authorxml.append(' <video aspect="4:3"/>\n')
+ for menu_count in range(1 , job.nr_menus+1):
+ if menu_count == 1:
+ authorxml.append(' <pgc entry="root">\n')
+ else:
+ authorxml.append(' <pgc>\n')
+ menu_start_title = (menu_count-1)*job.titles_per_menu + 1
+ menu_end_title = (menu_count)*job.titles_per_menu + 1
+ if menu_end_title > nr_titles:
+ menu_end_title = nr_titles+1
+ for i in range( menu_start_title , menu_end_title ):
+ authorxml.append(' <button name="button' + (str(i).zfill(2)) + '"> jump title ' + str(i) +'; </button>\n')
+ if menu_count > 1:
+ authorxml.append(' <button name="button_prev"> jump menu ' + str(menu_count-1) + '; </button>\n')
+ if menu_count < job.nr_menus:
+ authorxml.append(' <button name="button_next"> jump menu ' + str(menu_count+1) + '; </button>\n')
+ menuoutputfilename = job.workspace+"/dvdmenu"+str(menu_count)+".mpg"
+ authorxml.append(' <vob file="' + menuoutputfilename + '" pause="inf"/>\n')
+ authorxml.append(' </pgc>\n')
+ authorxml.append(' </menus>\n')
+ authorxml.append(' <titles>\n')
+ for i in range( nr_titles ):
+ chapters = ','.join(job.project.titles[i].getChapterMarks())
+ title_no = i+1
+ title_filename = job.workspace + "/dvd_title_%d.mpg" % (title_no)
+ if job.menupreview:
+ LinkTS(job, job.project.settings.vmgm.getValue(), title_filename)
+ else:
+ MakeFifoNode(job, title_no)
+ if mode.endswith("linked") and title_no < nr_titles:
+ post_tag = "jump title %d;" % ( title_no+1 )
+ elif mode.startswith("menu"):
+ post_tag = "call vmgm menu 1;"
+ else: post_tag = ""
+
+ authorxml.append(' <pgc>\n')
+ authorxml.append(' <vob file="' + title_filename + '" chapters="' + chapters + '" />\n')
+ authorxml.append(' <post> ' + post_tag + ' </post>\n')
+ authorxml.append(' </pgc>\n')
+
+ authorxml.append(' </titles>\n')
+ authorxml.append(' </titleset>\n')
+ authorxml.append(' </dvdauthor>\n')
+ f = open(job.workspace+"/dvdauthor.xml", "w")
+ for x in authorxml:
+ f.write(x)
+ f.close()
+
+def CreateAuthoringXML_multiset(job):
+ nr_titles = len(job.project.titles)
+ mode = job.project.settings.authormode.getValue()
+ authorxml = []
+ authorxml.append('<?xml version="1.0" encoding="utf-8"?>\n')
+ authorxml.append(' <dvdauthor dest="' + (job.workspace+"/dvd") + '" jumppad="yes">\n')
+ authorxml.append(' <vmgm>\n')
+ authorxml.append(' <menus>\n')
+ authorxml.append(' <video aspect="4:3"/>\n')
+ if mode.startswith("menu"):
+ for menu_count in range(1 , job.nr_menus+1):
+ authorxml.append(' <pgc>\n')
+ menu_start_title = (menu_count-1)*job.titles_per_menu + 1
+ menu_end_title = (menu_count)*job.titles_per_menu + 1
+ if menu_end_title > nr_titles:
+ menu_end_title = nr_titles+1
+ for i in range( menu_start_title , menu_end_title ):
+ authorxml.append(' <button name="button' + (str(i).zfill(2)) + '"> jump titleset ' + str(i) +' title 1; </button>\n')
+ if menu_count > 1:
+ authorxml.append(' <button name="button_prev"> jump menu ' + str(menu_count-1) + '; </button>\n')
+ if menu_count < job.nr_menus:
+ authorxml.append(' <button name="button_next"> jump menu ' + str(menu_count+1) + '; </button>\n')
+ menuoutputfilename = job.workspace+"/dvdmenu"+str(menu_count)+".mpg"
+ authorxml.append(' <vob file="' + menuoutputfilename + '" pause="inf"/>\n')
+ authorxml.append(' </pgc>\n')
+ else:
+ authorxml.append(' <pgc>\n')
+ authorxml.append(' <vob file="' + job.project.settings.vmgm.getValue() + '" />\n' )
+ authorxml.append(' <post> jump titleset 1 title 1; </post>\n')
+ authorxml.append(' </pgc>\n')
+ authorxml.append(' </menus>\n')
+ authorxml.append(' </vmgm>\n')
+
+ for i in range( nr_titles ):
+ title = job.project.titles[i]
+ authorxml.append(' <titleset>\n')
+ authorxml.append(' <titles>\n')
+ for audiotrack in title.properties.audiotracks:
+ active = audiotrack.active.getValue()
+ if active:
+ format = audiotrack.format.getValue()
+ language = audiotrack.language.getValue()
+ audio_tag = ' <audio format="%s"' % format
+ if language != "nolang":
+ audio_tag += ' lang="%s"' % language
+ audio_tag += ' />\n'
+ authorxml.append(audio_tag)
+ aspect = title.properties.aspect.getValue()
+ video_tag = ' <video aspect="'+aspect+'"'
+ if title.properties.widescreen.getValue() == "4:3":
+ video_tag += ' widescreen="'+title.properties.widescreen.getValue()+'"'
+ video_tag += ' />\n'
+ authorxml.append(video_tag)
+ chapters = ','.join(title.getChapterMarks())
+ title_no = i+1
+ title_filename = job.workspace + "/dvd_title_%d.mpg" % (title_no)
+ if job.menupreview:
+ LinkTS(job, job.project.settings.vmgm.getValue(), title_filename)
+ else:
+ MakeFifoNode(job, title_no)
+ if mode.endswith("linked") and title_no < nr_titles:
+ post_tag = "jump titleset %d title 1;" % ( title_no+1 )
+ elif mode.startswith("menu"):
+ post_tag = "call vmgm menu 1;"
+ else: post_tag = ""
+
+ authorxml.append(' <pgc>\n')
+ authorxml.append(' <vob file="' + title_filename + '" chapters="' + chapters + '" />\n')
+ authorxml.append(' <post> ' + post_tag + ' </post>\n')
+ authorxml.append(' </pgc>\n')
+ authorxml.append(' </titles>\n')
+ authorxml.append(' </titleset>\n')
+ authorxml.append(' </dvdauthor>\n')
+ f = open(job.workspace+"/dvdauthor.xml", "w")
+ for x in authorxml:
+ f.write(x)
+ f.close()
+
+def getISOfilename(isopath, volName):
+ from Tools.Directories import fileExists
+ i = 0
+ filename = isopath+'/'+volName+".iso"
+ while fileExists(filename):
+ i = i+1
+ filename = isopath+'/'+volName + str(i).zfill(3) + ".iso"
+ return filename