Ticket #1895: mythburn-copyremote.patch

File mythburn-copyremote.patch, 9.0 KB (added by lukas.kasprowicz@…, 19 years ago)

Patch file

  • mythburn/scripts/mythburn.py

    old new  
    5151##very much quicker!
    5252debug_secondrunthrough = False
    5353
     54#If set to true remote files are copied to local folder before processing.
     55copyremoteFiles = False
     56
    5457#*********************************************************************************
    5558#Dont change the stuff below!!
    5659#*********************************************************************************
     
    933936    #write( "Original file is",os.path.getsize(mediafile),"bytes in size")
    934937    getFileInformation(file, os.path.join(folder, "info.xml"))
    935938
     939    if file.hasAttribute("localfilename"):
     940            mediafile = file.attributes["localfilename"].value
     941
    936942    getStreamInformation(mediafile, os.path.join(folder, "streaminfo.xml"))
    937943
    938944    videosize = getVideoSize(os.path.join(folder, "streaminfo.xml"))
     
    10261032
    10271033    return (width, height)
    10281034
    1029 def runMythtranscode(chanid, starttime, destination, usecutlist):
     1035def runMythtranscode(chanid, starttime, destination, usecutlist, localfile):
    10301036    """Use mythtrancode to cut commercials and/or clean up an mpeg2 file"""
    10311037
    1032     if usecutlist == True:
    1033         command = "mythtranscode --mpeg2 --honorcutlist -c %s -s %s -o %s" % (chanid, starttime, destination)
     1038    if localfile != "":
     1039        if usecutlist == True:
     1040            command = "mythtranscode --mpeg2 --honorcutlist -i %s -o %s" % (localfile, destination)
     1041        else:
     1042            command = "mythtranscode --mpeg2 -i %s -o %s" % (localfile, destination)
    10341043    else:
    1035         command = "mythtranscode --mpeg2 -c %s -s %s -o %s" % (chanid, starttime, destination)
     1044        if usecutlist == True:
     1045            command = "mythtranscode --mpeg2 --honorcutlist -c %s -s %s -o %s" % (chanid, starttime, destination)
     1046        else:
     1047            command = "mythtranscode --mpeg2 -c %s -s %s -o %s" % (chanid, starttime, destination)
    10361048
    10371049    result = runCommand(command)
    10381050
     
    25102522    mediafile=""
    25112523
    25122524    if file.attributes["type"].value=="recording":
    2513         mediafile=os.path.join(recordingpath, file.attributes["filename"].value)
     2525        mediafile = os.path.join(recordingpath, file.attributes["filename"].value)
    25142526    elif file.attributes["type"].value=="video":
    25152527        mediafile=os.path.join(videopath, file.attributes["filename"].value)
    25162528    elif file.attributes["type"].value=="file":
     
    25322544        write("Video codec is '%s'" % getVideoCodec(folder))
    25332545        if string.lower(getVideoCodec(folder)) == "mpeg2video":
    25342546            if file.attributes["usecutlist"].value == "1" and getText(infoDOM.getElementsByTagName("hascutlist")[0]) == "yes":
     2547                # Run from local file?
     2548                if file.hasAttribute("localfilename"):
     2549                    localfile = file.attributes["localfilename"].value
     2550                else:
     2551                    localfile = ""
    25352552                write("File has a cut list - attempting to run mythtrancode to remove unwanted segments")
    25362553                chanid = getText(infoDOM.getElementsByTagName("chanid")[0])
    25372554                starttime = getText(infoDOM.getElementsByTagName("starttime")[0])
    2538                 if runMythtranscode(chanid, starttime, os.path.join(folder,'tmp'), True):
     2555                if runMythtranscode(chanid, starttime, os.path.join(folder,'tmp'), True, localfile):
    25392556                    mediafile = os.path.join(folder,'tmp')
    25402557                else:
    25412558                    write("Failed to run mythtranscode to remove unwanted segments")
     
    25432560                #does the user always want to run recordings through mythtranscode?
    25442561                #may help to fix any errors in the file
    25452562                if alwaysRunMythtranscode == True or (getFileType(folder) == "mpegts" and isFileOkayForDVD(folder)):
     2563                    # Run from local file?
     2564                    if file.hasAttribute("localfilename"):
     2565                        localfile = file.attributes["localfilename"].value
     2566                    else:
     2567                        localfile = ""
    25462568                    write("Attempting to run mythtranscode --mpeg2 to fix any errors")
    25472569                    chanid = getText(infoDOM.getElementsByTagName("chanid")[0])
    25482570                    starttime = getText(infoDOM.getElementsByTagName("starttime")[0])
    2549                     if runMythtranscode(chanid, starttime, os.path.join(folder, 'newfile.mpg'), False):
     2571                    if runMythtranscode(chanid, starttime, os.path.join(folder, 'newfile.mpg'), False, localfile):
    25502572                        mediafile = os.path.join(folder, 'newfile.mpg')
    25512573                    else:
    25522574                        write("Failed to run mythtrancode to fix any errors")
     
    25652587
    25662588        write("File is not DVD compliant - Re-encoding audio and video")
    25672589
     2590        # Run from local file?
     2591        if file.hasAttribute("localfilename"):
     2592            mediafile = file.attributes["localfilename"].value
     2593
    25682594        #do the re-encode
    25692595        encodeVideoToMPEG2(mediafile, os.path.join(folder, "newfile2.mpg"), video, audio1, audio2, aspectratio)
    25702596        mediafile = os.path.join(folder, 'newfile2.mpg')
     
    26032629    write( "Finished processing file " + file.attributes["filename"].value)
    26042630    write( "*************************************************************")
    26052631
     2632def copyRemote(files,tmpPath):
     2633    from shutil import copy
     2634
     2635    localTmpPath = os.path.join(tmpPath, "localcopy")
     2636    # Define remote filesystems
     2637    remotefs = ['nfs','smbfs']
     2638    remotemounts = []
     2639    # What does mount say?
     2640    mounts = os.popen('mount')
     2641    # Go through each line of mounts output
     2642    for line in mounts.readlines():
     2643        parts = line.split()
     2644        # mount says in this format
     2645        device, txt1, mountpoint, txt2, filesystem, options = parts
     2646        # only do if really remote
     2647        if filesystem in remotefs:
     2648            # add remote to list
     2649            remotemounts.append(string.split(mountpoint,'/'))
     2650            # go through files
     2651            for node in files:
     2652                # go through list
     2653                for mount in remotemounts:
     2654                    # Recordings have no path in xml file generated by mytharchive.
     2655                    #
     2656                    # Maybe better to put real path in xml like file and video have it.
     2657                    if node.attributes["type"].value == "recording":
     2658                        tmpfile = string.split(os.path.join(recordingpath, node.attributes["filename"].value), '/')
     2659                    else:
     2660                        tmpfile = string.split(node.attributes["filename"].value, '/')
     2661                    filename = tmpfile[len(tmpfile)-1]
     2662                    tmpfiledirs=""
     2663                    tmpremotedir=""
     2664                    # path has to be minimum length of mountpoint
     2665                    if len(tmpfile) > len(mount):
     2666                        for i in range(len(mount)):
     2667                            tmpfiledirs = tmpfiledirs + tmpfile[i] + "/"
     2668                        for i in range(len(mount)):
     2669                            tmpremotedir = tmpremotedir + mount[i] + "/"
     2670                        # Is it like the mount point?
     2671                        if tmpfiledirs == tmpremotedir:
     2672                            # Write that we copy
     2673                            write("Copying file from " +os.path.join(recordingpath, node.attributes["filename"].value))
     2674                            write("to " + os.path.join(localTmpPath, filename))
     2675                            # Copy file
     2676                            if not doesFileExist(os.path.join(localTmpPath, filename)):
     2677                                copy(os.path.join(recordingpath, node.attributes["filename"].value),os.path.join(localTmpPath, filename))
     2678                            # update node
     2679                            node.setAttribute("localfilename", os.path.join(localTmpPath, filename))
     2680                            print node.attributes["localfilename"].value
     2681    return files
    26062682
    26072683def processJob(job):
    26082684    """Starts processing a MythBurn job, expects XML nodes to be passed as input."""
     
    26632739                #Delete all the temporary files that currently exist
    26642740                deleteAllFilesInFolder(getTempPath())
    26652741
     2742            #If User wants to, copy remote files to a tmp dir
     2743            if copyremoteFiles==True:
     2744                if debug_secondrunthrough==False:
     2745                    localCopyFolder=os.path.join(getTempPath(),"localcopy")
     2746                    #If it already exists destroy it to remove previous debris
     2747                    if os.path.exists(localCopyFolder):
     2748                        #Remove all the files first
     2749                        deleteAllFilesInFolder(localCopyFolder)
     2750                        #Remove the folder
     2751                        os.rmdir (localCopyFolder)
     2752                    os.makedirs(localCopyFolder)
     2753                files=copyRemote(files,getTempPath())
     2754
    26662755            #First pass through the files to be recorded - sense check
    26672756            #we dont want to find half way through this long process that
    26682757            #a file does not exist, or is the wrong format!!