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_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 #print "[DemuxTask]", line
113 MSG_NEW_FILE = "---> new File: "
114 MSG_PROGRESS = "[PROGRESS] "
115 MSG_NEW_MP2 = "++> Mpg Audio: PID 0x"
116 MSG_NEW_AC3 = "++> AC3/DTS Audio: PID 0x"
118 if line.startswith(MSG_NEW_FILE):
119 file = line[len(MSG_NEW_FILE):]
122 self.haveNewFile(file)
123 elif line.startswith(MSG_PROGRESS):
124 progress = line[len(MSG_PROGRESS):]
125 self.haveProgress(progress)
126 elif line.startswith(MSG_NEW_MP2) or line.startswith(MSG_NEW_AC3):
128 self.currentPID = str(int(line.split(': PID 0x',1)[1].split(' ',1)[0],16))
130 print "[DemuxTask] ERROR: couldn't detect Audio PID (projectx too old?)"
132 def haveNewFile(self, file):
133 print "[DemuxTask] produced file:", file, self.currentPID
134 self.generated_files.append(file)
135 if self.currentPID in self.relevantAudioPIDs or file.endswith("m2v"):
136 self.mplex_streamfiles.append(file)
138 def haveProgress(self, progress):
139 #print "PROGRESS [%s]" % progress
140 MSG_CHECK = "check & synchronize audio file"
142 if progress == "preparing collection(s)...":
144 elif progress[:len(MSG_CHECK)] == MSG_CHECK:
149 p = p - 1 + self.prog_state * 100
150 if p > self.progress:
155 def writeCutfile(self):
156 f = open(self.cutfile, "w")
157 f.write("CollectionPanel.CutMode=4\n")
158 for p in self.cutlist:
166 f.write("%02d:%02d:%02d\n" % (h, m, s))
169 def cleanup(self, failed):
172 for file in self.generated_files:
178 class MplexTaskPostcondition(Condition):
179 def check(self, task):
180 if task.error == task.ERROR_UNDERRUN:
182 return task.error is None
184 def getErrorMessage(self, task):
186 task.ERROR_UNDERRUN: ("Can't multiplex source video!"),
187 task.ERROR_UNKNOWN: ("An unknown error occured!")
190 class MplexTask(Task):
191 ERROR_UNDERRUN, ERROR_UNKNOWN = range(2)
192 def __init__(self, job, outputfile, inputfiles=None, demux_task=None, weighting = 500):
193 Task.__init__(self, job, "Mux ES into PS")
194 self.weighting = weighting
195 self.demux_task = demux_task
196 self.postconditions.append(MplexTaskPostcondition())
197 self.setTool("mplex")
198 self.args += ["-f8", "-o", outputfile, "-v1"]
200 self.args += inputfiles
202 def setTool(self, tool):
205 self.global_preconditions.append(ToolExistsPrecondition())
206 # 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)
211 self.args += self.demux_task.mplex_streamfiles
213 def processOutputLine(self, line):
214 print "[MplexTask] ", line[:-1]
215 if line.startswith("**ERROR:"):
216 if line.find("Frame data under-runs detected") != -1:
217 self.error = self.ERROR_UNDERRUN
219 self.error = self.ERROR_UNKNOWN
221 class RemoveESFiles(Task):
222 def __init__(self, job, demux_task):
223 Task.__init__(self, job, "Remove temp. files")
224 self.demux_task = demux_task
230 self.args += self.demux_task.generated_files
231 self.args += [self.demux_task.cutfile]
233 class DVDAuthorTask(Task):
234 def __init__(self, job):
235 Task.__init__(self, job, "Authoring DVD")
237 self.setTool("dvdauthor")
238 self.CWD = self.job.workspace
239 self.args += ["-x", self.job.workspace+"/dvdauthor.xml"]
240 self.menupreview = job.menupreview
242 def processOutputLine(self, line):
243 print "[DVDAuthorTask] ", line[:-1]
244 if not self.menupreview and line.startswith("STAT: Processing"):
245 self.callback(self, [], stay_resident=True)
246 elif line.startswith("STAT: VOBU"):
248 progress = int(line.split("MB")[0].split(" ")[-1])
250 self.job.mplextask.progress = progress
251 print "[DVDAuthorTask] update mplextask progress:", self.job.mplextask.progress, "of", self.job.mplextask.end
253 print "couldn't set mux progress"
255 class DVDAuthorFinalTask(Task):
256 def __init__(self, job):
257 Task.__init__(self, job, "dvdauthor finalize")
258 self.setTool("dvdauthor")
259 self.args += ["-T", "-o", self.job.workspace + "/dvd"]
261 class WaitForResidentTasks(Task):
262 def __init__(self, job):
263 Task.__init__(self, job, "waiting for dvdauthor to finalize")
265 def run(self, callback):
266 print "waiting for %d resident task(s) %s to finish..." % (len(self.job.resident_tasks),str(self.job.resident_tasks))
267 self.callback = callback
268 if self.job.resident_tasks == 0:
271 class BurnTaskPostcondition(Condition):
273 def check(self, task):
274 if task.returncode == 0:
276 elif task.error is None or task.error is task.ERROR_MINUSRWBUG:
280 def getErrorMessage(self, task):
282 task.ERROR_NOTWRITEABLE: _("Medium is not a writeable DVD!"),
283 task.ERROR_LOAD: _("Could not load Medium! No disc inserted?"),
284 task.ERROR_SIZE: _("Content does not fit on DVD!"),
285 task.ERROR_WRITE_FAILED: _("Write failed!"),
286 task.ERROR_DVDROM: _("No (supported) DVDROM found!"),
287 task.ERROR_ISOFS: _("Medium is not empty!"),
288 task.ERROR_FILETOOLARGE: _("TS file is too large for ISO9660 level 1!"),
289 task.ERROR_ISOTOOLARGE: _("ISO file is too large for this filesystem!"),
290 task.ERROR_UNKNOWN: _("An unknown error occured!")
293 class BurnTask(Task):
294 ERROR_NOTWRITEABLE, ERROR_LOAD, ERROR_SIZE, ERROR_WRITE_FAILED, ERROR_DVDROM, ERROR_ISOFS, ERROR_FILETOOLARGE, ERROR_ISOTOOLARGE, ERROR_MINUSRWBUG, ERROR_UNKNOWN = range(10)
295 def __init__(self, job, extra_args=[], tool="growisofs"):
296 Task.__init__(self, job, job.name)
298 self.end = 120 # 100 for writing, 10 for buffer flush, 10 for closing disc
299 self.postconditions.append(BurnTaskPostcondition())
301 self.args += extra_args
306 def processOutputLine(self, line):
308 print "[GROWISOFS] %s" % line
309 if line[8:14] == "done, ":
310 self.progress = float(line[:6])
311 print "progress:", self.progress
312 elif line.find("flushing cache") != -1:
314 elif line.find("closing disc") != -1:
316 elif line.startswith(":-["):
317 if line.find("ASC=30h") != -1:
318 self.error = self.ERROR_NOTWRITEABLE
319 elif line.find("ASC=24h") != -1:
320 self.error = self.ERROR_LOAD
321 elif line.find("SK=5h/ASC=A8h/ACQ=04h") != -1:
322 self.error = self.ERROR_MINUSRWBUG
324 self.error = self.ERROR_UNKNOWN
325 print "BurnTask: unknown error %s" % line
326 elif line.startswith(":-("):
327 if line.find("No space left on device") != -1:
328 self.error = self.ERROR_SIZE
329 elif self.error == self.ERROR_MINUSRWBUG:
330 print "*sigh* this is a known bug. we're simply gonna assume everything is fine."
331 self.postconditions = []
332 elif line.find("write failed") != -1:
333 self.error = self.ERROR_WRITE_FAILED
334 elif line.find("unable to open64(") != -1 and line.find(",O_RDONLY): No such file or directory") != -1:
335 self.error = self.ERROR_DVDROM
336 elif line.find("media is not recognized as recordable DVD") != -1:
337 self.error = self.ERROR_NOTWRITEABLE
339 self.error = self.ERROR_UNKNOWN
340 print "BurnTask: unknown error %s" % line
341 elif line.startswith("FATAL:"):
342 if line.find("already carries isofs!"):
343 self.error = self.ERROR_ISOFS
345 self.error = self.ERROR_UNKNOWN
346 print "BurnTask: unknown error %s" % line
347 elif line.find("-allow-limited-size was not specified. There is no way do represent this file size. Aborting.") != -1:
348 self.error = self.ERROR_FILETOOLARGE
349 elif line.startswith("genisoimage: File too large."):
350 self.error = self.ERROR_ISOTOOLARGE
352 def setTool(self, tool):
355 self.global_preconditions.append(ToolExistsPrecondition())
357 class RemoveDVDFolder(Task):
358 def __init__(self, job):
359 Task.__init__(self, job, "Remove temp. files")
361 self.args += ["-rf", self.job.workspace]
364 class CheckDiskspaceTask(Task):
365 def __init__(self, job):
366 Task.__init__(self, job, "Checking free space")
367 totalsize = 0 # require an extra safety 50 MB
369 for title in job.project.titles:
370 titlesize = title.estimatedDiskspace
371 if titlesize > maxsize: maxsize = titlesize
372 totalsize += titlesize
373 diskSpaceNeeded = totalsize + maxsize
374 job.estimateddvdsize = totalsize / 1024 / 1024
375 totalsize += 50*1024*1024 # require an extra safety 50 MB
376 self.global_preconditions.append(DiskspacePrecondition(diskSpaceNeeded))
380 self.finish(aborted = True)
382 def run(self, callback):
383 self.callback = callback
384 failed_preconditions = self.checkPreconditions(True) + self.checkPreconditions(False)
385 if len(failed_preconditions):
386 callback(self, failed_preconditions)
388 Task.processFinished(self, 0)
390 class PreviewTask(Task):
391 def __init__(self, job, path):
392 Task.__init__(self, job, "Preview")
393 self.postconditions.append(PreviewTaskPostcondition())
398 def run(self, callback):
399 self.callback = callback
400 if self.job.menupreview:
401 self.previewProject()
403 import Screens.Standby
404 if Screens.Standby.inStandby:
405 self.previewCB(False)
407 from Tools import Notifications
408 Notifications.AddNotificationWithCallback(self.previewCB, MessageBox, _("Do you want to preview this DVD before burning?"), timeout = 60, default = False)
411 self.finish(aborted = True)
413 def previewCB(self, answer):
415 self.previewProject()
419 def playerClosed(self):
420 if self.job.menupreview:
423 from Tools import Notifications
424 Notifications.AddNotificationWithCallback(self.closedCB, MessageBox, _("Do you want to burn this collection to DVD medium?") )
426 def closedCB(self, answer):
428 Task.processFinished(self, 0)
430 Task.processFinished(self, 1)
432 def previewProject(self):
433 from Plugins.Extensions.DVDPlayer.plugin import DVDPlayer
434 self.job.project.session.openWithCallback(self.playerClosed, DVDPlayer, dvd_filelist= [ self.path ])
436 class PreviewTaskPostcondition(Condition):
437 def check(self, task):
438 return task.returncode == 0
440 def getErrorMessage(self, task):
443 class ImagingPostcondition(Condition):
444 def check(self, task):
445 return task.returncode == 0
447 def getErrorMessage(self, task):
448 return _("Failed") + ": python-imaging"
450 class ImagePrepareTask(Task):
451 def __init__(self, job):
452 Task.__init__(self, job, _("please wait, loading picture..."))
453 self.postconditions.append(ImagingPostcondition())
456 self.Menus = job.Menus
458 def run(self, callback):
459 self.callback = callback
460 # we are doing it this weird way so that the TaskView Screen actually pops up before the spinner comes
461 from enigma import eTimer
462 self.delayTimer = eTimer()
463 self.delayTimer.callback.append(self.conduct)
464 self.delayTimer.start(10,1)
468 from ImageFont import truetype
469 from Image import open as Image_open
470 s = self.job.project.menutemplate.settings
471 (width, height) = s.dimensions.getValue()
472 self.Menus.im_bg_orig = Image_open(s.menubg.getValue())
473 if self.Menus.im_bg_orig.size != (width, height):
474 self.Menus.im_bg_orig = self.Menus.im_bg_orig.resize((width, height))
475 self.Menus.fontsizes = [s.fontsize_headline.getValue(), s.fontsize_title.getValue(), s.fontsize_subtitle.getValue()]
476 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]))]
477 Task.processFinished(self, 0)
479 Task.processFinished(self, 1)
481 class MenuImageTask(Task):
482 def __init__(self, job, menu_count, spuxmlfilename, menubgpngfilename, highlightpngfilename):
483 Task.__init__(self, job, "Create Menu %d Image" % menu_count)
484 self.postconditions.append(ImagingPostcondition())
487 self.Menus = job.Menus
488 self.menu_count = menu_count
489 self.spuxmlfilename = spuxmlfilename
490 self.menubgpngfilename = menubgpngfilename
491 self.highlightpngfilename = highlightpngfilename
493 def run(self, callback):
494 self.callback = callback
496 import ImageDraw, Image, os
497 s = self.job.project.menutemplate.settings
498 s_top = s.margin_top.getValue()
499 s_bottom = s.margin_bottom.getValue()
500 s_left = s.margin_left.getValue()
501 s_right = s.margin_right.getValue()
502 s_rows = s.space_rows.getValue()
503 s_cols = s.space_cols.getValue()
504 nr_cols = s.cols.getValue()
505 nr_rows = s.rows.getValue()
506 thumb_size = s.thumb_size.getValue()
508 from Image import open as Image_open
509 (s_width, s_height) = s.dimensions.getValue()
510 fonts = self.Menus.fonts
511 im_bg = self.Menus.im_bg_orig.copy()
512 im_high = Image.new("P", (s_width, s_height), 0)
513 im_high.putpalette(self.Menus.spu_palette)
514 draw_bg = ImageDraw.Draw(im_bg)
515 draw_high = ImageDraw.Draw(im_high)
516 if self.menu_count == 1:
517 headlineText = self.job.project.settings.name.getValue().decode("utf-8")
518 headlinePos = self.getPosition(s.offset_headline.getValue(), 0, 0, s_width, s_top, draw_bg.textsize(headlineText, font=fonts[0]))
519 draw_bg.text(headlinePos, headlineText, fill=self.Menus.color_headline, font=fonts[0])
520 spuxml = """<?xml version="1.0" encoding="utf-8"?>
525 transparent="%02x%02x%02x"
527 force="yes" >""" % (self.highlightpngfilename, self.Menus.spu_palette[0], self.Menus.spu_palette[1], self.Menus.spu_palette[2])
528 #rowheight = (self.Menus.fontsizes[1]+self.Menus.fontsizes[2]+thumb_size[1]+s_rows)
529 menu_start_title = (self.menu_count-1)*self.job.titles_per_menu + 1
530 menu_end_title = (self.menu_count)*self.job.titles_per_menu + 1
531 nr_titles = len(self.job.project.titles)
532 if menu_end_title > nr_titles:
533 menu_end_title = nr_titles+1
536 for title_no in range( menu_start_title , menu_end_title ):
537 title = self.job.project.titles[title_no-1]
538 col_width = ( s_width - s_left - s_right ) / nr_cols
539 row_height = ( s_height - s_top - s_bottom ) / nr_rows
540 left = s_left + ( (col-1) * col_width ) + s_cols/2
541 right = left + col_width - s_cols
542 top = s_top + ( (row-1) * row_height) + s_rows/2
543 bottom = top + row_height - s_rows
545 height = bottom - top
547 if bottom > s_height:
549 #draw_bg.rectangle((left, top, right, bottom), outline=(255,0,0))
550 im_cell_bg = Image.new("RGBA", (width, height),(0,0,0,0))
551 draw_cell_bg = ImageDraw.Draw(im_cell_bg)
552 im_cell_high = Image.new("P", (width, height), 0)
553 im_cell_high.putpalette(self.Menus.spu_palette)
554 draw_cell_high = ImageDraw.Draw(im_cell_high)
557 thumbPos = self.getPosition(s.offset_thumb.getValue(), 0, 0, width, height, thumb_size)
558 box = (thumbPos[0], thumbPos[1], thumbPos[0]+thumb_size[0], thumbPos[1]+thumb_size[1])
560 thumbIm = Image_open(title.inputfile.rsplit('.',1)[0] + ".png")
561 im_cell_bg.paste(thumbIm,thumbPos)
563 draw_cell_bg.rectangle(box, fill=(64,127,127,127))
564 border = s.thumb_border.getValue()
566 draw_cell_high.rectangle(box, fill=1)
567 draw_cell_high.rectangle((box[0]+border, box[1]+border, box[2]-border, box[3]-border), fill=0)
569 titleText = title.formatDVDmenuText(s.titleformat.getValue(), title_no).decode("utf-8")
570 titlePos = self.getPosition(s.offset_title.getValue(), 0, 0, width, height, draw_bg.textsize(titleText, font=fonts[1]))
572 draw_cell_bg.text(titlePos, titleText, fill=self.Menus.color_button, font=fonts[1])
573 draw_cell_high.text(titlePos, titleText, fill=1, font=self.Menus.fonts[1])
575 subtitleText = title.formatDVDmenuText(s.subtitleformat.getValue(), title_no).decode("utf-8")
576 subtitlePos = self.getPosition(s.offset_subtitle.getValue(), 0, 0, width, height, draw_cell_bg.textsize(subtitleText, font=fonts[2]))
577 draw_cell_bg.text(subtitlePos, subtitleText, fill=self.Menus.color_button, font=fonts[2])
581 im_bg.paste(im_cell_bg,(left, top, right, bottom), mask=im_cell_bg)
582 im_high.paste(im_cell_high,(left, top, right, bottom))
585 <button name="button%s" x0="%d" x1="%d" y0="%d" y1="%d"/>""" % (str(title_no).zfill(2),left,right,top,bottom )
592 top = s_height - s_bottom - s_rows/2
593 if self.menu_count < self.job.nr_menus:
594 next_page_text = s.next_page_text.getValue().decode("utf-8")
595 textsize = draw_bg.textsize(next_page_text, font=fonts[1])
596 pos = ( s_width-textsize[0]-s_right, top )
597 draw_bg.text(pos, next_page_text, fill=self.Menus.color_button, font=fonts[1])
598 draw_high.text(pos, next_page_text, fill=1, font=fonts[1])
600 <button name="button_next" x0="%d" x1="%d" y0="%d" y1="%d"/>""" % (pos[0],pos[0]+textsize[0],pos[1],pos[1]+textsize[1])
601 if self.menu_count > 1:
602 prev_page_text = s.prev_page_text.getValue().decode("utf-8")
603 textsize = draw_bg.textsize(prev_page_text, font=fonts[1])
604 pos = ( (s_left+s_cols/2), top )
605 draw_bg.text(pos, prev_page_text, fill=self.Menus.color_button, font=fonts[1])
606 draw_high.text(pos, prev_page_text, fill=1, font=fonts[1])
608 <button name="button_prev" x0="%d" x1="%d" y0="%d" y1="%d"/>""" % (pos[0],pos[0]+textsize[0],pos[1],pos[1]+textsize[1])
611 fd=open(self.menubgpngfilename,"w")
614 fd=open(self.highlightpngfilename,"w")
615 im_high.save(fd,"PNG")
622 f = open(self.spuxmlfilename, "w")
625 Task.processFinished(self, 0)
627 #Task.processFinished(self, 1)
629 def getPosition(self, offset, left, top, right, bottom, size):
634 pos[0] += ( (right-left) - size[0] ) / 2
638 pos[1] += ( (bottom-top) - size[1] ) / 2
642 def __init__(self, job):
646 s = self.job.project.menutemplate.settings
648 self.color_headline = tuple(s.color_headline.getValue())
649 self.color_button = tuple(s.color_button.getValue())
650 self.color_highlight = tuple(s.color_highlight.getValue())
651 self.spu_palette = [ 0x60, 0x60, 0x60 ] + s.color_highlight.getValue()
653 ImagePrepareTask(job)
654 nr_titles = len(job.project.titles)
656 job.titles_per_menu = s.cols.getValue()*s.rows.getValue()
658 job.nr_menus = ((nr_titles+job.titles_per_menu-1)/job.titles_per_menu)
660 #a new menu_count every 4 titles (1,2,3,4->1 ; 5,6,7,8->2 etc.)
661 for menu_count in range(1 , job.nr_menus+1):
662 num = str(menu_count)
663 spuxmlfilename = job.workspace+"/spumux"+num+".xml"
664 menubgpngfilename = job.workspace+"/dvd_menubg"+num+".png"
665 highlightpngfilename = job.workspace+"/dvd_highlight"+num+".png"
666 MenuImageTask(job, menu_count, spuxmlfilename, menubgpngfilename, highlightpngfilename)
667 png2yuvTask(job, menubgpngfilename, job.workspace+"/dvdmenubg"+num+".yuv")
668 menubgm2vfilename = job.workspace+"/dvdmenubg"+num+".mv2"
669 mpeg2encTask(job, job.workspace+"/dvdmenubg"+num+".yuv", menubgm2vfilename)
670 menubgmpgfilename = job.workspace+"/dvdmenubg"+num+".mpg"
671 menuaudiofilename = s.menuaudio.getValue()
672 MplexTask(job, outputfile=menubgmpgfilename, inputfiles = [menubgm2vfilename, menuaudiofilename], weighting = 20)
673 menuoutputfilename = job.workspace+"/dvdmenu"+num+".mpg"
674 spumuxTask(job, spuxmlfilename, menubgmpgfilename, menuoutputfilename)
676 def CreateAuthoringXML_singleset(job):
677 nr_titles = len(job.project.titles)
678 mode = job.project.settings.authormode.getValue()
680 authorxml.append('<?xml version="1.0" encoding="utf-8"?>\n')
681 authorxml.append(' <dvdauthor dest="' + (job.workspace+"/dvd") + '">\n')
682 authorxml.append(' <vmgm>\n')
683 authorxml.append(' <menus lang="' + job.project.menutemplate.settings.menulang.getValue() + '">\n')
684 authorxml.append(' <pgc>\n')
685 authorxml.append(' <vob file="' + job.project.settings.vmgm.getValue() + '" />\n', )
686 if mode.startswith("menu"):
687 authorxml.append(' <post> jump titleset 1 menu; </post>\n')
689 authorxml.append(' <post> jump title 1; </post>\n')
690 authorxml.append(' </pgc>\n')
691 authorxml.append(' </menus>\n')
692 authorxml.append(' </vmgm>\n')
693 authorxml.append(' <titleset>\n')
694 if mode.startswith("menu"):
695 authorxml.append(' <menus lang="' + job.project.menutemplate.settings.menulang.getValue() + '">\n')
696 authorxml.append(' <video aspect="4:3"/>\n')
697 for menu_count in range(1 , job.nr_menus+1):
699 authorxml.append(' <pgc entry="root">\n')
701 authorxml.append(' <pgc>\n')
702 menu_start_title = (menu_count-1)*job.titles_per_menu + 1
703 menu_end_title = (menu_count)*job.titles_per_menu + 1
704 if menu_end_title > nr_titles:
705 menu_end_title = nr_titles+1
706 for i in range( menu_start_title , menu_end_title ):
707 authorxml.append(' <button name="button' + (str(i).zfill(2)) + '"> jump title ' + str(i) +'; </button>\n')
709 authorxml.append(' <button name="button_prev"> jump menu ' + str(menu_count-1) + '; </button>\n')
710 if menu_count < job.nr_menus:
711 authorxml.append(' <button name="button_next"> jump menu ' + str(menu_count+1) + '; </button>\n')
712 menuoutputfilename = job.workspace+"/dvdmenu"+str(menu_count)+".mpg"
713 authorxml.append(' <vob file="' + menuoutputfilename + '" pause="inf"/>\n')
714 authorxml.append(' </pgc>\n')
715 authorxml.append(' </menus>\n')
716 authorxml.append(' <titles>\n')
717 for i in range( nr_titles ):
718 chapters = ','.join(job.project.titles[i].getChapterMarks())
720 title_filename = job.workspace + "/dvd_title_%d.mpg" % (title_no)
722 LinkTS(job, job.project.settings.vmgm.getValue(), title_filename)
724 MakeFifoNode(job, title_no)
725 if mode.endswith("linked") and title_no < nr_titles:
726 post_tag = "jump title %d;" % ( title_no+1 )
727 elif mode.startswith("menu"):
728 post_tag = "call vmgm menu 1;"
731 authorxml.append(' <pgc>\n')
732 authorxml.append(' <vob file="' + title_filename + '" chapters="' + chapters + '" />\n')
733 authorxml.append(' <post> ' + post_tag + ' </post>\n')
734 authorxml.append(' </pgc>\n')
736 authorxml.append(' </titles>\n')
737 authorxml.append(' </titleset>\n')
738 authorxml.append(' </dvdauthor>\n')
739 f = open(job.workspace+"/dvdauthor.xml", "w")
744 def CreateAuthoringXML_multiset(job):
745 nr_titles = len(job.project.titles)
746 mode = job.project.settings.authormode.getValue()
748 authorxml.append('<?xml version="1.0" encoding="utf-8"?>\n')
749 authorxml.append(' <dvdauthor dest="' + (job.workspace+"/dvd") + '" jumppad="yes">\n')
750 authorxml.append(' <vmgm>\n')
751 authorxml.append(' <menus lang="' + job.project.menutemplate.settings.menulang.getValue() + '">\n')
752 authorxml.append(' <video aspect="4:3"/>\n')
753 if mode.startswith("menu"):
754 for menu_count in range(1 , job.nr_menus+1):
756 authorxml.append(' <pgc>\n')
758 authorxml.append(' <pgc>\n')
759 menu_start_title = (menu_count-1)*job.titles_per_menu + 1
760 menu_end_title = (menu_count)*job.titles_per_menu + 1
761 if menu_end_title > nr_titles:
762 menu_end_title = nr_titles+1
763 for i in range( menu_start_title , menu_end_title ):
764 authorxml.append(' <button name="button' + (str(i).zfill(2)) + '"> jump titleset ' + str(i) +' title 1; </button>\n')
766 authorxml.append(' <button name="button_prev"> jump menu ' + str(menu_count-1) + '; </button>\n')
767 if menu_count < job.nr_menus:
768 authorxml.append(' <button name="button_next"> jump menu ' + str(menu_count+1) + '; </button>\n')
769 menuoutputfilename = job.workspace+"/dvdmenu"+str(menu_count)+".mpg"
770 authorxml.append(' <vob file="' + menuoutputfilename + '" pause="inf"/>\n')
771 authorxml.append(' </pgc>\n')
773 authorxml.append(' <pgc>\n')
774 authorxml.append(' <vob file="' + job.project.settings.vmgm.getValue() + '" />\n' )
775 authorxml.append(' <post> jump titleset 1 title 1; </post>\n')
776 authorxml.append(' </pgc>\n')
777 authorxml.append(' </menus>\n')
778 authorxml.append(' </vmgm>\n')
780 for i in range( nr_titles ):
781 title = job.project.titles[i]
782 authorxml.append(' <titleset>\n')
783 authorxml.append(' <menus lang="' + job.project.menutemplate.settings.menulang.getValue() + '">\n')
784 authorxml.append(' <pgc entry="root">\n')
785 authorxml.append(' <pre>\n')
786 authorxml.append(' jump vmgm menu entry title;\n')
787 authorxml.append(' </pre>\n')
788 authorxml.append(' </pgc>\n')
789 authorxml.append(' </menus>\n')
790 authorxml.append(' <titles>\n')
791 for audiotrack in title.properties.audiotracks:
792 active = audiotrack.active.getValue()
794 format = audiotrack.format.getValue()
795 language = audiotrack.language.getValue()
796 audio_tag = ' <audio format="%s"' % format
797 if language != "nolang":
798 audio_tag += ' lang="%s"' % language
800 authorxml.append(audio_tag)
801 aspect = title.properties.aspect.getValue()
802 video_tag = ' <video aspect="'+aspect+'"'
803 if title.properties.widescreen.getValue() == "4:3":
804 video_tag += ' widescreen="'+title.properties.widescreen.getValue()+'"'
806 authorxml.append(video_tag)
807 chapters = ','.join(title.getChapterMarks())
809 title_filename = job.workspace + "/dvd_title_%d.mpg" % (title_no)
811 LinkTS(job, job.project.settings.vmgm.getValue(), title_filename)
813 MakeFifoNode(job, title_no)
814 if mode.endswith("linked") and title_no < nr_titles:
815 post_tag = "jump titleset %d title 1;" % ( title_no+1 )
816 elif mode.startswith("menu"):
817 post_tag = "call vmgm menu 1;"
820 authorxml.append(' <pgc>\n')
821 authorxml.append(' <vob file="' + title_filename + '" chapters="' + chapters + '" />\n')
822 authorxml.append(' <post> ' + post_tag + ' </post>\n')
823 authorxml.append(' </pgc>\n')
824 authorxml.append(' </titles>\n')
825 authorxml.append(' </titleset>\n')
826 authorxml.append(' </dvdauthor>\n')
827 f = open(job.workspace+"/dvdauthor.xml", "w")
832 def getISOfilename(isopath, volName):
833 from Tools.Directories import fileExists
835 filename = isopath+'/'+volName+".iso"
836 while fileExists(filename):
838 filename = isopath+'/'+volName + str(i).zfill(3) + ".iso"
842 def __init__(self, project, menupreview=False):
843 Job.__init__(self, "DVDBurn Job")
844 self.project = project
845 from time import strftime
846 from Tools.Directories import SCOPE_HDD, resolveFilename, createDir
847 new_workspace = resolveFilename(SCOPE_HDD) + "tmp/" + strftime("%Y%m%d%H%M%S")
848 createDir(new_workspace, True)
849 self.workspace = new_workspace
850 self.project.workspace = self.workspace
851 self.menupreview = menupreview
855 CheckDiskspaceTask(self)
856 if self.project.settings.authormode.getValue().startswith("menu") or self.menupreview:
858 if self.project.settings.titlesetmode.getValue() == "multi":
859 CreateAuthoringXML_multiset(self)
861 CreateAuthoringXML_singleset(self)
865 nr_titles = len(self.project.titles)
868 PreviewTask(self, self.workspace + "/dvd/VIDEO_TS/")
870 for self.i in range(nr_titles):
871 self.title = self.project.titles[self.i]
872 link_name = self.workspace + "/source_title_%d.ts" % (self.i+1)
873 title_filename = self.workspace + "/dvd_title_%d.mpg" % (self.i+1)
874 LinkTS(self, self.title.inputfile, link_name)
875 demux = DemuxTask(self, link_name)
876 self.mplextask = MplexTask(self, outputfile=title_filename, demux_task=demux)
877 self.mplextask.end = self.estimateddvdsize
878 RemoveESFiles(self, demux)
879 WaitForResidentTasks(self)
880 PreviewTask(self, self.workspace + "/dvd/VIDEO_TS/")
881 output = self.project.settings.output.getValue()
882 volName = self.project.settings.name.getValue()
884 self.name = _("Burn DVD")
886 burnargs = [ "-Z", "/dev/" + harddiskmanager.getCD(), "-dvd-compat" ]
887 if self.project.size/(1024*1024) > self.project.MAX_SL:
888 burnargs += [ "-use-the-force-luke=4gms", "-speed=1", "-R" ]
889 elif output == "iso":
890 self.name = _("Create DVD-ISO")
892 isopathfile = getISOfilename(self.project.settings.isopath.getValue(), volName)
893 burnargs = [ "-o", isopathfile ]
894 burnargs += [ "-dvd-video", "-publisher", "Dreambox", "-V", volName, self.workspace + "/dvd" ]
895 BurnTask(self, burnargs, tool)
896 RemoveDVDFolder(self)
898 class DVDdataJob(Job):
899 def __init__(self, project):
900 Job.__init__(self, "Data DVD Burn")
901 self.project = project
902 from time import strftime
903 from Tools.Directories import SCOPE_HDD, resolveFilename, createDir
904 new_workspace = resolveFilename(SCOPE_HDD) + "tmp/" + strftime("%Y%m%d%H%M%S") + "/dvd/"
905 createDir(new_workspace, True)
906 self.workspace = new_workspace
907 self.project.workspace = self.workspace
911 if self.project.settings.output.getValue() == "iso":
912 CheckDiskspaceTask(self)
913 nr_titles = len(self.project.titles)
914 for self.i in range(nr_titles):
915 title = self.project.titles[self.i]
916 filename = title.inputfile.rstrip("/").rsplit("/",1)[1]
917 link_name = self.workspace + filename
918 LinkTS(self, title.inputfile, link_name)
919 CopyMeta(self, title.inputfile)
921 output = self.project.settings.output.getValue()
922 volName = self.project.settings.name.getValue()
925 self.name = _("Burn DVD")
926 burnargs = [ "-Z", "/dev/" + harddiskmanager.getCD(), "-dvd-compat" ]
927 if self.project.size/(1024*1024) > self.project.MAX_SL:
928 burnargs += [ "-use-the-force-luke=4gms", "-speed=1", "-R" ]
929 elif output == "iso":
931 self.name = _("Create DVD-ISO")
932 isopathfile = getISOfilename(self.project.settings.isopath.getValue(), volName)
933 burnargs = [ "-o", isopathfile ]
934 if self.project.settings.dataformat.getValue() == "iso9660_1":
935 burnargs += ["-iso-level", "1" ]
936 elif self.project.settings.dataformat.getValue() == "iso9660_4":
937 burnargs += ["-iso-level", "4", "-allow-limited-size" ]
938 elif self.project.settings.dataformat.getValue() == "udf":
939 burnargs += ["-udf", "-allow-limited-size" ]
940 burnargs += [ "-publisher", "Dreambox", "-V", volName, "-follow-links", self.workspace ]
941 BurnTask(self, burnargs, tool)
942 RemoveDVDFolder(self)
944 class DVDisoJob(Job):
945 def __init__(self, project, imagepath):
946 Job.__init__(self, _("Burn DVD"))
947 self.project = project
948 self.menupreview = False
949 from Tools.Directories import getSize
950 if imagepath.endswith(".iso"):
951 PreviewTask(self, imagepath)
952 burnargs = [ "-Z", "/dev/" + harddiskmanager.getCD() + '='+imagepath, "-dvd-compat" ]
953 if getSize(imagepath)/(1024*1024) > self.project.MAX_SL:
954 burnargs += [ "-use-the-force-luke=4gms", "-speed=1", "-R" ]
956 PreviewTask(self, imagepath + "/VIDEO_TS/")
957 volName = self.project.settings.name.getValue()
958 burnargs = [ "-Z", "/dev/" + harddiskmanager.getCD(), "-dvd-compat" ]
959 if getSize(imagepath)/(1024*1024) > self.project.MAX_SL:
960 burnargs += [ "-use-the-force-luke=4gms", "-speed=1", "-R" ]
961 burnargs += [ "-dvd-video", "-publisher", "Dreambox", "-V", volName, imagepath ]
963 BurnTask(self, burnargs, tool)