Ticket #1895: mythburn-copyremote.patch
File mythburn-copyremote.patch, 9.0 KB (added by , 18 years ago) |
---|
-
mythburn/scripts/mythburn.py
old new 51 51 ##very much quicker! 52 52 debug_secondrunthrough = False 53 53 54 #If set to true remote files are copied to local folder before processing. 55 copyremoteFiles = False 56 54 57 #********************************************************************************* 55 58 #Dont change the stuff below!! 56 59 #********************************************************************************* … … 933 936 #write( "Original file is",os.path.getsize(mediafile),"bytes in size") 934 937 getFileInformation(file, os.path.join(folder, "info.xml")) 935 938 939 if file.hasAttribute("localfilename"): 940 mediafile = file.attributes["localfilename"].value 941 936 942 getStreamInformation(mediafile, os.path.join(folder, "streaminfo.xml")) 937 943 938 944 videosize = getVideoSize(os.path.join(folder, "streaminfo.xml")) … … 1026 1032 1027 1033 return (width, height) 1028 1034 1029 def runMythtranscode(chanid, starttime, destination, usecutlist ):1035 def runMythtranscode(chanid, starttime, destination, usecutlist, localfile): 1030 1036 """Use mythtrancode to cut commercials and/or clean up an mpeg2 file""" 1031 1037 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) 1034 1043 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) 1036 1048 1037 1049 result = runCommand(command) 1038 1050 … … 2510 2522 mediafile="" 2511 2523 2512 2524 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) 2514 2526 elif file.attributes["type"].value=="video": 2515 2527 mediafile=os.path.join(videopath, file.attributes["filename"].value) 2516 2528 elif file.attributes["type"].value=="file": … … 2532 2544 write("Video codec is '%s'" % getVideoCodec(folder)) 2533 2545 if string.lower(getVideoCodec(folder)) == "mpeg2video": 2534 2546 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 = "" 2535 2552 write("File has a cut list - attempting to run mythtrancode to remove unwanted segments") 2536 2553 chanid = getText(infoDOM.getElementsByTagName("chanid")[0]) 2537 2554 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): 2539 2556 mediafile = os.path.join(folder,'tmp') 2540 2557 else: 2541 2558 write("Failed to run mythtranscode to remove unwanted segments") … … 2543 2560 #does the user always want to run recordings through mythtranscode? 2544 2561 #may help to fix any errors in the file 2545 2562 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 = "" 2546 2568 write("Attempting to run mythtranscode --mpeg2 to fix any errors") 2547 2569 chanid = getText(infoDOM.getElementsByTagName("chanid")[0]) 2548 2570 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): 2550 2572 mediafile = os.path.join(folder, 'newfile.mpg') 2551 2573 else: 2552 2574 write("Failed to run mythtrancode to fix any errors") … … 2565 2587 2566 2588 write("File is not DVD compliant - Re-encoding audio and video") 2567 2589 2590 # Run from local file? 2591 if file.hasAttribute("localfilename"): 2592 mediafile = file.attributes["localfilename"].value 2593 2568 2594 #do the re-encode 2569 2595 encodeVideoToMPEG2(mediafile, os.path.join(folder, "newfile2.mpg"), video, audio1, audio2, aspectratio) 2570 2596 mediafile = os.path.join(folder, 'newfile2.mpg') … … 2603 2629 write( "Finished processing file " + file.attributes["filename"].value) 2604 2630 write( "*************************************************************") 2605 2631 2632 def 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 2606 2682 2607 2683 def processJob(job): 2608 2684 """Starts processing a MythBurn job, expects XML nodes to be passed as input.""" … … 2663 2739 #Delete all the temporary files that currently exist 2664 2740 deleteAllFilesInFolder(getTempPath()) 2665 2741 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 2666 2755 #First pass through the files to be recorded - sense check 2667 2756 #we dont want to find half way through this long process that 2668 2757 #a file does not exist, or is the wrong format!!