parameters: (job)
return_statement: return
docstring: Starts processing a MythBurn job, expects XML nodes to be passed as input.
docstring_summary: Starts processing a MythBurn job, expects XML nodes to be passed as input.
docstring_tokens: Starts processing a MythBurn job expects XML nodes to be passed as input .
function: def processJob(job):
      """Starts processing a MythBurn job, expects XML nodes to be passed as input."""
      global wantIntro, wantMainMenu, wantChapterMenu, wantDetailsPage
      global themeDOM, themeName, themeFonts
  
  
      media=job.getElementsByTagName("media")
  
      if media.length==1:
  
          themeName=job.attributes["theme"].value
  
          #Check theme exists
          if not validateTheme(themeName):
              fatalError("Failed to validate theme (%s)" % themeName)
          #Get the theme XML
          themeDOM = getThemeConfigurationXML(themeName)
  
          #Pre generate all the fonts we need
          loadFonts(themeDOM)
  
          #Update the global flags
          nodes=themeDOM.getElementsByTagName("intro")
          wantIntro = (nodes.length > 0)
  
          nodes=themeDOM.getElementsByTagName("menu")
          wantMainMenu = (nodes.length > 0)
  
          nodes=themeDOM.getElementsByTagName("submenu")
          wantChapterMenu = (nodes.length > 0)
  
          nodes=themeDOM.getElementsByTagName("detailspage")
          wantDetailsPage = (nodes.length > 0)
  
          write( "wantIntro: %d, wantMainMenu: %d, wantChapterMenu: %d, wantDetailsPage: %d" \
                  % (wantIntro, wantMainMenu, wantChapterMenu, wantDetailsPage))
  
          if videomode=="ntsc":
              format=dvdNTSC
              dpi=dvdNTSCdpi
          elif videomode=="pal":
              format=dvdPAL
              dpi=dvdPALdpi
          else:
              fatalError("Unknown videomode is set (%s)" % videomode)
  
          write( "Final DVD Video format will be " + videomode)
  
  
          #Loop through all the files
          files=media[0].getElementsByTagName("file")
          filecount=0
          if files.length > 0:
              write( "There are %s file(s) to process" % files.length)
  
              if debug_secondrunthrough==False:
                  #Delete all the temporary files that currently exist
                  deleteEverythingInFolder(getTempPath())
                  localCopyFolder=os.path.join(getTempPath(),"localcopy")
                  os.makedirs(localCopyFolder)
              files=copyRemote(files,getTempPath())
  
              #First pass through the files to be recorded - sense check
              #we dont want to find half way through this long process that
              #a file does not exist, or is the wrong format!!
              for node in files:
                  filecount+=1
  
                  #Generate a temp folder name for this file
                  folder=getItemTempPath(filecount)
  
                  if debug_secondrunthrough==False:
                      os.makedirs(folder)
                  #Do the pre-process work
                  preProcessFile(node,folder,filecount)
  
              if debug_secondrunthrough==False:
                  #Loop through all the files again but this time do more serious work!
                  filecount=0
                  for node in files:
                      filecount+=1
                      folder=getItemTempPath(filecount)
  
                      #Process this file
                      processFile(node,folder,filecount)
  
              #We can only create the menus after the videos have been processed
              #and the commercials cut out so we get the correct run time length
              #for the chapter marks and thumbnails.
              #create the DVD menus...
              if wantMainMenu:
                  createMenu(format, dpi, files.length)
  
              #Submenus are visible when you select the chapter menu while the recording is playing
              if wantChapterMenu:
                  createChapterMenu(format, dpi, files.length)
  
              #Details Page are displayed just before playing each recording
              if wantDetailsPage:
                  createDetailsPage(format, dpi, files.length)
  
              #DVD Author file
              if not wantMainMenu and not wantChapterMenu:
                  createDVDAuthorXMLNoMenus(format, files.length)
              elif not wantMainMenu:
                  createDVDAuthorXMLNoMainMenu(format, files.length)
              else:
                  createDVDAuthorXML(format, files.length)
  
              #Check all the files will fit onto a recordable DVD
              if mediatype == DVD_DL:
                  # dual layer
                  performMPEG2Shrink(files, dvdrsize[1])
              else:
                  #single layer
                  performMPEG2Shrink(files, dvdrsize[0])
  
              filecount=0
              for node in files:
                  filecount+=1
                  folder=getItemTempPath(filecount)
                  #Multiplex this file
                  #(This also removes non-required audio feeds inside mpeg streams
                  #(through re-multiplexing) we only take 1 video and 1 or 2 audio streams)
                  pid=multiplexMPEGStream(os.path.join(folder,'stream.mv2'),
                          os.path.join(folder,'stream0'),
                          os.path.join(folder,'stream1'),
                          os.path.join(folder,'final.vob'),
                          calcSyncOffset(filecount))
  
              #Now all the files are completed and ready to be burnt
              runDVDAuthor()
  
              #Delete dvdauthor work files
              if debug_keeptempfiles==False:
                  filecount=0
                  for node in files:
                      filecount+=1
                      folder=getItemTempPath(filecount)
                      if os.path.exists(os.path.join(folder, "stream.mv2")):
                          os.remove(os.path.join(folder,'stream.mv2'))
                      if os.path.exists(os.path.join(folder, "stream0.mp2")):
                          os.remove(os.path.join(folder,'stream0.mp2'))
                      if os.path.exists(os.path.join(folder, "stream1.mp2")):
                          os.remove(os.path.join(folder,'stream1.mp2'))
                      if os.path.exists(os.path.join(folder, "stream0.ac3")):
                          os.remove(os.path.join(folder,'stream0.ac3'))
                      if os.path.exists(os.path.join(folder, "stream1.ac3")):
                          os.remove(os.path.join(folder,'stream1.ac3'))
  
              #Get DVD title from first processed file
              #Get the XML containing information about this item
              infoDOM = xml.dom.minidom.parse( os.path.join(getItemTempPath(1),"info.xml") )
              #Error out if its the wrong XML
              if infoDOM.documentElement.tagName != "fileinfo":
                  fatalError("The info.xml file (%s) doesn't look right" % os.path.join(folder,"info.xml"))
              title = expandItemText(infoDOM,"%title",1,0,0,0,0)
              # replace all non-ascii-characters
              title = title.encode('ascii', 'replace').decode('ascii', 'replace')
              title = title.strip()
  
              # replace not-allowed characters
              index = 0
              title_new = ''
              while (index < len(title)) and (index < 32):
                  if title[index].isalnum and title[index] != ' ':
                      title_new += title[index]
                  else:
                      title_new += '_'
                  index = index + 1
  
              title = title_new.upper()
  
              if len(title) < 1:
                  title = 'UNNAMED'
  
              #Create the DVD ISO image
              if docreateiso == True or mediatype == FILE:
                  CreateDVDISO(title)
  
              #Burn the DVD ISO image
              if doburn == True and mediatype != FILE:
                  BurnDVDISO(title)
  
              #Move the created iso image to the given location
              if mediatype == FILE and savefilename != "":
                  write("Moving ISO image to: %s" % savefilename)
                  try:
                      os.rename(os.path.join(getTempPath(), 'mythburn.iso'), savefilename)
                  except:
                      f1 = open(os.path.join(getTempPath(), 'mythburn.iso'), 'rb')
                      f2 = open(savefilename, 'wb')
                      data = f1.read(1024 * 1024)
                      while data:
                          f2.write(data)
                          data = f1.read(1024 * 1024)
                      f1.close()
                      f2.close()
                      os.unlink(os.path.join(getTempPath(), 'mythburn.iso'))
          else:
              write( "Nothing to do! (files)")
      else:
          write( "Nothing to do! (media)")
      return
