1 from Components.Task import Task, Job, DiskspacePrecondition, Condition, ToolExistsPrecondition
2 from Components.Harddisk import harddiskmanager
3 from Screens.MessageBox import MessageBox
5 class png2yuvTask(Task):
6 def __init__(self, job, inputfile, outputfile):
7 Task.__init__(self, job, "Creating menu video")
8 self.setTool("/usr/bin/png2yuv")
9 self.args += ["-n1", "-Ip", "-f25", "-j", inputfile]
10 self.dumpFile = outputfile
13 def run(self, callback):
14 Task.run(self, callback)
15 self.container.stdoutAvail.remove(self.processStdout)
16 self.container.dumpToFile(self.dumpFile)
18 def processStderr(self, data):
19 print "[png2yuvTask]", data[:-1]
21 class mpeg2encTask(Task):
22 def __init__(self, job, inputfile, outputfile):
23 Task.__init__(self, job, "Encoding menu video")
24 self.setTool("/usr/bin/mpeg2enc")
25 self.args += ["-f8", "-np", "-a2", "-o", outputfile]
26 self.inputFile = inputfile
29 def run(self, callback):
30 Task.run(self, callback)
31 self.container.readFromFile(self.inputFile)
33 def processOutputLine(self, line):
34 print "[mpeg2encTask]", line[:-1]
36 class spumuxTask(Task):
37 def __init__(self, job, xmlfile, inputfile, outputfile):
38 Task.__init__(self, job, "Muxing buttons into menu")
39 self.setTool("/usr/bin/spumux")
40 self.args += [xmlfile]
41 self.inputFile = inputfile
42 self.dumpFile = outputfile
45 def run(self, callback):
46 Task.run(self, callback)
47 self.container.stdoutAvail.remove(self.processStdout)
48 self.container.dumpToFile(self.dumpFile)
49 self.container.readFromFile(self.inputFile)
51 def processStderr(self, data):
52 print "[spumuxTask]", data[:-1]
54 class MakeFifoNode(Task):
55 def __init__(self, job, number):
56 Task.__init__(self, job, "Make FIFO nodes")
57 self.setTool("/bin/mknod")
58 nodename = self.job.workspace + "/dvd_title_%d" % number + ".mpg"
59 self.args += [nodename, "p"]
63 def __init__(self, job, sourcefile, link_name):
64 Task.__init__(self, job, "Creating symlink for source titles")
65 self.setTool("/bin/ln")
66 self.args += ["-s", sourcefile, link_name]
70 def __init__(self, job, sourcefile):
71 Task.__init__(self, job, "Copy title meta files")
72 self.setTool("/bin/cp")
73 from os import listdir
74 path, filename = sourcefile.rstrip("/").rsplit("/",1)
75 tsfiles = listdir(path)
77 if file.startswith(filename+"."):
78 self.args += [path+'/'+file]
79 self.args += [self.job.workspace]
82 class DemuxTask(Task):
83 def __init__(self, job, inputfile):
84 Task.__init__(self, job, "Demux video into ES")
85 title = job.project.titles[job.i]
86 self.global_preconditions.append(DiskspacePrecondition(title.estimatedDiskspace))
87 self.setTool("/usr/bin/projectx")
88 self.args += [inputfile, "-demux", "-out", self.job.workspace ]
92 self.cutfile = self.job.workspace + "/cut_%d.Xcl" % (job.i+1)
93 self.cutlist = title.cutlist
94 self.currentPID = None
95 self.relevantAudioPIDs = [ ]
96 self.getRelevantAudioPIDs(title)
97 self.generated_files = [ ]
98 self.mplex_streamfiles = [ ]
99 if len(self.cutlist) > 1:
100 self.args += [ "-cut", self.cutfile ]
105 def getRelevantAudioPIDs(self, title):
106 for audiotrack in title.properties.audiotracks:
107 if audiotrack.active.getValue():
108 self.relevantAudioPIDs.append(audiotrack.pid.getValue())
110 def processOutputLine(self, line):
112 MSG_NEW_FILE = "---> new File: "
113 MSG_PROGRESS = "[PROGRESS] "
114 MSG_NEW_MP2 = "--> MPEG Audio (0x"
115 MSG_NEW_AC3 = "--> AC-3/DTS Audio on PID "
117 if line.startswith(MSG_NEW_FILE):
118 file = line[len(MSG_NEW_FILE):]
121 self.haveNewFile(file)
122 elif line.startswith(MSG_PROGRESS):
123 progress = line[len(MSG_PROGRESS):]
124 self.haveProgress(progress)
125 elif line.startswith(MSG_NEW_MP2) or line.startswith(MSG_NEW_AC3):
126 self.currentPID = str(int(line.rstrip()[-6:].rsplit('0x',1)[-1],16))
128 def haveNewFile(self, file):
129 print "[DemuxTask] produced file:", file, self.currentPID
130 self.generated_files.append(file)
131 if self.currentPID in self.relevantAudioPIDs or file.endswith("m2v"):
132 self.mplex_streamfiles.append(file)
134 def haveProgress(self, progress):
135 #print "PROGRESS [%s]" % progress
136 MSG_CHECK = "check & synchronize audio file"
138 if progress == "preparing collection(s)...":
140 elif progress[:len(MSG_CHECK)] == MSG_CHECK:
145 p = p - 1 + self.prog_state * 100
146 if p > self.progress:
151 def writeCutfile(self):
152 f = open(self.cutfile, "w")
153 f.write("CollectionPanel.CutMode=4\n")
154 for p in self.cutlist:
162 f.write("%02d:%02d:%02d\n" % (h, m, s))
165 def cleanup(self, failed):
168 for file in self.generated_files.itervalues():
171 class MplexTaskPostcondition(Condition):
172 def check(self, task):
173 if task.error == task.ERROR_UNDERRUN:
175 return task.error is None
177 def getErrorMessage(self, task):
179 task.ERROR_UNDERRUN: ("Can't multiplex source video!"),
180 task.ERROR_UNKNOWN: ("An unknown error occured!")
183 class MplexTask(Task):
184 ERROR_UNDERRUN, ERROR_UNKNOWN = range(2)
185 def __init__(self, job, outputfile, inputfiles=None, demux_task=None, weighting = 500):
186 Task.__init__(self, job, "Mux ES into PS")
187 self.weighting = weighting
188 self.demux_task = demux_task
189 self.postconditions.append(MplexTaskPostcondition())
190 self.setTool("/usr/bin/mplex")
191 self.args += ["-f8", "-o", outputfile, "-v1"]
193 self.args += inputfiles
195 def setTool(self, tool):
198 self.global_preconditions.append(ToolExistsPrecondition())
199 # we don't want the ReturncodePostcondition in this case because for right now we're just gonna ignore the fact that mplex fails with a buffer underrun error on some streams (this always at the very end)
204 self.args += self.demux_task.mplex_streamfiles
206 def processOutputLine(self, line):
207 print "[MplexTask] ", line[:-1]
208 if line.startswith("**ERROR:"):
209 if line.find("Frame data under-runs detected") != -1:
210 self.error = self.ERROR_UNDERRUN
212 self.error = self.ERROR_UNKNOWN
214 class RemoveESFiles(Task):
215 def __init__(self, job, demux_task):
216 Task.__init__(self, job, "Remove temp. files")
217 self.demux_task = demux_task
218 self.setTool("/bin/rm")
223 self.args += self.demux_task.generated_files.values()
224 self.args += [self.demux_task.cutfile]
226 class DVDAuthorTask(Task):
227 def __init__(self, job):
228 Task.__init__(self, job, "Authoring DVD")
230 self.setTool("/usr/bin/dvdauthor")
231 self.CWD = self.job.workspace
232 self.args += ["-x", self.job.workspace+"/dvdauthor.xml"]
233 self.menupreview = job.menupreview
235 def processOutputLine(self, line):
236 print "[DVDAuthorTask] ", line[:-1]
237 if not self.menupreview and line.startswith("STAT: Processing"):
238 self.callback(self, [], stay_resident=True)
239 elif line.startswith("STAT: VOBU"):
241 progress = int(line.split("MB")[0].split(" ")[-1])
243 self.job.mplextask.progress = progress
244 print "[DVDAuthorTask] update mplextask progress:", self.job.mplextask.progress, "of", self.job.mplextask.end
246 print "couldn't set mux progress"
248 class DVDAuthorFinalTask(Task):
249 def __init__(self, job):
250 Task.__init__(self, job, "dvdauthor finalize")
251 self.setTool("/usr/bin/dvdauthor")
252 self.args += ["-T", "-o", self.job.workspace + "/dvd"]
254 class WaitForResidentTasks(Task):
255 def __init__(self, job):
256 Task.__init__(self, job, "waiting for dvdauthor to finalize")
258 def run(self, callback):
259 print "waiting for %d resident task(s) %s to finish..." % (len(self.job.resident_tasks),str(self.job.resident_tasks))
260 if self.job.resident_tasks == 0:
263 class BurnTaskPostcondition(Condition):
265 def check(self, task):
266 if task.returncode == 0:
268 elif task.error is None or task.error is task.ERROR_MINUSRWBUG:
272 def getErrorMessage(self, task):
274 task.ERROR_NOTWRITEABLE: _("Medium is not a writeable DVD!"),
275 task.ERROR_LOAD: _("Could not load Medium! No disc inserted?"),
276 task.ERROR_SIZE: _("Content does not fit on DVD!"),
277 task.ERROR_WRITE_FAILED: _("Write failed!"),
278 task.ERROR_DVDROM: _("No (supported) DVDROM found!"),
279 task.ERROR_ISOFS: _("Medium is not empty!"),
280 task.ERROR_FILETOOLARGE: _("TS file is too large for ISO9660 level 1!"),
281 task.ERROR_ISOTOOLARGE: _("ISO file is too large for this filesystem!"),
282 task.ERROR_UNKNOWN: _("An unknown error occured!")
285 class BurnTask(Task):
286 ERROR_NOTWRITEABLE, ERROR_LOAD, ERROR_SIZE, ERROR_WRITE_FAILED, ERROR_DVDROM, ERROR_ISOFS, ERROR_FILETOOLARGE, ERROR_ISOTOOLARGE, ERROR_MINUSRWBUG, ERROR_UNKNOWN = range(10)
287 def __init__(self, job, extra_args=[], tool="/bin/growisofs"):
288 Task.__init__(self, job, job.name)
290 self.end = 120 # 100 for writing, 10 for buffer flush, 10 for closing disc
291 self.postconditions.append(BurnTaskPostcondition())
293 self.args += extra_args
298 def processOutputLine(self, line):
300 print "[GROWISOFS] %s" % line
301 if line[8:14] == "done, ":
302 self.progress = float(line[:6])
303 print "progress:", self.progress
304 elif line.find("flushing cache") != -1:
306 elif line.find("closing disc") != -1:
308 elif line.startswith(":-["):
309 if line.find("ASC=30h") != -1:
310 self.error = self.ERROR_NOTWRITEABLE
311 if line.find("ASC=24h") != -1:
312 self.error = self.ERROR_LOAD
313 if line.find("SK=5h/ASC=A8h/ACQ=04h") != -1:
314 self.error = self.ERROR_MINUSRWBUG
316 self.error = self.ERROR_UNKNOWN
317 print "BurnTask: unknown error %s" % line
318 elif line.startswith(":-("):
319 if line.find("No space left on device") != -1:
320 self.error = self.ERROR_SIZE
321 elif self.error == self.ERROR_MINUSRWBUG:
322 print "*sigh* this is a known bug. we're simply gonna assume everything is fine."
323 self.postconditions = []
324 elif line.find("write failed") != -1:
325 self.error = self.ERROR_WRITE_FAILED
326 elif line.find("unable to open64(") != -1 and line.find(",O_RDONLY): No such file or directory") != -1:
327 self.error = self.ERROR_DVDROM
328 elif line.find("media is not recognized as recordable DVD") != -1:
329 self.error = self.ERROR_NOTWRITEABLE
331 self.error = self.ERROR_UNKNOWN
332 print "BurnTask: unknown error %s" % line
333 elif line.startswith("FATAL:"):
334 if line.find("already carries isofs!"):
335 self.error = self.ERROR_ISOFS
337 self.error = self.ERROR_UNKNOWN
338 print "BurnTask: unknown error %s" % line
339 elif line.find("-allow-limited-size was not specified. There is no way do represent this file size. Aborting.") != -1:
340 self.error = self.ERROR_FILETOOLARGE
341 elif line.startswith("genisoimage: File too large."):
342 self.error = self.ERROR_ISOTOOLARGE
344 def setTool(self, tool):
347 self.global_preconditions.append(ToolExistsPrecondition())
349 class RemoveDVDFolder(Task):
350 def __init__(self, job):
351 Task.__init__(self, job, "Remove temp. files")
352 self.setTool("/bin/rm")
353 self.args += ["-rf", self.job.workspace]
356 class CheckDiskspaceTask(Task):
357 def __init__(self, job):
358 Task.__init__(self, job, "Checking free space")
359 totalsize = 0 # require an extra safety 50 MB
361 for title in job.project.titles:
362 titlesize = title.estimatedDiskspace
363 if titlesize > maxsize: maxsize = titlesize
364 totalsize += titlesize
365 diskSpaceNeeded = totalsize + maxsize
366 job.estimateddvdsize = totalsize / 1024 / 1024
367 totalsize += 50*1024*1024 # require an extra safety 50 MB
368 self.global_preconditions.append(DiskspacePrecondition(diskSpaceNeeded))
371 def run(self, callback):
372 failed_preconditions = self.checkPreconditions(True) + self.checkPreconditions(False)
373 if len(failed_preconditions):
374 callback(self, failed_preconditions)
376 self.callback = callback
377 Task.processFinished(self, 0)
379 class PreviewTask(Task):
380 def __init__(self, job, path):
381 Task.__init__(self, job, "Preview")
382 self.postconditions.append(PreviewTaskPostcondition())
387 def run(self, callback):
388 self.callback = callback
389 if self.job.menupreview:
390 self.previewProject()
392 from Tools import Notifications
393 Notifications.AddNotificationWithCallback(self.previewCB, MessageBox, _("Do you want to preview this DVD before burning?"), timeout = 60, default = False)
396 self.finish(aborted = True)
398 def previewCB(self, answer):
400 self.previewProject()
404 def playerClosed(self):
405 if self.job.menupreview:
408 from Tools import Notifications
409 Notifications.AddNotificationWithCallback(self.closedCB, MessageBox, _("Do you want to burn this collection to DVD medium?") )
411 def closedCB(self, answer):
413 Task.processFinished(self, 0)
415 Task.processFinished(self, 1)
417 def previewProject(self):
418 from Plugins.Extensions.DVDPlayer.plugin import DVDPlayer
419 self.job.project.session.openWithCallback(self.playerClosed, DVDPlayer, dvd_filelist= [ self.path ])
421 class PreviewTaskPostcondition(Condition):
422 def check(self, task):
423 return task.returncode == 0
425 def getErrorMessage(self, task):
428 class ImagingPostcondition(Condition):
429 def check(self, task):
430 return task.returncode == 0
432 def getErrorMessage(self, task):
433 return _("Failed") + ": python-imaging"
435 class ImagePrepareTask(Task):
436 def __init__(self, job):
437 Task.__init__(self, job, _("please wait, loading picture..."))
438 self.postconditions.append(ImagingPostcondition())
441 self.Menus = job.Menus
443 def run(self, callback):
444 self.callback = callback
445 # we are doing it this weird way so that the TaskView Screen actually pops up before the spinner comes
446 from enigma import eTimer
447 self.delayTimer = eTimer()
448 self.delayTimer.callback.append(self.conduct)
449 self.delayTimer.start(10,1)
453 from ImageFont import truetype
454 from Image import open as Image_open
455 s = self.job.project.settings
456 self.Menus.im_bg_orig = Image_open(s.menubg.getValue())
457 if self.Menus.im_bg_orig.size != (self.Menus.imgwidth, self.Menus.imgheight):
458 self.Menus.im_bg_orig = self.Menus.im_bg_orig.resize((720, 576))
459 self.Menus.fontsizes = s.font_size.getValue()
460 fontface = s.font_face.getValue()
461 self.Menus.fonts = [truetype(fontface, self.Menus.fontsizes[0]), truetype(fontface, self.Menus.fontsizes[1]), truetype(fontface, self.Menus.fontsizes[2])]
462 Task.processFinished(self, 0)
464 Task.processFinished(self, 1)
466 class MenuImageTask(Task):
467 def __init__(self, job, menu_count, spuxmlfilename, menubgpngfilename, highlightpngfilename):
468 Task.__init__(self, job, "Create Menu %d Image" % menu_count)
469 self.postconditions.append(ImagingPostcondition())
472 self.Menus = job.Menus
473 self.menu_count = menu_count
474 self.spuxmlfilename = spuxmlfilename
475 self.menubgpngfilename = menubgpngfilename
476 self.highlightpngfilename = highlightpngfilename
478 def run(self, callback):
479 self.callback = callback
481 import ImageDraw, Image, os
482 s = self.job.project.settings
483 fonts = self.Menus.fonts
484 im_bg = self.Menus.im_bg_orig.copy()
485 im_high = Image.new("P", (self.Menus.imgwidth, self.Menus.imgheight), 0)
486 im_high.putpalette(self.Menus.spu_palette)
487 draw_bg = ImageDraw.Draw(im_bg)
488 draw_high = ImageDraw.Draw(im_high)
489 if self.menu_count == 1:
490 headline = s.name.getValue().decode("utf-8")
491 textsize = draw_bg.textsize(headline, font=fonts[0])
492 if textsize[0] > self.Menus.imgwidth:
495 offset = (((self.Menus.imgwidth-textsize[0]) / 2) , 20)
496 draw_bg.text(offset, headline, fill=self.Menus.color_headline, font=fonts[0])
497 spuxml = """<?xml version="1.0" encoding="utf-8"?>
502 transparent="%02x%02x%02x"
504 force="yes" >""" % (self.highlightpngfilename, self.Menus.spu_palette[0], self.Menus.spu_palette[1], self.Menus.spu_palette[2])
505 s_top, s_rows, s_left = s.space.getValue()
506 rowheight = (self.Menus.fontsizes[1]+self.Menus.fontsizes[2]+s_rows)
507 menu_start_title = (self.menu_count-1)*self.job.titles_per_menu + 1
508 menu_end_title = (self.menu_count)*self.job.titles_per_menu + 1
509 nr_titles = len(self.job.project.titles)
510 if menu_end_title > nr_titles:
511 menu_end_title = nr_titles+1
513 for title_no in range( menu_start_title , menu_end_title ):
515 title = self.job.project.titles[title_no-1]
516 top = s_top + ( menu_i * rowheight )
517 titleText = title.formatDVDmenuText(s.titleformat.getValue(), title_no).decode("utf-8")
518 draw_bg.text((s_left,top), titleText, fill=self.Menus.color_button, font=fonts[1])
519 draw_high.text((s_left,top), titleText, fill=1, font=self.Menus.fonts[1])
520 subtitleText = title.formatDVDmenuText(s.subtitleformat.getValue(), title_no).decode("utf-8")
521 draw_bg.text((s_left,top+36), subtitleText, fill=self.Menus.color_button, font=fonts[2])
522 bottom = top+rowheight
523 if bottom > self.Menus.imgheight:
524 bottom = self.Menus.imgheight
526 <button name="button%s" x0="%d" x1="%d" y0="%d" y1="%d"/>""" % (str(title_no).zfill(2),s_left,self.Menus.imgwidth,top,bottom )
527 if self.menu_count < self.job.nr_menus:
528 next_page_text = ">>>"
529 textsize = draw_bg.textsize(next_page_text, font=fonts[1])
530 offset = ( self.Menus.imgwidth-textsize[0]-2*s_left, s_top + ( self.job.titles_per_menu * rowheight ) )
531 draw_bg.text(offset, next_page_text, fill=self.Menus.color_button, font=fonts[1])
532 draw_high.text(offset, next_page_text, fill=1, font=fonts[1])
534 <button name="button_next" x0="%d" x1="%d" y0="%d" y1="%d"/>""" % (offset[0],offset[0]+textsize[0],offset[1],offset[1]+textsize[1])
535 if self.menu_count > 1:
536 prev_page_text = "<<<"
537 textsize = draw_bg.textsize(prev_page_text, font=fonts[1])
538 offset = ( 2*s_left, s_top + ( self.job.titles_per_menu * rowheight ) )
539 draw_bg.text(offset, prev_page_text, fill=self.Menus.color_button, font=fonts[1])
540 draw_high.text(offset, prev_page_text, fill=1, font=fonts[1])
542 <button name="button_prev" x0="%d" x1="%d" y0="%d" y1="%d"/>""" % (offset[0],offset[0]+textsize[0],offset[1],offset[1]+textsize[1])
545 fd=open(self.menubgpngfilename,"w")
548 fd=open(self.highlightpngfilename,"w")
549 im_high.save(fd,"PNG")
556 f = open(self.spuxmlfilename, "w")
559 Task.processFinished(self, 0)
561 Task.processFinished(self, 1)
564 def __init__(self, job):
568 s = self.job.project.settings
573 self.color_headline = tuple(s.color_headline.getValue())
574 self.color_button = tuple(s.color_button.getValue())
575 self.color_highlight = tuple(s.color_highlight.getValue())
576 self.spu_palette = [ 0x60, 0x60, 0x60 ] + s.color_highlight.getValue()
578 ImagePrepareTask(job)
579 nr_titles = len(job.project.titles)
581 job.titles_per_menu = 5
583 job.titles_per_menu = 4
584 job.nr_menus = ((nr_titles+job.titles_per_menu-1)/job.titles_per_menu)
586 #a new menu_count every 4 titles (1,2,3,4->1 ; 5,6,7,8->2 etc.)
587 for menu_count in range(1 , job.nr_menus+1):
588 num = str(menu_count)
589 spuxmlfilename = job.workspace+"/spumux"+num+".xml"
590 menubgpngfilename = job.workspace+"/dvd_menubg"+num+".png"
591 highlightpngfilename = job.workspace+"/dvd_highlight"+num+".png"
592 MenuImageTask(job, menu_count, spuxmlfilename, menubgpngfilename, highlightpngfilename)
593 png2yuvTask(job, menubgpngfilename, job.workspace+"/dvdmenubg"+num+".yuv")
594 menubgm2vfilename = job.workspace+"/dvdmenubg"+num+".mv2"
595 mpeg2encTask(job, job.workspace+"/dvdmenubg"+num+".yuv", menubgm2vfilename)
596 menubgmpgfilename = job.workspace+"/dvdmenubg"+num+".mpg"
597 menuaudiofilename = s.menuaudio.getValue()
598 MplexTask(job, outputfile=menubgmpgfilename, inputfiles = [menubgm2vfilename, menuaudiofilename], weighting = 20)
599 menuoutputfilename = job.workspace+"/dvdmenu"+num+".mpg"
600 spumuxTask(job, spuxmlfilename, menubgmpgfilename, menuoutputfilename)
602 def CreateAuthoringXML_singleset(job):
603 nr_titles = len(job.project.titles)
604 mode = job.project.settings.authormode.getValue()
606 authorxml.append('<?xml version="1.0" encoding="utf-8"?>\n')
607 authorxml.append(' <dvdauthor dest="' + (job.workspace+"/dvd") + '">\n')
608 authorxml.append(' <vmgm>\n')
609 authorxml.append(' <menus>\n')
610 authorxml.append(' <pgc>\n')
611 authorxml.append(' <vob file="' + job.project.settings.vmgm.getValue() + '" />\n', )
612 if mode.startswith("menu"):
613 authorxml.append(' <post> jump titleset 1 menu; </post>\n')
615 authorxml.append(' <post> jump title 1; </post>\n')
616 authorxml.append(' </pgc>\n')
617 authorxml.append(' </menus>\n')
618 authorxml.append(' </vmgm>\n')
619 authorxml.append(' <titleset>\n')
620 if mode.startswith("menu"):
621 authorxml.append(' <menus>\n')
622 authorxml.append(' <video aspect="4:3"/>\n')
623 for menu_count in range(1 , job.nr_menus+1):
625 authorxml.append(' <pgc entry="root">\n')
627 authorxml.append(' <pgc>\n')
628 menu_start_title = (menu_count-1)*job.titles_per_menu + 1
629 menu_end_title = (menu_count)*job.titles_per_menu + 1
630 if menu_end_title > nr_titles:
631 menu_end_title = nr_titles+1
632 for i in range( menu_start_title , menu_end_title ):
633 authorxml.append(' <button name="button' + (str(i).zfill(2)) + '"> jump title ' + str(i) +'; </button>\n')
635 authorxml.append(' <button name="button_prev"> jump menu ' + str(menu_count-1) + '; </button>\n')
636 if menu_count < job.nr_menus:
637 authorxml.append(' <button name="button_next"> jump menu ' + str(menu_count+1) + '; </button>\n')
638 menuoutputfilename = job.workspace+"/dvdmenu"+str(menu_count)+".mpg"
639 authorxml.append(' <vob file="' + menuoutputfilename + '" pause="inf"/>\n')
640 authorxml.append(' </pgc>\n')
641 authorxml.append(' </menus>\n')
642 authorxml.append(' <titles>\n')
643 for i in range( nr_titles ):
644 chapters = ','.join(job.project.titles[i].getChapterMarks())
646 title_filename = job.workspace + "/dvd_title_%d.mpg" % (title_no)
648 LinkTS(job, job.project.settings.vmgm.getValue(), title_filename)
650 MakeFifoNode(job, title_no)
651 if mode.endswith("linked") and title_no < nr_titles:
652 post_tag = "jump title %d;" % ( title_no+1 )
653 elif mode.startswith("menu"):
654 post_tag = "call vmgm menu 1;"
657 authorxml.append(' <pgc>\n')
658 authorxml.append(' <vob file="' + title_filename + '" chapters="' + chapters + '" />\n')
659 authorxml.append(' <post> ' + post_tag + ' </post>\n')
660 authorxml.append(' </pgc>\n')
662 authorxml.append(' </titles>\n')
663 authorxml.append(' </titleset>\n')
664 authorxml.append(' </dvdauthor>\n')
665 f = open(job.workspace+"/dvdauthor.xml", "w")
670 def CreateAuthoringXML_multiset(job):
671 nr_titles = len(job.project.titles)
672 mode = job.project.settings.authormode.getValue()
674 authorxml.append('<?xml version="1.0" encoding="utf-8"?>\n')
675 authorxml.append(' <dvdauthor dest="' + (job.workspace+"/dvd") + '" jumppad="yes">\n')
676 authorxml.append(' <vmgm>\n')
677 authorxml.append(' <menus>\n')
678 authorxml.append(' <video aspect="4:3"/>\n')
679 if mode.startswith("menu"):
680 for menu_count in range(1 , job.nr_menus+1):
681 authorxml.append(' <pgc>\n')
682 menu_start_title = (menu_count-1)*job.titles_per_menu + 1
683 menu_end_title = (menu_count)*job.titles_per_menu + 1
684 if menu_end_title > nr_titles:
685 menu_end_title = nr_titles+1
686 for i in range( menu_start_title , menu_end_title ):
687 authorxml.append(' <button name="button' + (str(i).zfill(2)) + '"> jump titleset ' + str(i) +' title 1; </button>\n')
689 authorxml.append(' <button name="button_prev"> jump menu ' + str(menu_count-1) + '; </button>\n')
690 if menu_count < job.nr_menus:
691 authorxml.append(' <button name="button_next"> jump menu ' + str(menu_count+1) + '; </button>\n')
692 menuoutputfilename = job.workspace+"/dvdmenu"+str(menu_count)+".mpg"
693 authorxml.append(' <vob file="' + menuoutputfilename + '" pause="inf"/>\n')
694 authorxml.append(' </pgc>\n')
696 authorxml.append(' <pgc>\n')
697 authorxml.append(' <vob file="' + job.project.settings.vmgm.getValue() + '" />\n' )
698 authorxml.append(' <post> jump titleset 1 title 1; </post>\n')
699 authorxml.append(' </pgc>\n')
700 authorxml.append(' </menus>\n')
701 authorxml.append(' </vmgm>\n')
703 for i in range( nr_titles ):
704 title = job.project.titles[i]
705 authorxml.append(' <titleset>\n')
706 authorxml.append(' <titles>\n')
707 for audiotrack in title.properties.audiotracks:
708 active = audiotrack.active.getValue()
710 format = audiotrack.format.getValue()
711 language = audiotrack.language.getValue()
712 audio_tag = ' <audio format="%s"' % format
713 if language != "nolang":
714 audio_tag += ' lang="%s"' % language
716 authorxml.append(audio_tag)
717 aspect = title.properties.aspect.getValue()
718 video_tag = ' <video aspect="'+aspect+'"'
719 if title.properties.widescreen.getValue() == "4:3":
720 video_tag += ' widescreen="'+title.properties.widescreen.getValue()+'"'
722 authorxml.append(video_tag)
723 chapters = ','.join(title.getChapterMarks())
725 title_filename = job.workspace + "/dvd_title_%d.mpg" % (title_no)
727 LinkTS(job, job.project.settings.vmgm.getValue(), title_filename)
729 MakeFifoNode(job, title_no)
730 if mode.endswith("linked") and title_no < nr_titles:
731 post_tag = "jump titleset %d title 1;" % ( title_no+1 )
732 elif mode.startswith("menu"):
733 post_tag = "call vmgm menu 1;"
736 authorxml.append(' <pgc>\n')
737 authorxml.append(' <vob file="' + title_filename + '" chapters="' + chapters + '" />\n')
738 authorxml.append(' <post> ' + post_tag + ' </post>\n')
739 authorxml.append(' </pgc>\n')
740 authorxml.append(' </titles>\n')
741 authorxml.append(' </titleset>\n')
742 authorxml.append(' </dvdauthor>\n')
743 f = open(job.workspace+"/dvdauthor.xml", "w")
748 def getISOfilename(isopath, volName):
749 from Tools.Directories import fileExists
751 filename = isopath+'/'+volName+".iso"
752 while fileExists(filename):
754 filename = isopath+'/'+volName + str(i).zfill(3) + ".iso"
758 def __init__(self, project, menupreview=False):
759 Job.__init__(self, "DVDBurn Job")
760 self.project = project
761 from time import strftime
762 from Tools.Directories import SCOPE_HDD, resolveFilename, createDir
763 new_workspace = resolveFilename(SCOPE_HDD) + "tmp/" + strftime("%Y%m%d%H%M%S")
764 createDir(new_workspace, True)
765 self.workspace = new_workspace
766 self.project.workspace = self.workspace
767 self.menupreview = menupreview
771 CheckDiskspaceTask(self)
772 if self.project.settings.authormode.getValue().startswith("menu") or self.menupreview:
774 if self.project.settings.titlesetmode.getValue() == "multi":
775 CreateAuthoringXML_multiset(self)
777 CreateAuthoringXML_singleset(self)
781 nr_titles = len(self.project.titles)
784 PreviewTask(self, self.workspace + "/dvd/VIDEO_TS/")
786 for self.i in range(nr_titles):
787 self.title = self.project.titles[self.i]
788 link_name = self.workspace + "/source_title_%d.ts" % (self.i+1)
789 title_filename = self.workspace + "/dvd_title_%d.mpg" % (self.i+1)
790 LinkTS(self, self.title.inputfile, link_name)
791 demux = DemuxTask(self, link_name)
792 self.mplextask = MplexTask(self, outputfile=title_filename, demux_task=demux)
793 self.mplextask.end = self.estimateddvdsize
794 #RemoveESFiles(self, demux)
795 WaitForResidentTasks(self)
796 PreviewTask(self, self.workspace + "/dvd/VIDEO_TS/")
797 output = self.project.settings.output.getValue()
798 volName = self.project.settings.name.getValue()
800 self.name = _("Burn DVD")
801 tool = "/bin/growisofs"
802 burnargs = [ "-Z", "/dev/" + harddiskmanager.getCD(), "-dvd-compat" ]
803 elif output == "iso":
804 self.name = _("Create DVD-ISO")
805 tool = "/usr/bin/mkisofs"
806 isopathfile = getISOfilename(self.project.settings.isopath.getValue(), volName)
807 burnargs = [ "-o", isopathfile ]
808 burnargs += [ "-dvd-video", "-publisher", "Dreambox", "-V", volName, self.workspace + "/dvd" ]
809 BurnTask(self, burnargs, tool)
810 RemoveDVDFolder(self)
812 class DVDdataJob(Job):
813 def __init__(self, project):
814 Job.__init__(self, "Data DVD Burn")
815 self.project = project
816 from time import strftime
817 from Tools.Directories import SCOPE_HDD, resolveFilename, createDir
818 new_workspace = resolveFilename(SCOPE_HDD) + "tmp/" + strftime("%Y%m%d%H%M%S") + "/dvd/"
819 createDir(new_workspace, True)
820 self.workspace = new_workspace
821 self.project.workspace = self.workspace
825 if self.project.settings.output.getValue() == "iso":
826 CheckDiskspaceTask(self)
827 nr_titles = len(self.project.titles)
828 for self.i in range(nr_titles):
829 title = self.project.titles[self.i]
830 filename = title.inputfile.rstrip("/").rsplit("/",1)[1]
831 link_name = self.workspace + filename
832 LinkTS(self, title.inputfile, link_name)
833 CopyMeta(self, title.inputfile)
835 output = self.project.settings.output.getValue()
836 volName = self.project.settings.name.getValue()
837 tool = "/bin/growisofs"
839 self.name = _("Burn DVD")
840 burnargs = [ "-Z", "/dev/" + harddiskmanager.getCD(), "-dvd-compat" ]
841 elif output == "iso":
842 tool = "/usr/bin/mkisofs"
843 self.name = _("Create DVD-ISO")
844 isopathfile = getISOfilename(self.project.settings.isopath.getValue(), volName)
845 burnargs = [ "-o", isopathfile ]
846 if self.project.settings.dataformat.getValue() == "iso9660_1":
847 burnargs += ["-iso-level", "1" ]
848 elif self.project.settings.dataformat.getValue() == "iso9660_4":
849 burnargs += ["-iso-level", "4", "-allow-limited-size" ]
850 elif self.project.settings.dataformat.getValue() == "udf":
851 burnargs += ["-udf", "-allow-limited-size" ]
852 burnargs += [ "-publisher", "Dreambox", "-V", volName, "-follow-links", self.workspace ]
853 BurnTask(self, burnargs, tool)
854 RemoveDVDFolder(self)
856 class DVDisoJob(Job):
857 def __init__(self, project, imagepath):
858 Job.__init__(self, _("Burn DVD"))
859 self.project = project
860 self.menupreview = False
861 if imagepath.endswith(".iso"):
862 PreviewTask(self, imagepath)
863 burnargs = [ "-Z", "/dev/" + harddiskmanager.getCD() + '='+imagepath, "-dvd-compat" ]
865 PreviewTask(self, imagepath + "/VIDEO_TS/")
866 volName = self.project.settings.name.getValue()
867 burnargs = [ "-Z", "/dev/" + harddiskmanager.getCD(), "-dvd-compat" ]
868 burnargs += [ "-dvd-video", "-publisher", "Dreambox", "-V", volName, imagepath ]
869 tool = "/bin/growisofs"
870 BurnTask(self, burnargs, tool)