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("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("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("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")
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")
66 self.args += ["-s", sourcefile, link_name]
70 def __init__(self, job, sourcefile):
71 Task.__init__(self, job, "Copy title meta files")
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("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_audiofiles = { }
99 self.mplex_videofile = ""
100 self.mplex_streamfiles = [ ]
101 if len(self.cutlist) > 1:
102 self.args += [ "-cut", self.cutfile ]
107 def getRelevantAudioPIDs(self, title):
108 for audiotrack in title.properties.audiotracks:
109 if audiotrack.active.getValue():
110 self.relevantAudioPIDs.append(audiotrack.pid.getValue())
112 def processOutputLine(self, line):
114 #print "[DemuxTask]", line
115 MSG_NEW_FILE = "---> new File: "
116 MSG_PROGRESS = "[PROGRESS] "
117 MSG_NEW_MP2 = "++> Mpg Audio: PID 0x"
118 MSG_NEW_AC3 = "++> AC3/DTS Audio: PID 0x"
120 if line.startswith(MSG_NEW_FILE):
121 file = line[len(MSG_NEW_FILE):]
124 self.haveNewFile(file)
125 elif line.startswith(MSG_PROGRESS):
126 progress = line[len(MSG_PROGRESS):]
127 self.haveProgress(progress)
128 elif line.startswith(MSG_NEW_MP2) or line.startswith(MSG_NEW_AC3):
130 self.currentPID = str(int(line.split(': PID 0x',1)[1].split(' ',1)[0],16))
132 print "[DemuxTask] ERROR: couldn't detect Audio PID (projectx too old?)"
134 def haveNewFile(self, file):
135 print "[DemuxTask] produced file:", file, self.currentPID
136 self.generated_files.append(file)
137 if self.currentPID in self.relevantAudioPIDs:
138 self.mplex_audiofiles[self.currentPID] = file
139 elif file.endswith("m2v"):
140 self.mplex_videofile = file
142 def haveProgress(self, progress):
143 #print "PROGRESS [%s]" % progress
144 MSG_CHECK = "check & synchronize audio file"
146 if progress == "preparing collection(s)...":
148 elif progress[:len(MSG_CHECK)] == MSG_CHECK:
153 p = p - 1 + self.prog_state * 100
154 if p > self.progress:
159 def writeCutfile(self):
160 f = open(self.cutfile, "w")
161 f.write("CollectionPanel.CutMode=4\n")
162 for p in self.cutlist:
170 f.write("%02d:%02d:%02d\n" % (h, m, s))
173 def cleanup(self, failed):
174 print "[DemuxTask::cleanup]"
175 self.mplex_streamfiles = [ self.mplex_videofile ]
176 for pid in self.relevantAudioPIDs:
177 if pid in self.mplex_audiofiles:
178 self.mplex_streamfiles.append(self.mplex_audiofiles[pid])
179 print self.mplex_streamfiles
183 for file in self.generated_files:
189 class MplexTaskPostcondition(Condition):
190 def check(self, task):
191 if task.error == task.ERROR_UNDERRUN:
193 return task.error is None
195 def getErrorMessage(self, task):
197 task.ERROR_UNDERRUN: ("Can't multiplex source video!"),
198 task.ERROR_UNKNOWN: ("An unknown error occured!")
201 class MplexTask(Task):
202 ERROR_UNDERRUN, ERROR_UNKNOWN = range(2)
203 def __init__(self, job, outputfile, inputfiles=None, demux_task=None, weighting = 500):
204 Task.__init__(self, job, "Mux ES into PS")
205 self.weighting = weighting
206 self.demux_task = demux_task
207 self.postconditions.append(MplexTaskPostcondition())
208 self.setTool("mplex")
209 self.args += ["-f8", "-o", outputfile, "-v1"]
211 self.args += inputfiles
213 def setTool(self, tool):
216 self.global_preconditions.append(ToolExistsPrecondition())
217 # 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)
222 self.args += self.demux_task.mplex_streamfiles
224 def processOutputLine(self, line):
225 print "[MplexTask] ", line[:-1]
226 if line.startswith("**ERROR:"):
227 if line.find("Frame data under-runs detected") != -1:
228 self.error = self.ERROR_UNDERRUN
230 self.error = self.ERROR_UNKNOWN
232 class RemoveESFiles(Task):
233 def __init__(self, job, demux_task):
234 Task.__init__(self, job, "Remove temp. files")
235 self.demux_task = demux_task
241 self.args += self.demux_task.generated_files
242 self.args += [self.demux_task.cutfile]
244 class DVDAuthorTask(Task):
245 def __init__(self, job):
246 Task.__init__(self, job, "Authoring DVD")
248 self.setTool("dvdauthor")
249 self.CWD = self.job.workspace
250 self.args += ["-x", self.job.workspace+"/dvdauthor.xml"]
251 self.menupreview = job.menupreview
253 def processOutputLine(self, line):
254 print "[DVDAuthorTask] ", line[:-1]
255 if not self.menupreview and line.startswith("STAT: Processing"):
256 self.callback(self, [], stay_resident=True)
257 elif line.startswith("STAT: VOBU"):
259 progress = int(line.split("MB")[0].split(" ")[-1])
261 self.job.mplextask.progress = progress
262 print "[DVDAuthorTask] update mplextask progress:", self.job.mplextask.progress, "of", self.job.mplextask.end
264 print "couldn't set mux progress"
266 class DVDAuthorFinalTask(Task):
267 def __init__(self, job):
268 Task.__init__(self, job, "dvdauthor finalize")
269 self.setTool("dvdauthor")
270 self.args += ["-T", "-o", self.job.workspace + "/dvd"]
272 class WaitForResidentTasks(Task):
273 def __init__(self, job):
274 Task.__init__(self, job, "waiting for dvdauthor to finalize")
276 def run(self, callback):
277 print "waiting for %d resident task(s) %s to finish..." % (len(self.job.resident_tasks),str(self.job.resident_tasks))
278 self.callback = callback
279 if self.job.resident_tasks == 0:
282 class BurnTaskPostcondition(Condition):
284 def check(self, task):
285 if task.returncode == 0:
287 elif task.error is None or task.error is task.ERROR_MINUSRWBUG:
291 def getErrorMessage(self, task):
293 task.ERROR_NOTWRITEABLE: _("Medium is not a writeable DVD!"),
294 task.ERROR_LOAD: _("Could not load Medium! No disc inserted?"),
295 task.ERROR_SIZE: _("Content does not fit on DVD!"),
296 task.ERROR_WRITE_FAILED: _("Write failed!"),
297 task.ERROR_DVDROM: _("No (supported) DVDROM found!"),
298 task.ERROR_ISOFS: _("Medium is not empty!"),
299 task.ERROR_FILETOOLARGE: _("TS file is too large for ISO9660 level 1!"),
300 task.ERROR_ISOTOOLARGE: _("ISO file is too large for this filesystem!"),
301 task.ERROR_UNKNOWN: _("An unknown error occured!")
304 class BurnTask(Task):
305 ERROR_NOTWRITEABLE, ERROR_LOAD, ERROR_SIZE, ERROR_WRITE_FAILED, ERROR_DVDROM, ERROR_ISOFS, ERROR_FILETOOLARGE, ERROR_ISOTOOLARGE, ERROR_MINUSRWBUG, ERROR_UNKNOWN = range(10)
306 def __init__(self, job, extra_args=[], tool="growisofs"):
307 Task.__init__(self, job, job.name)
309 self.end = 120 # 100 for writing, 10 for buffer flush, 10 for closing disc
310 self.postconditions.append(BurnTaskPostcondition())
312 self.args += extra_args
317 def processOutputLine(self, line):
319 print "[GROWISOFS] %s" % line
320 if line[8:14] == "done, ":
321 self.progress = float(line[:6])
322 print "progress:", self.progress
323 elif line.find("flushing cache") != -1:
325 elif line.find("closing disc") != -1:
327 elif line.startswith(":-["):
328 if line.find("ASC=30h") != -1:
329 self.error = self.ERROR_NOTWRITEABLE
330 elif line.find("ASC=24h") != -1:
331 self.error = self.ERROR_LOAD
332 elif line.find("SK=5h/ASC=A8h/ACQ=04h") != -1:
333 self.error = self.ERROR_MINUSRWBUG
335 self.error = self.ERROR_UNKNOWN
336 print "BurnTask: unknown error %s" % line
337 elif line.startswith(":-("):
338 if line.find("No space left on device") != -1:
339 self.error = self.ERROR_SIZE
340 elif self.error == self.ERROR_MINUSRWBUG:
341 print "*sigh* this is a known bug. we're simply gonna assume everything is fine."
342 self.postconditions = []
343 elif line.find("write failed") != -1:
344 self.error = self.ERROR_WRITE_FAILED
345 elif line.find("unable to open64(") != -1 and line.find(",O_RDONLY): No such file or directory") != -1:
346 self.error = self.ERROR_DVDROM
347 elif line.find("media is not recognized as recordable DVD") != -1:
348 self.error = self.ERROR_NOTWRITEABLE
350 self.error = self.ERROR_UNKNOWN
351 print "BurnTask: unknown error %s" % line
352 elif line.startswith("FATAL:"):
353 if line.find("already carries isofs!"):
354 self.error = self.ERROR_ISOFS
356 self.error = self.ERROR_UNKNOWN
357 print "BurnTask: unknown error %s" % line
358 elif line.find("-allow-limited-size was not specified. There is no way do represent this file size. Aborting.") != -1:
359 self.error = self.ERROR_FILETOOLARGE
360 elif line.startswith("genisoimage: File too large."):
361 self.error = self.ERROR_ISOTOOLARGE
363 def setTool(self, tool):
366 self.global_preconditions.append(ToolExistsPrecondition())
368 class RemoveDVDFolder(Task):
369 def __init__(self, job):
370 Task.__init__(self, job, "Remove temp. files")
372 self.args += ["-rf", self.job.workspace]
375 class CheckDiskspaceTask(Task):
376 def __init__(self, job):
377 Task.__init__(self, job, "Checking free space")
378 totalsize = 0 # require an extra safety 50 MB
380 for title in job.project.titles:
381 titlesize = title.estimatedDiskspace
382 if titlesize > maxsize: maxsize = titlesize
383 totalsize += titlesize
384 diskSpaceNeeded = totalsize + maxsize
385 job.estimateddvdsize = totalsize / 1024 / 1024
386 totalsize += 50*1024*1024 # require an extra safety 50 MB
387 self.global_preconditions.append(DiskspacePrecondition(diskSpaceNeeded))
391 self.finish(aborted = True)
393 def run(self, callback):
394 self.callback = callback
395 failed_preconditions = self.checkPreconditions(True) + self.checkPreconditions(False)
396 if len(failed_preconditions):
397 callback(self, failed_preconditions)
399 Task.processFinished(self, 0)
401 class PreviewTask(Task):
402 def __init__(self, job, path):
403 Task.__init__(self, job, "Preview")
404 self.postconditions.append(PreviewTaskPostcondition())
409 def run(self, callback):
410 self.callback = callback
411 if self.job.menupreview:
412 self.previewProject()
414 import Screens.Standby
415 if Screens.Standby.inStandby:
416 self.previewCB(False)
418 from Tools import Notifications
419 Notifications.AddNotificationWithCallback(self.previewCB, MessageBox, _("Do you want to preview this DVD before burning?"), timeout = 60, default = False)
422 self.finish(aborted = True)
424 def previewCB(self, answer):
426 self.previewProject()
430 def playerClosed(self):
431 if self.job.menupreview:
434 from Tools import Notifications
435 Notifications.AddNotificationWithCallback(self.closedCB, MessageBox, _("Do you want to burn this collection to DVD medium?") )
437 def closedCB(self, answer):
439 Task.processFinished(self, 0)
441 Task.processFinished(self, 1)
443 def previewProject(self):
444 from Plugins.Extensions.DVDPlayer.plugin import DVDPlayer
445 self.job.project.session.openWithCallback(self.playerClosed, DVDPlayer, dvd_filelist= [ self.path ])
447 class PreviewTaskPostcondition(Condition):
448 def check(self, task):
449 return task.returncode == 0
451 def getErrorMessage(self, task):
454 class ImagingPostcondition(Condition):
455 def check(self, task):
456 return task.returncode == 0
458 def getErrorMessage(self, task):
459 return _("Failed") + ": python-imaging"
461 class ImagePrepareTask(Task):
462 def __init__(self, job):
463 Task.__init__(self, job, _("please wait, loading picture..."))
464 self.postconditions.append(ImagingPostcondition())
467 self.Menus = job.Menus
469 def run(self, callback):
470 self.callback = callback
471 # we are doing it this weird way so that the TaskView Screen actually pops up before the spinner comes
472 from enigma import eTimer
473 self.delayTimer = eTimer()
474 self.delayTimer.callback.append(self.conduct)
475 self.delayTimer.start(10,1)
479 from ImageFont import truetype
480 from Image import open as Image_open
481 s = self.job.project.menutemplate.settings
482 (width, height) = s.dimensions.getValue()
483 self.Menus.im_bg_orig = Image_open(s.menubg.getValue())
484 if self.Menus.im_bg_orig.size != (width, height):
485 self.Menus.im_bg_orig = self.Menus.im_bg_orig.resize((width, height))
486 self.Menus.fontsizes = [s.fontsize_headline.getValue(), s.fontsize_title.getValue(), s.fontsize_subtitle.getValue()]
487 self.Menus.fonts = [(truetype(s.fontface_headline.getValue(), self.Menus.fontsizes[0])), (truetype(s.fontface_title.getValue(), self.Menus.fontsizes[1])),(truetype(s.fontface_subtitle.getValue(), self.Menus.fontsizes[2]))]
488 Task.processFinished(self, 0)
490 Task.processFinished(self, 1)
492 class MenuImageTask(Task):
493 def __init__(self, job, menu_count, spuxmlfilename, menubgpngfilename, highlightpngfilename):
494 Task.__init__(self, job, "Create Menu %d Image" % menu_count)
495 self.postconditions.append(ImagingPostcondition())
498 self.Menus = job.Menus
499 self.menu_count = menu_count
500 self.spuxmlfilename = spuxmlfilename
501 self.menubgpngfilename = menubgpngfilename
502 self.highlightpngfilename = highlightpngfilename
504 def run(self, callback):
505 self.callback = callback
507 import ImageDraw, Image, os
508 s = self.job.project.menutemplate.settings
509 s_top = s.margin_top.getValue()
510 s_bottom = s.margin_bottom.getValue()
511 s_left = s.margin_left.getValue()
512 s_right = s.margin_right.getValue()
513 s_rows = s.space_rows.getValue()
514 s_cols = s.space_cols.getValue()
515 nr_cols = s.cols.getValue()
516 nr_rows = s.rows.getValue()
517 thumb_size = s.thumb_size.getValue()
519 from Image import open as Image_open
520 (s_width, s_height) = s.dimensions.getValue()
521 fonts = self.Menus.fonts
522 im_bg = self.Menus.im_bg_orig.copy()
523 im_high = Image.new("P", (s_width, s_height), 0)
524 im_high.putpalette(self.Menus.spu_palette)
525 draw_bg = ImageDraw.Draw(im_bg)
526 draw_high = ImageDraw.Draw(im_high)
527 if self.menu_count == 1:
528 headlineText = self.job.project.settings.name.getValue().decode("utf-8")
529 headlinePos = self.getPosition(s.offset_headline.getValue(), 0, 0, s_width, s_top, draw_bg.textsize(headlineText, font=fonts[0]))
530 draw_bg.text(headlinePos, headlineText, fill=self.Menus.color_headline, font=fonts[0])
531 spuxml = """<?xml version="1.0" encoding="utf-8"?>
536 transparent="%02x%02x%02x"
538 force="yes" >""" % (self.highlightpngfilename, self.Menus.spu_palette[0], self.Menus.spu_palette[1], self.Menus.spu_palette[2])
539 #rowheight = (self.Menus.fontsizes[1]+self.Menus.fontsizes[2]+thumb_size[1]+s_rows)
540 menu_start_title = (self.menu_count-1)*self.job.titles_per_menu + 1
541 menu_end_title = (self.menu_count)*self.job.titles_per_menu + 1
542 nr_titles = len(self.job.project.titles)
543 if menu_end_title > nr_titles:
544 menu_end_title = nr_titles+1
547 for title_no in range( menu_start_title , menu_end_title ):
548 title = self.job.project.titles[title_no-1]
549 col_width = ( s_width - s_left - s_right ) / nr_cols
550 row_height = ( s_height - s_top - s_bottom ) / nr_rows
551 left = s_left + ( (col-1) * col_width ) + s_cols/2
552 right = left + col_width - s_cols
553 top = s_top + ( (row-1) * row_height) + s_rows/2
554 bottom = top + row_height - s_rows
556 height = bottom - top
558 if bottom > s_height:
560 #draw_bg.rectangle((left, top, right, bottom), outline=(255,0,0))
561 im_cell_bg = Image.new("RGBA", (width, height),(0,0,0,0))
562 draw_cell_bg = ImageDraw.Draw(im_cell_bg)
563 im_cell_high = Image.new("P", (width, height), 0)
564 im_cell_high.putpalette(self.Menus.spu_palette)
565 draw_cell_high = ImageDraw.Draw(im_cell_high)
568 thumbPos = self.getPosition(s.offset_thumb.getValue(), 0, 0, width, height, thumb_size)
569 box = (thumbPos[0], thumbPos[1], thumbPos[0]+thumb_size[0], thumbPos[1]+thumb_size[1])
571 thumbIm = Image_open(title.inputfile.rsplit('.',1)[0] + ".png")
572 im_cell_bg.paste(thumbIm,thumbPos)
574 draw_cell_bg.rectangle(box, fill=(64,127,127,127))
575 border = s.thumb_border.getValue()
577 draw_cell_high.rectangle(box, fill=1)
578 draw_cell_high.rectangle((box[0]+border, box[1]+border, box[2]-border, box[3]-border), fill=0)
580 titleText = title.formatDVDmenuText(s.titleformat.getValue(), title_no).decode("utf-8")
581 titlePos = self.getPosition(s.offset_title.getValue(), 0, 0, width, height, draw_bg.textsize(titleText, font=fonts[1]))
583 draw_cell_bg.text(titlePos, titleText, fill=self.Menus.color_button, font=fonts[1])
584 draw_cell_high.text(titlePos, titleText, fill=1, font=self.Menus.fonts[1])
586 subtitleText = title.formatDVDmenuText(s.subtitleformat.getValue(), title_no).decode("utf-8")
587 subtitlePos = self.getPosition(s.offset_subtitle.getValue(), 0, 0, width, height, draw_cell_bg.textsize(subtitleText, font=fonts[2]))
588 draw_cell_bg.text(subtitlePos, subtitleText, fill=self.Menus.color_button, font=fonts[2])
592 im_bg.paste(im_cell_bg,(left, top, right, bottom), mask=im_cell_bg)
593 im_high.paste(im_cell_high,(left, top, right, bottom))
596 <button name="button%s" x0="%d" x1="%d" y0="%d" y1="%d"/>""" % (str(title_no).zfill(2),left,right,top,bottom )
603 top = s_height - s_bottom - s_rows/2
604 if self.menu_count < self.job.nr_menus:
605 next_page_text = s.next_page_text.getValue().decode("utf-8")
606 textsize = draw_bg.textsize(next_page_text, font=fonts[1])
607 pos = ( s_width-textsize[0]-s_right, top )
608 draw_bg.text(pos, next_page_text, fill=self.Menus.color_button, font=fonts[1])
609 draw_high.text(pos, next_page_text, fill=1, font=fonts[1])
611 <button name="button_next" x0="%d" x1="%d" y0="%d" y1="%d"/>""" % (pos[0],pos[0]+textsize[0],pos[1],pos[1]+textsize[1])
612 if self.menu_count > 1:
613 prev_page_text = s.prev_page_text.getValue().decode("utf-8")
614 textsize = draw_bg.textsize(prev_page_text, font=fonts[1])
615 pos = ( (s_left+s_cols/2), top )
616 draw_bg.text(pos, prev_page_text, fill=self.Menus.color_button, font=fonts[1])
617 draw_high.text(pos, prev_page_text, fill=1, font=fonts[1])
619 <button name="button_prev" x0="%d" x1="%d" y0="%d" y1="%d"/>""" % (pos[0],pos[0]+textsize[0],pos[1],pos[1]+textsize[1])
622 fd=open(self.menubgpngfilename,"w")
625 fd=open(self.highlightpngfilename,"w")
626 im_high.save(fd,"PNG")
633 f = open(self.spuxmlfilename, "w")
636 Task.processFinished(self, 0)
638 #Task.processFinished(self, 1)
640 def getPosition(self, offset, left, top, right, bottom, size):
645 pos[0] += ( (right-left) - size[0] ) / 2
649 pos[1] += ( (bottom-top) - size[1] ) / 2
653 def __init__(self, job):
657 s = self.job.project.menutemplate.settings
659 self.color_headline = tuple(s.color_headline.getValue())
660 self.color_button = tuple(s.color_button.getValue())
661 self.color_highlight = tuple(s.color_highlight.getValue())
662 self.spu_palette = [ 0x60, 0x60, 0x60 ] + s.color_highlight.getValue()
664 ImagePrepareTask(job)
665 nr_titles = len(job.project.titles)
667 job.titles_per_menu = s.cols.getValue()*s.rows.getValue()
669 job.nr_menus = ((nr_titles+job.titles_per_menu-1)/job.titles_per_menu)
671 #a new menu_count every 4 titles (1,2,3,4->1 ; 5,6,7,8->2 etc.)
672 for menu_count in range(1 , job.nr_menus+1):
673 num = str(menu_count)
674 spuxmlfilename = job.workspace+"/spumux"+num+".xml"
675 menubgpngfilename = job.workspace+"/dvd_menubg"+num+".png"
676 highlightpngfilename = job.workspace+"/dvd_highlight"+num+".png"
677 MenuImageTask(job, menu_count, spuxmlfilename, menubgpngfilename, highlightpngfilename)
678 png2yuvTask(job, menubgpngfilename, job.workspace+"/dvdmenubg"+num+".yuv")
679 menubgm2vfilename = job.workspace+"/dvdmenubg"+num+".mv2"
680 mpeg2encTask(job, job.workspace+"/dvdmenubg"+num+".yuv", menubgm2vfilename)
681 menubgmpgfilename = job.workspace+"/dvdmenubg"+num+".mpg"
682 menuaudiofilename = s.menuaudio.getValue()
683 MplexTask(job, outputfile=menubgmpgfilename, inputfiles = [menubgm2vfilename, menuaudiofilename], weighting = 20)
684 menuoutputfilename = job.workspace+"/dvdmenu"+num+".mpg"
685 spumuxTask(job, spuxmlfilename, menubgmpgfilename, menuoutputfilename)
687 def CreateAuthoringXML_singleset(job):
688 nr_titles = len(job.project.titles)
689 mode = job.project.settings.authormode.getValue()
691 authorxml.append('<?xml version="1.0" encoding="utf-8"?>\n')
692 authorxml.append(' <dvdauthor dest="' + (job.workspace+"/dvd") + '">\n')
693 authorxml.append(' <vmgm>\n')
694 authorxml.append(' <menus lang="' + job.project.menutemplate.settings.menulang.getValue() + '">\n')
695 authorxml.append(' <pgc>\n')
696 authorxml.append(' <vob file="' + job.project.settings.vmgm.getValue() + '" />\n', )
697 if mode.startswith("menu"):
698 authorxml.append(' <post> jump titleset 1 menu; </post>\n')
700 authorxml.append(' <post> jump title 1; </post>\n')
701 authorxml.append(' </pgc>\n')
702 authorxml.append(' </menus>\n')
703 authorxml.append(' </vmgm>\n')
704 authorxml.append(' <titleset>\n')
705 if mode.startswith("menu"):
706 authorxml.append(' <menus lang="' + job.project.menutemplate.settings.menulang.getValue() + '">\n')
707 authorxml.append(' <video aspect="4:3"/>\n')
708 for menu_count in range(1 , job.nr_menus+1):
710 authorxml.append(' <pgc entry="root">\n')
712 authorxml.append(' <pgc>\n')
713 menu_start_title = (menu_count-1)*job.titles_per_menu + 1
714 menu_end_title = (menu_count)*job.titles_per_menu + 1
715 if menu_end_title > nr_titles:
716 menu_end_title = nr_titles+1
717 for i in range( menu_start_title , menu_end_title ):
718 authorxml.append(' <button name="button' + (str(i).zfill(2)) + '"> jump title ' + str(i) +'; </button>\n')
720 authorxml.append(' <button name="button_prev"> jump menu ' + str(menu_count-1) + '; </button>\n')
721 if menu_count < job.nr_menus:
722 authorxml.append(' <button name="button_next"> jump menu ' + str(menu_count+1) + '; </button>\n')
723 menuoutputfilename = job.workspace+"/dvdmenu"+str(menu_count)+".mpg"
724 authorxml.append(' <vob file="' + menuoutputfilename + '" pause="inf"/>\n')
725 authorxml.append(' </pgc>\n')
726 authorxml.append(' </menus>\n')
727 authorxml.append(' <titles>\n')
728 for i in range( nr_titles ):
729 chapters = ','.join(job.project.titles[i].getChapterMarks())
731 title_filename = job.workspace + "/dvd_title_%d.mpg" % (title_no)
733 LinkTS(job, job.project.settings.vmgm.getValue(), title_filename)
735 MakeFifoNode(job, title_no)
736 if mode.endswith("linked") and title_no < nr_titles:
737 post_tag = "jump title %d;" % ( title_no+1 )
738 elif mode.startswith("menu"):
739 post_tag = "call vmgm menu 1;"
742 authorxml.append(' <pgc>\n')
743 authorxml.append(' <vob file="' + title_filename + '" chapters="' + chapters + '" />\n')
744 authorxml.append(' <post> ' + post_tag + ' </post>\n')
745 authorxml.append(' </pgc>\n')
747 authorxml.append(' </titles>\n')
748 authorxml.append(' </titleset>\n')
749 authorxml.append(' </dvdauthor>\n')
750 f = open(job.workspace+"/dvdauthor.xml", "w")
755 def CreateAuthoringXML_multiset(job):
756 nr_titles = len(job.project.titles)
757 mode = job.project.settings.authormode.getValue()
759 authorxml.append('<?xml version="1.0" encoding="utf-8"?>\n')
760 authorxml.append(' <dvdauthor dest="' + (job.workspace+"/dvd") + '" jumppad="yes">\n')
761 authorxml.append(' <vmgm>\n')
762 authorxml.append(' <menus lang="' + job.project.menutemplate.settings.menulang.getValue() + '">\n')
763 authorxml.append(' <video aspect="4:3"/>\n')
764 if mode.startswith("menu"):
765 for menu_count in range(1 , job.nr_menus+1):
767 authorxml.append(' <pgc>\n')
769 authorxml.append(' <pgc>\n')
770 menu_start_title = (menu_count-1)*job.titles_per_menu + 1
771 menu_end_title = (menu_count)*job.titles_per_menu + 1
772 if menu_end_title > nr_titles:
773 menu_end_title = nr_titles+1
774 for i in range( menu_start_title , menu_end_title ):
775 authorxml.append(' <button name="button' + (str(i).zfill(2)) + '"> jump titleset ' + str(i) +' title 1; </button>\n')
777 authorxml.append(' <button name="button_prev"> jump menu ' + str(menu_count-1) + '; </button>\n')
778 if menu_count < job.nr_menus:
779 authorxml.append(' <button name="button_next"> jump menu ' + str(menu_count+1) + '; </button>\n')
780 menuoutputfilename = job.workspace+"/dvdmenu"+str(menu_count)+".mpg"
781 authorxml.append(' <vob file="' + menuoutputfilename + '" pause="inf"/>\n')
782 authorxml.append(' </pgc>\n')
784 authorxml.append(' <pgc>\n')
785 authorxml.append(' <vob file="' + job.project.settings.vmgm.getValue() + '" />\n' )
786 authorxml.append(' <post> jump titleset 1 title 1; </post>\n')
787 authorxml.append(' </pgc>\n')
788 authorxml.append(' </menus>\n')
789 authorxml.append(' </vmgm>\n')
791 for i in range( nr_titles ):
792 title = job.project.titles[i]
793 authorxml.append(' <titleset>\n')
794 authorxml.append(' <menus lang="' + job.project.menutemplate.settings.menulang.getValue() + '">\n')
795 authorxml.append(' <pgc entry="root">\n')
796 authorxml.append(' <pre>\n')
797 authorxml.append(' jump vmgm menu entry title;\n')
798 authorxml.append(' </pre>\n')
799 authorxml.append(' </pgc>\n')
800 authorxml.append(' </menus>\n')
801 authorxml.append(' <titles>\n')
802 for audiotrack in title.properties.audiotracks:
803 active = audiotrack.active.getValue()
805 format = audiotrack.format.getValue()
806 language = audiotrack.language.getValue()
807 audio_tag = ' <audio format="%s"' % format
808 if language != "nolang":
809 audio_tag += ' lang="%s"' % language
811 authorxml.append(audio_tag)
812 aspect = title.properties.aspect.getValue()
813 video_tag = ' <video aspect="'+aspect+'"'
814 if title.properties.widescreen.getValue() == "4:3":
815 video_tag += ' widescreen="'+title.properties.widescreen.getValue()+'"'
817 authorxml.append(video_tag)
818 chapters = ','.join(title.getChapterMarks())
820 title_filename = job.workspace + "/dvd_title_%d.mpg" % (title_no)
822 LinkTS(job, job.project.settings.vmgm.getValue(), title_filename)
824 MakeFifoNode(job, title_no)
825 if mode.endswith("linked") and title_no < nr_titles:
826 post_tag = "jump titleset %d title 1;" % ( title_no+1 )
827 elif mode.startswith("menu"):
828 post_tag = "call vmgm menu 1;"
831 authorxml.append(' <pgc>\n')
832 authorxml.append(' <vob file="' + title_filename + '" chapters="' + chapters + '" />\n')
833 authorxml.append(' <post> ' + post_tag + ' </post>\n')
834 authorxml.append(' </pgc>\n')
835 authorxml.append(' </titles>\n')
836 authorxml.append(' </titleset>\n')
837 authorxml.append(' </dvdauthor>\n')
838 f = open(job.workspace+"/dvdauthor.xml", "w")
843 def getISOfilename(isopath, volName):
844 from Tools.Directories import fileExists
846 filename = isopath+'/'+volName+".iso"
847 while fileExists(filename):
849 filename = isopath+'/'+volName + str(i).zfill(3) + ".iso"
853 def __init__(self, project, menupreview=False):
854 Job.__init__(self, "DVDBurn Job")
855 self.project = project
856 from time import strftime
857 from Tools.Directories import SCOPE_HDD, resolveFilename, createDir
858 new_workspace = resolveFilename(SCOPE_HDD) + "tmp/" + strftime("%Y%m%d%H%M%S")
859 createDir(new_workspace, True)
860 self.workspace = new_workspace
861 self.project.workspace = self.workspace
862 self.menupreview = menupreview
866 CheckDiskspaceTask(self)
867 if self.project.settings.authormode.getValue().startswith("menu") or self.menupreview:
869 if self.project.settings.titlesetmode.getValue() == "multi":
870 CreateAuthoringXML_multiset(self)
872 CreateAuthoringXML_singleset(self)
876 nr_titles = len(self.project.titles)
879 PreviewTask(self, self.workspace + "/dvd/VIDEO_TS/")
881 for self.i in range(nr_titles):
882 self.title = self.project.titles[self.i]
883 link_name = self.workspace + "/source_title_%d.ts" % (self.i+1)
884 title_filename = self.workspace + "/dvd_title_%d.mpg" % (self.i+1)
885 LinkTS(self, self.title.inputfile, link_name)
886 demux = DemuxTask(self, link_name)
887 self.mplextask = MplexTask(self, outputfile=title_filename, demux_task=demux)
888 self.mplextask.end = self.estimateddvdsize
889 RemoveESFiles(self, demux)
890 WaitForResidentTasks(self)
891 PreviewTask(self, self.workspace + "/dvd/VIDEO_TS/")
892 output = self.project.settings.output.getValue()
893 volName = self.project.settings.name.getValue()
895 self.name = _("Burn DVD")
897 burnargs = [ "-Z", "/dev/" + harddiskmanager.getCD(), "-dvd-compat" ]
898 if self.project.size/(1024*1024) > self.project.MAX_SL:
899 burnargs += [ "-use-the-force-luke=4gms", "-speed=1", "-R" ]
900 elif output == "iso":
901 self.name = _("Create DVD-ISO")
903 isopathfile = getISOfilename(self.project.settings.isopath.getValue(), volName)
904 burnargs = [ "-o", isopathfile ]
905 burnargs += [ "-dvd-video", "-publisher", "Dreambox", "-V", volName, self.workspace + "/dvd" ]
906 BurnTask(self, burnargs, tool)
907 RemoveDVDFolder(self)
909 class DVDdataJob(Job):
910 def __init__(self, project):
911 Job.__init__(self, "Data DVD Burn")
912 self.project = project
913 from time import strftime
914 from Tools.Directories import SCOPE_HDD, resolveFilename, createDir
915 new_workspace = resolveFilename(SCOPE_HDD) + "tmp/" + strftime("%Y%m%d%H%M%S") + "/dvd/"
916 createDir(new_workspace, True)
917 self.workspace = new_workspace
918 self.project.workspace = self.workspace
922 if self.project.settings.output.getValue() == "iso":
923 CheckDiskspaceTask(self)
924 nr_titles = len(self.project.titles)
925 for self.i in range(nr_titles):
926 title = self.project.titles[self.i]
927 filename = title.inputfile.rstrip("/").rsplit("/",1)[1]
928 link_name = self.workspace + filename
929 LinkTS(self, title.inputfile, link_name)
930 CopyMeta(self, title.inputfile)
932 output = self.project.settings.output.getValue()
933 volName = self.project.settings.name.getValue()
936 self.name = _("Burn DVD")
937 burnargs = [ "-Z", "/dev/" + harddiskmanager.getCD(), "-dvd-compat" ]
938 if self.project.size/(1024*1024) > self.project.MAX_SL:
939 burnargs += [ "-use-the-force-luke=4gms", "-speed=1", "-R" ]
940 elif output == "iso":
942 self.name = _("Create DVD-ISO")
943 isopathfile = getISOfilename(self.project.settings.isopath.getValue(), volName)
944 burnargs = [ "-o", isopathfile ]
945 if self.project.settings.dataformat.getValue() == "iso9660_1":
946 burnargs += ["-iso-level", "1" ]
947 elif self.project.settings.dataformat.getValue() == "iso9660_4":
948 burnargs += ["-iso-level", "4", "-allow-limited-size" ]
949 elif self.project.settings.dataformat.getValue() == "udf":
950 burnargs += ["-udf", "-allow-limited-size" ]
951 burnargs += [ "-publisher", "Dreambox", "-V", volName, "-follow-links", self.workspace ]
952 BurnTask(self, burnargs, tool)
953 RemoveDVDFolder(self)
955 class DVDisoJob(Job):
956 def __init__(self, project, imagepath):
957 Job.__init__(self, _("Burn DVD"))
958 self.project = project
959 self.menupreview = False
960 from Tools.Directories import getSize
961 if imagepath.endswith(".iso"):
962 PreviewTask(self, imagepath)
963 burnargs = [ "-Z", "/dev/" + harddiskmanager.getCD() + '='+imagepath, "-dvd-compat" ]
964 if getSize(imagepath)/(1024*1024) > self.project.MAX_SL:
965 burnargs += [ "-use-the-force-luke=4gms", "-speed=1", "-R" ]
967 PreviewTask(self, imagepath + "/VIDEO_TS/")
968 volName = self.project.settings.name.getValue()
969 burnargs = [ "-Z", "/dev/" + harddiskmanager.getCD(), "-dvd-compat" ]
970 if getSize(imagepath)/(1024*1024) > self.project.MAX_SL:
971 burnargs += [ "-use-the-force-luke=4gms", "-speed=1", "-R" ]
972 burnargs += [ "-dvd-video", "-publisher", "Dreambox", "-V", volName, imagepath ]
974 BurnTask(self, burnargs, tool)