+ def waitAndOpenPlayer(self):
+ from enigma import eTimer
+ self.delayTimer = eTimer()
+ self.delayTimer.callback.append(self.previewProject)
+ self.delayTimer.start(10,1)
+
+ def previewProject(self):
+ from Plugins.Extensions.DVDPlayer.plugin import DVDPlayer
+ self.job.project.session.openWithCallback(self.playerClosed, DVDPlayer, dvd_filelist= [ self.job.project.workspace + "/dvd/VIDEO_TS/" ])
+
+def getTitlesPerMenu(nr_titles):
+ if nr_titles < 6:
+ titles_per_menu = 5
+ else:
+ titles_per_menu = 4
+ return titles_per_menu
+
+def CreateMenus(job):
+ import os, Image, ImageDraw, ImageFont, re
+ imgwidth = 720
+ imgheight = 576
+
+ im_bg_orig = Image.open(job.project.menubg)
+ if im_bg_orig.size != (imgwidth, imgheight):
+ im_bg_orig = im_bg_orig.resize((720, 576))
+
+ font0 = ImageFont.truetype(job.project.font_face, job.project.font_size[0])
+ font1 = ImageFont.truetype(job.project.font_face, job.project.font_size[1])
+ font2 = ImageFont.truetype(job.project.font_face, job.project.font_size[2])
+ spu_palette = [ 0x60, 0x60, 0x60 ] + list(job.project.color_highlight)
+
+ nr_titles = len(job.project.titles)
+ titles_per_menu = getTitlesPerMenu(nr_titles)
+ job.nr_menus = ((nr_titles+titles_per_menu-1)/titles_per_menu)
+
+ #a new menu_count every 5 titles (1,2,3,4,5->1 ; 6,7,8,9,10->2 etc.)
+ for menu_count in range(1 , job.nr_menus+1):
+ im_bg = im_bg_orig.copy()
+ im_high = Image.new("P", (imgwidth, imgheight), 0)
+ im_high.putpalette(spu_palette)
+ draw_bg = ImageDraw.Draw(im_bg)
+ draw_high = ImageDraw.Draw(im_high)
+
+ if menu_count == 1:
+ headline = job.project.name.decode("utf-8")
+ textsize = draw_bg.textsize(headline, font=font0)
+ if textsize[0] > imgwidth:
+ offset = (0 , 20)
+ else:
+ offset = (((imgwidth-textsize[0]) / 2) , 20)
+ draw_bg.text(offset, headline, fill=job.project.color_headline, font=font0)
+
+ menubgpngfilename = job.workspace+"/dvd_menubg"+str(menu_count)+".png"
+ highlightpngfilename = job.workspace+"/dvd_highlight"+str(menu_count)+".png"
+ spuxml = """<?xml version="1.0" encoding="utf-8"?>
+ <subpictures>
+ <stream>
+ <spu
+ highlight="%s"
+ transparent="%02x%02x%02x"
+ start="00:00:00.00"
+ force="yes" >""" % (highlightpngfilename, spu_palette[0], spu_palette[1], spu_palette[2])
+
+ rowheight = (job.project.font_size[1]+job.project.font_size[2]+job.project.space_rows)
+ menu_start_title = (menu_count-1)*titles_per_menu + 1
+ menu_end_title = (menu_count)*titles_per_menu + 1
+ 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 ):
+ i = title_no-1
+ top = job.project.space_top + ( menu_i * rowheight )
+ menu_i += 1
+ title = job.project.titles[i]
+ titlename = title.name.decode("utf-8")
+ menuitem = "%d. %s" % (title_no, titlename)
+ draw_bg.text((job.project.space_left,top), menuitem, fill=job.project.color_button, font=font1)
+ draw_high.text((job.project.space_left,top), menuitem, fill=1, font=font1)
+ res = re.search("(?:/.*?).*/(?P<year>\d{4})(?P<month>\d{2})(?P<day>\d{2}).(?P<hour>\d{2})(?P<minute>\d{2}).-.*.?.ts", title.inputfile)
+ subtitle = ""
+ if res:
+ subtitle = "%s-%s-%s, %s:%s. " % (res.group("year"),res.group("month"),res.group("day"),res.group("hour"),res.group("minute"))
+ if len(title.descr) > 1:
+ subtitle += title.descr.decode("utf-8") + ". "
+ if len(title.chaptermarks) > 1:
+ subtitle += (" (%d %s)" % (len(title.chaptermarks)+1, _("chapters")))
+ draw_bg.text((job.project.space_left,top+36), subtitle, fill=job.project.color_button, font=font2)
+
+ bottom = top+rowheight
+ if bottom > imgheight:
+ bottom = imgheight
+ spuxml += """
+ <button name="button%s" x0="%d" x1="%d" y0="%d" y1="%d"/>""" % (str(title_no).zfill(2),job.project.space_left,imgwidth,top,bottom )
+ if menu_count > 1:
+ prev_page_text = "<<<"
+ textsize = draw_bg.textsize(prev_page_text, font=font1)
+ offset = ( 2*job.project.space_left, job.project.space_top + ( titles_per_menu * rowheight ) )
+ draw_bg.text(offset, prev_page_text, fill=job.project.color_button, font=font1)
+ draw_high.text(offset, prev_page_text, fill=1, font=font1)
+ 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])
+
+ if menu_count < job.nr_menus:
+ next_page_text = ">>>"
+ textsize = draw_bg.textsize(next_page_text, font=font1)
+ offset = ( imgwidth-textsize[0]-2*job.project.space_left, job.project.space_top + ( titles_per_menu * rowheight ) )
+ draw_bg.text(offset, next_page_text, fill=job.project.color_button, font=font1)
+ draw_high.text(offset, next_page_text, fill=1, font=font1)
+ 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])
+
+ del draw_bg
+ del draw_high
+ fd=open(menubgpngfilename,"w")
+ im_bg.save(fd,"PNG")
+ fd.close()
+ fd=open(highlightpngfilename,"w")
+ im_high.save(fd,"PNG")
+ fd.close()
+
+ png2yuvTask(job, menubgpngfilename, job.workspace+"/dvdmenubg"+str(menu_count)+".yuv")
+ menubgm2vfilename = job.workspace+"/dvdmenubg"+str(menu_count)+".mv2"
+ mpeg2encTask(job, job.workspace+"/dvdmenubg"+str(menu_count)+".yuv", menubgm2vfilename)
+ menubgmpgfilename = job.workspace+"/dvdmenubg"+str(menu_count)+".mpg"
+ MplexTask(job, outputfile=menubgmpgfilename, inputfiles = [menubgm2vfilename, job.project.menuaudio])
+
+ spuxml += """
+ </spu>
+ </stream>
+ </subpictures>"""
+ spuxmlfilename = job.workspace+"/spumux"+str(menu_count)+".xml"
+ f = open(spuxmlfilename, "w")
+ f.write(spuxml)
+ f.close()
+
+ menuoutputfilename = job.workspace+"/dvdmenu"+str(menu_count)+".mpg"
+ spumuxTask(job, spuxmlfilename, menubgmpgfilename, menuoutputfilename)
+
+def CreateAuthoringXML(job):
+ nr_titles = len(job.project.titles)
+ titles_per_menu = getTitlesPerMenu(nr_titles)
+ authorxml = """<?xml version="1.0" encoding="utf-8"?>