function_tokens: def processJob ( job ) : global wantIntro , wantMainMenu , wantChapterMenu , wantDetailsPage global themeDOM , themeName , themeFonts media = job . getElementsByTagName ( "media" ) if media . length == 1 : themeName = job . attributes [ "theme" ] . value #Check theme exists if not validateTheme ( themeName ) : fatalError ( "Failed to validate theme (%s)" % themeName ) #Get the theme XML themeDOM = getThemeConfigurationXML ( themeName ) #Pre generate all the fonts we need loadFonts ( themeDOM ) #Update the global flags nodes = themeDOM . getElementsByTagName ( "intro" ) wantIntro = ( nodes . length > 0 ) nodes = themeDOM . getElementsByTagName ( "menu" ) wantMainMenu = ( nodes . length > 0 ) nodes = themeDOM . getElementsByTagName ( "submenu" ) wantChapterMenu = ( nodes . length > 0 ) nodes = themeDOM . getElementsByTagName ( "detailspage" ) wantDetailsPage = ( nodes . length > 0 ) write ( "wantIntro: %d, wantMainMenu: %d, wantChapterMenu: %d, wantDetailsPage: %d" % ( wantIntro , wantMainMenu , wantChapterMenu , wantDetailsPage ) ) if videomode == "ntsc" : format = dvdNTSC dpi = dvdNTSCdpi elif videomode == "pal" : format = dvdPAL dpi = dvdPALdpi else : fatalError ( "Unknown videomode is set (%s)" % videomode ) write ( "Final DVD Video format will be " + videomode ) #Loop through all the files files = media [ 0 ] . getElementsByTagName ( "file" ) filecount = 0 if files . length > 0 : write ( "There are %s file(s) to process" % files . length ) if debug_secondrunthrough == False : #Delete all the temporary files that currently exist deleteEverythingInFolder ( getTempPath ( ) ) localCopyFolder = os . path . join ( getTempPath ( ) , "localcopy" ) os . makedirs ( localCopyFolder ) files = copyRemote ( files , getTempPath ( ) ) #First pass through the files to be recorded - sense check #we dont want to find half way through this long process that #a file does not exist, or is the wrong format!! for node in files : filecount += 1 #Generate a temp folder name for this file folder = getItemTempPath ( filecount ) if debug_secondrunthrough == False : os . makedirs ( folder ) #Do the pre-process work preProcessFile ( node , folder , filecount ) if debug_secondrunthrough == False : #Loop through all the files again but this time do more serious work! filecount = 0 for node in files : filecount += 1 folder = getItemTempPath ( filecount ) #Process this file processFile ( node , folder , filecount ) #We can only create the menus after the videos have been processed #and the commercials cut out so we get the correct run time length #for the chapter marks and thumbnails. #create the DVD menus... if wantMainMenu : createMenu ( format , dpi , files . length ) #Submenus are visible when you select the chapter menu while the recording is playing if wantChapterMenu : createChapterMenu ( format , dpi , files . length ) #Details Page are displayed just before playing each recording if wantDetailsPage : createDetailsPage ( format , dpi , files . length ) #DVD Author file if not wantMainMenu and not wantChapterMenu : createDVDAuthorXMLNoMenus ( format , files . length ) elif not wantMainMenu : createDVDAuthorXMLNoMainMenu ( format , files . length ) else : createDVDAuthorXML ( format , files . length ) #Check all the files will fit onto a recordable DVD if mediatype == DVD_DL : # dual layer performMPEG2Shrink ( files , dvdrsize [ 1 ] ) else : #single layer performMPEG2Shrink ( files , dvdrsize [ 0 ] ) filecount = 0 for node in files : filecount += 1 folder = getItemTempPath ( filecount ) #Multiplex this file #(This also removes non-required audio feeds inside mpeg streams #(through re-multiplexing) we only take 1 video and 1 or 2 audio streams) pid = multiplexMPEGStream ( os . path . join ( folder , 'stream.mv2' ) , os . path . join ( folder , 'stream0' ) , os . path . join ( folder , 'stream1' ) , os . path . join ( folder , 'final.vob' ) , calcSyncOffset ( filecount ) ) #Now all the files are completed and ready to be burnt runDVDAuthor ( ) #Delete dvdauthor work files if debug_keeptempfiles == False : filecount = 0 for node in files : filecount += 1 folder = getItemTempPath ( filecount ) if os . path . exists ( os . path . join ( folder , "stream.mv2" ) ) : os . remove ( os . path . join ( folder , 'stream.mv2' ) ) if os . path . exists ( os . path . join ( folder , "stream0.mp2" ) ) : os . remove ( os . path . join ( folder , 'stream0.mp2' ) ) if os . path . exists ( os . path . join ( folder , "stream1.mp2" ) ) : os . remove ( os . path . join ( folder , 'stream1.mp2' ) ) if os . path . exists ( os . path . join ( folder , "stream0.ac3" ) ) : os . remove ( os . path . join ( folder , 'stream0.ac3' ) ) if os . path . exists ( os . path . join ( folder , "stream1.ac3" ) ) : os . remove ( os . path . join ( folder , 'stream1.ac3' ) ) #Get DVD title from first processed file #Get the XML containing information about this item infoDOM = xml . dom . minidom . parse ( os . path . join ( getItemTempPath ( 1 ) , "info.xml" ) ) #Error out if its the wrong XML if infoDOM . documentElement . tagName != "fileinfo" : fatalError ( "The info.xml file (%s) doesn't look right" % os . path . join ( folder , "info.xml" ) ) title = expandItemText ( infoDOM , "%title" , 1 , 0 , 0 , 0 , 0 ) # replace all non-ascii-characters title = title . encode ( 'ascii' , 'replace' ) . decode ( 'ascii' , 'replace' ) title = title . strip ( ) # replace not-allowed characters index = 0 title_new = '' while ( index < len ( title ) ) and ( index < 32 ) : if title [ index ] . isalnum and title [ index ] != ' ' : title_new += title [ index ] else : title_new += '_' index = index + 1 title = title_new . upper ( ) if len ( title ) < 1 : title = 'UNNAMED' #Create the DVD ISO image if docreateiso == True or mediatype == FILE : CreateDVDISO ( title ) #Burn the DVD ISO image if doburn == True and mediatype != FILE : BurnDVDISO ( title ) #Move the created iso image to the given location if mediatype == FILE and savefilename != "" : write ( "Moving ISO image to: %s" % savefilename ) try : os . rename ( os . path . join ( getTempPath ( ) , 'mythburn.iso' ) , savefilename ) except : f1 = open ( os . path . join ( getTempPath ( ) , 'mythburn.iso' ) , 'rb' ) f2 = open ( savefilename , 'wb' ) data = f1 . read ( 1024 * 1024 ) while data : f2 . write ( data ) data = f1 . read ( 1024 * 1024 ) f1 . close ( ) f2 . close ( ) os . unlink ( os . path . join ( getTempPath ( ) , 'mythburn.iso' ) ) else : write ( "Nothing to do! (files)" ) else : write ( "Nothing to do! (media)" ) return