Ticket #10071: mythburn.py.patch
File mythburn.py.patch, 38.1 KB (added by , 14 years ago) |
---|
-
mythburn.
old new 1 1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 2 3 # mythburn.py 3 4 # The ported MythBurn scripts which feature: 4 5 … … 31 32 #pyfribidi 32 33 33 34 #Optional (alternate demuxer) 34 #ProjectX - 0.90.4.0035 #ProjectX - >=0.91 35 36 36 37 #****************************************************************************** 37 38 #****************************************************************************** 38 39 #****************************************************************************** 39 40 41 42 # All strings in this file should be unicode, not byte string!! They get converted to utf-8 only 43 44 45 46 40 47 # version of script - change after each update 41 48 VERSION="0.1.20101206-1" 42 49 … … 239 246 240 247 def write(text, progress=True): 241 248 """Simple place to channel all text output through""" 249 250 text = text.encode("utf-8", "replace") 242 251 sys.stdout.write(text + "\n") 243 252 sys.stdout.flush() 244 253 … … 253 262 """Display an error message and exit app""" 254 263 write("*"*60) 255 264 write("ERROR: " + msg) 265 write("See mythburn.log for more information.") 256 266 write("*"*60) 257 267 write("") 258 268 saveSetting("MythArchiveLastRunResult", "Failed: " + quoteString(msg)); … … 287 297 # Try to work out how many cpus we have available 288 298 289 299 def getCPUCount(): 290 """return the number of CPU 's"""300 """return the number of CPUs""" 291 301 cpustat = open("/proc/cpuinfo") 292 302 cpudata = cpustat.readlines() 293 303 cpustat.close() … … 349 359 350 360 def getDatabaseConnection(): 351 361 """Returns a mySQL connection to mythconverg database.""" 352 return MySQLdb.connect(host=mysql_host, user=mysql_user, passwd=mysql_passwd, db=mysql_db, init_command='SET NAMES utf8')362 return MySQLdb.connect(host=mysql_host, user=mysql_user, passwd=mysql_passwd, db=mysql_db, charset="utf8", use_unicode=True) 353 363 354 364 ############################################################# 355 365 # Returns true/false if a given file or path exists. … … 359 369 return os.path.exists( file ) 360 370 361 371 ############################################################# 362 # Escape quotes in a filename372 # Escape quotes in a command line argument 363 373 364 def quote Filename(filename):365 filename = filename.replace('"', '\\"')366 filename = filename.replace('`', '\\`')367 return '"%s"' % filename374 def quoteCmdArg(arg): 375 arg = arg.replace('"', '\\"') 376 arg = arg.replace('`', '\\`') 377 return '"%s"' % arg 368 378 369 379 ############################################################# 370 380 # Returns the text contents from a given XML element. … … 436 446 os.remove(os.path.join(root, name)) 437 447 438 448 ############################################################# 449 # Romoves all the objects from a directory 450 451 def deleteEverythingInFolder(folder): 452 for root, dirs, files in os.walk(folder, topdown=False): 453 for name in files: 454 os.remove(os.path.join(root, name)) 455 for name in dirs: 456 if os.path.islink(os.path.join(root, name)): 457 os.remove(os.path.join(root, name)) 458 else: 459 os.rmdir(os.path.join(root, name)) 460 461 ############################################################# 439 462 # Check to see if the user has cancelled the DVD creation process 440 463 441 464 def checkCancelFlag(): … … 454 477 def runCommand(command): 455 478 checkCancelFlag() 456 479 457 result = os.system(command) 480 # mytharchivehelper needes this locale to work correctly 481 try: 482 oldlocale = os.environ["LC_ALL"] 483 except: 484 oldlocale = "" 485 os.putenv("LC_ALL", "en_US.UTF-8") 486 result = os.system(command.encode('utf-8')) 487 os.putenv("LC_ALL", oldlocale) 458 488 459 489 if os.WIFEXITED(result): 460 490 result = os.WEXITSTATUS(result) … … 485 515 486 516 totalframes=int(musiclength * framespersecond) 487 517 488 command = path_jpeg2yuv[0] + " -n %s -v0 -I p -f %s -j '%s' | %s -b 5000 -a %s -v 1 -f 8 -o '%s'" \489 % (totalframes, framespersecond, background, path_mpeg2enc[0], aspectratio, tempvideo)518 command = quoteCmdArg(path_jpeg2yuv[0]) + " -n %s -v0 -I p -f %s -j %s | %s -b 5000 -a %s -v 1 -f 8 -o %s" \ 519 % (totalframes, framespersecond, quoteCmdArg(background), quoteCmdArg(path_mpeg2enc[0]), aspectratio, quoteCmdArg(tempvideo)) 490 520 result = runCommand(command) 491 521 if result<>0: 492 522 fatalError("Failed while running jpeg2yuv - %s" % command) 493 523 494 command = path_mplex[0] + " -f 8 -v 0 -o '%s' '%s' '%s'" % (tempmovie, tempvideo, music)524 command = quoteCmdArg(path_mplex[0]) + " -f 8 -v 0 -o %s %s %s" % (quoteCmdArg(tempmovie), quoteCmdArg(tempvideo), quoteCmdArg(music)) 495 525 result = runCommand(command) 496 526 if result<>0: 497 527 fatalError("Failed while running mplex - %s" % command) 498 528 499 529 if xmlfile != "": 500 command = path_spumux[0] + " -m dvd -s 0 '%s' < '%s' > '%s'" % (xmlfile, tempmovie, finaloutput)530 command = quoteCmdArg(path_spumux[0]) + " -m dvd -s 0 %s < %s > %s" % (quoteCmdArg(xmlfile), quoteCmdArg(tempmovie), quoteCmdArg(finaloutput)) 501 531 result = runCommand(command) 502 532 if result<>0: 503 533 fatalError("Failed while running spumux - %s" % command) … … 1509 1539 top_element.appendChild(node) 1510 1540 1511 1541 node = infoDOM.createElement("title") 1512 node.appendChild(infoDOM.createTextNode( unicode(record[6], "UTF-8")))1542 node.appendChild(infoDOM.createTextNode(record[6])) 1513 1543 top_element.appendChild(node) 1514 1544 1515 1545 #date time is returned as 2005-12-19 00:15:00 … … 1523 1553 top_element.appendChild(node) 1524 1554 1525 1555 node = infoDOM.createElement("subtitle") 1526 node.appendChild(infoDOM.createTextNode(unicode(record[5], "UTF-8"))) 1556 node.appendChild(infoDOM.createTextNode(record[5])) 1557 1527 1558 top_element.appendChild(node) 1528 1559 1529 1560 node = infoDOM.createElement("description") 1530 node.appendChild(infoDOM.createTextNode(unicode(record[4], "UTF-8"))) 1561 node.appendChild(infoDOM.createTextNode(record[4])) 1562 1531 1563 top_element.appendChild(node) 1532 1564 1533 1565 node = infoDOM.createElement("rating") … … 1630 1662 top_element.appendChild(node) 1631 1663 1632 1664 node = infoDOM.createElement("title") 1633 node.appendChild(infoDOM.createTextNode( unicode(record[0], "UTF-8")))1665 node.appendChild(infoDOM.createTextNode(record[0])) 1634 1666 top_element.appendChild(node) 1635 1667 1636 1668 node = infoDOM.createElement("recordingdate") … … 1647 1679 top_element.appendChild(node) 1648 1680 1649 1681 node = infoDOM.createElement("subtitle") 1650 node.appendChild(infoDOM.createTextNode( unicode(record[9], "UTF-8")))1682 node.appendChild(infoDOM.createTextNode(record[9])) 1651 1683 top_element.appendChild(node) 1652 1684 1653 1685 node = infoDOM.createElement("description") 1654 1686 if record[2] != None: 1655 desc = unicode(record[2], "UTF-8")1687 desc = record[2] 1656 1688 if desc != "None": 1657 1689 node.appendChild(infoDOM.createTextNode(desc)) 1658 1690 else: … … 1805 1837 def encodeAudio(format, sourcefile, destinationfile, deletesourceafterencode): 1806 1838 write( "Encoding audio to "+format) 1807 1839 if format == "ac3": 1808 cmd = path_ffmpeg[0]+ " -v 0 -y "1840 cmd = quoteCmdArg(path_ffmpeg[0]) + " -v 0 -y " 1809 1841 1810 1842 if cpuCount > 1: 1811 1843 cmd += "-threads %d " % cpuCount 1812 1844 1813 cmd += "-i '%s' -f ac3 -ab 192k -ar 48000 '%s'" % (sourcefile, destinationfile)1845 cmd += "-i %s -f ac3 -ab 192k -ar 48000 %s" % (quoteCmdArg(sourcefile), quoteCmdArg(destinationfile)) 1814 1846 result = runCommand(cmd) 1815 1847 1816 1848 if result != 0: … … 1904 1936 # run spumux to add subtitles if they exist 1905 1937 if os.path.exists(os.path.dirname(destination) + "/stream.d/spumux.xml"): 1906 1938 write("Checking integrity of subtitle pngs") 1907 command = os.path.join(scriptpath, "testsubtitlepngs.sh") + " %s/stream.d/spumux.xml" % (os.path.dirname(destination))1939 command = quoteCmdArg(os.path.join(scriptpath, "testsubtitlepngs.sh")) + " " + quoteCmdArg(os.path.dirname(destination) + "/stream.d/spumux.xml") 1908 1940 result = runCommand(command) 1909 1941 if result<>0: 1910 1942 fatalError("Failed while running testsubtitlepngs.sh - %s" % command) 1911 1943 1912 1944 write("Running spumux to add subtitles") 1913 command = path_spumux[0] + " -P %s/stream.d/spumux.xml <%s >%s" % (os.path.dirname(destination), destination, os.path.splitext(destination)[0] + "-sub.mpg")1945 command = quoteCmdArg(path_spumux[0]) + " -P %s <%s >%s" % (quoteCmdArg(os.path.dirname(destination) + "/stream.d/spumux.xml"), quoteCmdArg(destination), quoteCmdArg(os.path.splitext(destination)[0] + "-sub.mpg")) 1914 1946 result = runCommand(command) 1915 1947 if result<>0: 1916 1948 nonfatalError("Failed while running spumux.\n" … … 1928 1960 1929 1961 def getStreamInformation(filename, xmlFilename, lenMethod): 1930 1962 """create a stream.xml file for filename""" 1931 filename = quoteFilename(filename) 1932 command = "mytharchivehelper --getfileinfo --infile %s --outfile %s --method %d" % (filename, xmlFilename, lenMethod) 1963 1964 command = "mytharchivehelper --getfileinfo --infile %s --outfile %s --method %d" % (quoteCmdArg(filename), quoteCmdArg(xmlFilename), lenMethod) 1965 write(command) 1933 1966 1934 1967 result = runCommand(command) 1935 1968 … … 1938 1971 1939 1972 # print out the streaminfo.xml file to the log 1940 1973 infoDOM = xml.dom.minidom.parse(xmlFilename) 1941 write( "streaminfo.xml:-\n" + infoDOM.toprettyxml(" ", ""), False)1974 write(xmlFilename + ":-\n" + infoDOM.toprettyxml(" ", ""), False) 1942 1975 1943 1976 ############################################################# 1944 1977 # Gets the video width and height from a file's stream xml file … … 1971 2004 """Use mythtranscode to cut commercials and/or clean up an mpeg2 file""" 1972 2005 1973 2006 if localfile != "": 1974 localfile = quoteFilename(localfile)1975 2007 if usecutlist == True: 1976 command = "mythtranscode --mpeg2 --honorcutlist -i %s -o %s" % ( localfile, destination)2008 command = "mythtranscode --mpeg2 --honorcutlist -i %s -o %s" % (quoteCmdArg(localfile), quoteCmdArg(destination)) 1977 2009 else: 1978 command = "mythtranscode --mpeg2 -i %s -o %s" % ( localfile, destination)2010 command = "mythtranscode --mpeg2 -i %s -o %s" % (quoteCmdArg(localfile), quoteCmdArg(destination)) 1979 2011 else: 1980 2012 if usecutlist == True: 1981 command = "mythtranscode --mpeg2 --honorcutlist -c %s -s %s -o %s" % (chanid, starttime, destination)2013 command = "mythtranscode --mpeg2 --honorcutlist -c %s -s %s -o %s" % (chanid, starttime, quoteCmdArg(destination)) 1982 2014 else: 1983 command = "mythtranscode --mpeg2 -c %s -s %s -o %s" % (chanid, starttime, destination)2015 command = "mythtranscode --mpeg2 -c %s -s %s -o %s" % (chanid, starttime, quoteCmdArg(destination)) 1984 2016 1985 2017 result = runCommand(command) 1986 2018 … … 2043 2075 write("Failed to generate Project-X cutlist.") 2044 2076 return False 2045 2077 2046 pxbasename = os.path.splitext(os.path.basename(file))[0]2047 2048 2078 if os.path.exists(file) != True: 2049 2079 write("Error: input file doesn't exist on local filesystem") 2050 2080 return False 2051 2081 2052 2053 qdestdir = quoteFilename(folder) 2054 qpxbasename = quoteFilename(pxbasename) 2055 qfile = quoteFilename(file) 2056 qcutlist = os.path.join(folder, "cutlist_x.txt") 2057 2058 command = path_projectx[0] + " -id %s" % getStreamList(folder) 2082 command = quoteCmdArg(path_projectx[0]) + " %s -id '%s' -set ExternPanel.appendPidToFileName=1 -out %s -name stream" % (quoteCmdArg(file), getStreamList(folder), quoteCmdArg(folder)) 2059 2083 if usecutlist == True: 2060 command += " -cut %s -out %s -name %s %s" % (qcutlist, qdestdir, qpxbasename, qfile) 2061 else: 2062 command += " -out %s -name %s %s" % (qdestdir, qpxbasename, qfile) 2063 2084 command += " -cut %s" % quoteCmdArg(os.path.join(folder, "cutlist_x.txt")) 2064 2085 write(command) 2065 2066 2086 result = runCommand(command) 2067 2087 2068 2088 if (result != 0): … … 2072 2092 2073 2093 2074 2094 # workout which files we need and rename them 2075 renameProjectXFiles(folder, pxbasename) 2095 video, audio1, audio2 = selectStreams(folder) 2096 if addSubtitles: 2097 subtitles = selectSubtitleStream(folder) 2098 2099 videoID_hex = "0x%x" % video[VIDEO_ID] 2100 if audio1[AUDIO_ID] != -1: 2101 audio1ID_hex = "0x%x" % audio1[AUDIO_ID] 2102 else: 2103 audio1ID_hex = "" 2104 if audio2[AUDIO_ID] != -1: 2105 audio2ID_hex = "0x%x" % audio2[AUDIO_ID] 2106 else: 2107 audio2ID_hex = "" 2108 if addSubtitles and subtitles[SUBTITLE_ID] != -1: 2109 subtitlesID_hex = "0x%x" % subtitles[SUBTITLE_ID] 2110 else: 2111 subtitlesID_hex = "" 2112 2113 2114 files = os.listdir(folder) 2115 for file in files: 2116 if file[0:9] == "stream{0x": # don't rename files that have already been renamed 2117 PID = file[7:13] 2118 SubID = file[19:23] 2119 if PID == videoID_hex or SubID == videoID_hex: 2120 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.mv2")) 2121 elif PID == audio1ID_hex or SubID == audio1ID_hex: 2122 os.rename(os.path.join(folder, file), os.path.join(folder, "stream0." + file[-3:])) 2123 elif PID == audio2ID_hex or SubID == audio2ID_hex: 2124 os.rename(os.path.join(folder, file), os.path.join(folder, "stream1." + file[-3:])) 2125 elif PID == subtitlesID_hex or SubID == subtitlesID_hex: 2126 if file[-3:] == "sup": 2127 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup")) 2128 else: 2129 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup.IFO")) 2130 2131 2132 # Fallback if assignment and renaming by ID failed 2133 2134 files = os.listdir(folder) 2135 for file in files: 2136 if file[0:9] == "stream{0x": # don't rename files that have already been renamed 2137 if not os.path.exists(os.path.join(folder, "stream.mv2")) and file[-3:] == "m2v": 2138 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.mv2")) 2139 elif not (os.path.exists(os.path.join(folder, "stream0.ac3")) or os.path.exists(os.path.join(folder, "stream0.mp2"))) and file[-3:] == "ac3": 2140 os.rename(os.path.join(folder, file), os.path.join(folder, "stream0.ac3")) 2141 elif not (os.path.exists(os.path.join(folder, "stream0.ac3")) or os.path.exists(os.path.join(folder, "stream0.mp2"))) and file[-3:] == "mp2": 2142 os.rename(os.path.join(folder, file), os.path.join(folder, "stream0.mp2")) 2143 elif not (os.path.exists(os.path.join(folder, "stream1.ac3")) or os.path.exists(os.path.join(folder, "stream1.mp2"))) and file[-3:] == "ac3": 2144 os.rename(os.path.join(folder, file), os.path.join(folder, "stream1.ac3")) 2145 elif not (os.path.exists(os.path.join(folder, "stream1.ac3")) or os.path.exists(os.path.join(folder, "stream1.mp2"))) and file[-3:] == "mp2": 2146 os.rename(os.path.join(folder, file), os.path.join(folder, "stream1.mp2")) 2147 elif not os.path.exists(os.path.join(folder, "stream.sup")) and file[-3:] == "sup": 2148 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup")) 2149 elif not os.path.exists(os.path.join(folder, "stream.sup.IFO")) and file[-3:] == "IFO": 2150 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup.IFO")) 2151 2076 2152 2077 2153 # if we have some dvb subtitles and the user wants to add them to the DVD 2078 2154 # convert them to pngs and create the spumux xml file … … 2081 2157 os.path.exists(os.path.join(folder, "stream.sup.IFO"))): 2082 2158 write("Found DVB subtitles converting to DVD subtitles") 2083 2159 command = "mytharchivehelper --sup2dast " 2084 command += " --infile %s --ifofile %s --delay 0" % ( os.path.join(folder, "stream.sup"), os.path.join(folder, "stream.sup.IFO"))2160 command += " --infile %s --ifofile %s --delay 0" % (quoteCmdArg(os.path.join(folder, "stream.sup")), quoteCmdArg(os.path.join(folder, "stream.sup.IFO"))) 2085 2161 2086 2162 result = runCommand(command) 2087 2163 … … 2096 2172 return True 2097 2173 2098 2174 ############################################################# 2099 # find the required stream files and rename them2100 2101 def renameProjectXFiles(folder, pxbasename):2102 2103 write("renameProjectXFiles start -----------------------------------------", False)2104 logf = open(os.path.join(folder, pxbasename + "_log.txt"))2105 logdata = logf.readlines()2106 logf.close()2107 2108 # find stream PIDs and Files2109 streamIds = []2110 streamFiles = []2111 for line in logdata:2112 tokens = line.split()2113 if len(tokens) > 0:2114 if tokens[0] == "++>":2115 # From ProjectX/resources/pjxresources_en.properties:2116 if tokens[1] == "Mpg":2117 if tokens[2] == "Video:":2118 write("found MPEG video stream %s" % tokens[4], False)2119 streamIds.append(int(tokens[4], 16))2120 if tokens[2] == "Audio:":2121 write("found MPEG audio stream %s" % tokens[4], False)2122 streamIds.append(int(tokens[4], 16))2123 if tokens[1] == "AC3/DTS":2124 write("found AC3/DTS audio stream %s" % tokens[4], False)2125 streamIds.append(int(tokens[4], 16))2126 if tokens[1] == "LPCM":2127 write("found LPCM audio stream %s" % tokens[4], False)2128 streamIds.append(int(tokens[4], 16))2129 if tokens[1] == "Teletext:":2130 write("found Teletext stream %s" % tokens[3], False)2131 streamIds.append(int(tokens[3], 16))2132 if tokens[1] == "Subpicture:":2133 write("found Subpicture stream %s" % tokens[3], False)2134 streamIds.append(int(tokens[3], 16))2135 if tokens[1] == "Generic_VBI:":2136 write("found Generic_VBI stream %s" % tokens[3], False)2137 streamIds.append(int(tokens[3], 16))2138 if tokens[0] == "--->":2139 if tokens[1] == "new":2140 if tokens[2] == "File:":2141 write("found file for stream 0x%x, %s" % (streamIds[len(streamIds)-1], tokens[3]), False)2142 streamFiles.append(tokens[3].replace("'","")) # let's hope the path never has a space in it2143 if tokens[0] == "-->":2144 if tokens[1] == "stream":2145 if tokens[2] == "omitted":2146 write("stream 0x%x omitted" % streamIds[len(streamIds)-1], False)2147 streamFiles.append("")2148 2149 write("streadmIds=%s" % streamIds)2150 write("streamFiles=%s" % streamFiles)2151 2152 # choose which streams we need2153 video, audio1, audio2 = selectStreams(folder)2154 2155 if getFileType(folder) == "mpeg":2156 videoID = video[VIDEO_ID] & 2552157 audio1ID = audio1[AUDIO_ID] & 2552158 audio2ID = audio2[AUDIO_ID] & 2552159 else:2160 videoID = video[VIDEO_ID]2161 audio1ID = audio1[AUDIO_ID]2162 audio2ID = audio2[AUDIO_ID]2163 2164 # sanity check - we should have a file for each ID2165 if len(streamIds) == len(streamFiles):2166 # loop thought the available streams looking for the ones we want2167 for stream in streamIds:2168 write("got stream: %d" % stream, False)2169 if stream == videoID:2170 write("found video streamID", False)2171 if os.path.exists(streamFiles[streamIds.index(stream)]):2172 write("found video stream file", False)2173 os.rename(streamFiles[streamIds.index(stream)], os.path.join(folder, "stream.mv2"))2174 2175 if stream == audio1ID:2176 write("found audio1 streamID", False)2177 if os.path.exists(streamFiles[streamIds.index(stream)]):2178 write("found audio1 stream file", False)2179 if audio1[AUDIO_CODEC] == "AC3":2180 os.rename(streamFiles[streamIds.index(stream)], os.path.join(folder, "stream0.ac3"))2181 else:2182 os.rename(streamFiles[streamIds.index(stream)], os.path.join(folder, "stream0.mp2"))2183 2184 if stream == audio2ID:2185 write("found audio2 streamID", False)2186 if os.path.exists(streamFiles[streamIds.index(stream)]):2187 write("found audio2 stream file", False)2188 if audio2[AUDIO_CODEC] == "AC3":2189 os.rename(streamFiles[streamIds.index(stream)], os.path.join(folder, "stream1.ac3"))2190 else:2191 os.rename(streamFiles[streamIds.index(stream)], os.path.join(folder, "stream1.mp2"))2192 2193 # final chance to find the correct stream files2194 if not os.path.exists(os.path.join(folder, "stream.mv2")):2195 if os.path.exists(os.path.join(folder, pxbasename + ".m2v")):2196 os.rename(os.path.join(folder, pxbasename + ".m2v"), os.path.join(folder, "stream.mv2"))2197 2198 if not os.path.exists(os.path.join(folder, "stream0.mp2")) or not os.path.exists(os.path.join(folder, "stream0.ac3")):2199 if os.path.exists(os.path.join(folder, pxbasename + ".mp2")):2200 os.rename(os.path.join(folder, pxbasename + ".mp2"), os.path.join(folder, "stream0.mp2"))2201 if os.path.exists(os.path.join(folder, pxbasename + ".ac3")):2202 os.rename(os.path.join(folder, pxbasename + ".ac3"), os.path.join(folder, "stream0.ac3"))2203 2204 if not os.path.exists(os.path.join(folder, "stream1.mp2")) or not os.path.exists(os.path.join(folder, "stream1.ac3")):2205 if os.path.exists(os.path.join(folder, pxbasename + "[1].mp2")):2206 os.rename(os.path.join(folder, pxbasename + "[1].mp2"), os.path.join(folder, "stream1.mp2"))2207 if os.path.exists(os.path.join(folder, pxbasename + "[1].ac3")):2208 os.rename(os.path.join(folder, pxbasename + "[1].ac3"), os.path.join(folder, "stream1.ac3"))2209 2210 # do we have any subtitle files2211 if os.path.exists(os.path.join(folder, pxbasename + ".sup")):2212 os.rename(os.path.join(folder, pxbasename + ".sup"), os.path.join(folder, "stream.sup"))2213 2214 if os.path.exists(os.path.join(folder, pxbasename + ".sup.IFO")):2215 os.rename(os.path.join(folder, pxbasename + ".sup.IFO"), os.path.join(folder, "stream.sup.IFO"))2216 2217 write("renameProjectXFiles end -----------------------------------------", False)2218 2219 #############################################################2220 2175 # convert time stamp to pts 2221 2176 2222 2177 def ts2pts(time): … … 2287 2242 else: 2288 2243 fr=framerateNTSC 2289 2244 2290 source = quoteFilename(source) 2291 2292 command = "mytharchivehelper --createthumbnail --infile %s --thumblist '%s' --outfile %s" % (source, seconds, destination) 2245 command = "mytharchivehelper --createthumbnail --infile %s --thumblist '%s' --outfile %s" % (quoteCmdArg(source), seconds, quoteCmdArg(destination)) 2293 2246 result = runCommand(command) 2294 2247 if result <> 0: 2295 2248 fatalError("Failed while running mytharchivehelper to get thumbnails.\n" … … 2312 2265 write("Extracting thumbnail images from: %s - at %s" % (source, thumbList)) 2313 2266 write("Destination file %s" % destination) 2314 2267 2315 source = quoteFilename(source) 2316 2317 command = "mytharchivehelper -v important --createthumbnail --infile %s --thumblist '%s' --outfile %s" % (source, thumbList, destination) 2268 command = "mytharchivehelper -v important --createthumbnail --infile %s --thumblist '%s' --outfile %s" % (quoteCmdArg(source), thumbList, quoteCmdArg(destination)) 2269 write(command) 2318 2270 result = runCommand(command) 2319 2271 if result <> 0: 2320 2272 fatalError("Failed while running mytharchivehelper to get thumbnails") … … 2329 2281 2330 2282 passes = int(getText(profileNode.getElementsByTagName("passes")[0])) 2331 2283 2332 command = path_ffmpeg[0]2284 command = quoteCmdArg(path_ffmpeg[0]) 2333 2285 2334 2286 if cpuCount > 1: 2335 2287 command += " -threads %d" % cpuCount … … 2342 2294 2343 2295 # do some parameter substitution 2344 2296 if value == "%inputfile": 2345 value = quote Filename(source)2297 value = quoteCmdArg(source) 2346 2298 if value == "%outputfile": 2347 value = quote Filename(destvideofile)2299 value = quoteCmdArg(destvideofile) 2348 2300 if value == "%aspect": 2349 2301 value = aspectratio 2350 2302 … … 2398 2350 passLog = os.path.join(getTempPath(), 'pass') 2399 2351 2400 2352 pass1 = string.replace(command, "%passno","1") 2401 pass1 = string.replace(pass1, "%passlogfile", passLog)2353 pass1 = string.replace(pass1, "%passlogfile", quoteCmdArg(passLog)) 2402 2354 write("Pass 1 - " + pass1) 2403 2355 result = runCommand(pass1) 2404 2356 … … 2410 2362 os.remove(destvideofile) 2411 2363 2412 2364 pass2 = string.replace(command, "%passno","2") 2413 pass2 = string.replace(pass2, "%passlogfile", passLog)2365 pass2 = string.replace(pass2, "%passlogfile", quoteCmdArg(passLog)) 2414 2366 write("Pass 2 - " + pass2) 2415 2367 result = runCommand(pass2) 2416 2368 … … 2515 2467 samplerate, channels = getAudioParams(folder) 2516 2468 videores, fps, aspectratio = getVideoParams(folder) 2517 2469 2518 command = path_ffmpeg[0]+ " -y "2470 command = quoteCmdArg(path_ffmpeg[0]) + " -y " 2519 2471 2520 2472 if cpuCount > 1: 2521 2473 command += "-threads %d " % cpuCount 2522 2474 2523 command += "-f s16le -ar %s -ac %s -i %s " % (samplerate, channels, os.path.join(folder, "audout"))2475 command += "-f s16le -ar %s -ac %s -i %s " % (samplerate, channels, quoteCmdArg(os.path.join(folder, "audout"))) 2524 2476 command += "-f rawvideo -pix_fmt yuv420p -s %s -aspect %s -r %s " % (videores, aspectratio, fps) 2525 command += "-i %s " % os.path.join(folder, "vidout")2477 command += "-i %s " % quoteCmdArg(os.path.join(folder, "vidout")) 2526 2478 command += "-aspect %s -r %s " % (aspectratio, fps) 2527 2479 if (deinterlace == 1): 2528 2480 command += "-deinterlace " … … 2530 2482 command += "-s %s -b %s -vcodec mpeg2video " % (outvideores, outvideobitrate) 2531 2483 command += "-qmin %s -qmax %s -qdiff %s " % (qmin, qmax, qdiff) 2532 2484 command += "-ab %s -ar %s -acodec %s " % (outaudiobitrate, outaudiosamplerate, outaudiocodec) 2533 command += "-f dvd %s" % quote Filename(destvideofile)2485 command += "-f dvd %s" % quoteCmdArg(destvideofile) 2534 2486 2535 2487 #wait for mythtranscode to create the fifos 2536 2488 tries = 30 … … 2556 2508 def runDVDAuthor(): 2557 2509 write( "Starting dvdauthor") 2558 2510 checkCancelFlag() 2511 # Scheint hier ohne escapes richtig zu sein. Warum hier anders in subprocess als anderswo (runCommand)? 2512 # See http://docs.python.org/library/subprocess.html#subprocess-replacements 2559 2513 result=os.spawnlp(os.P_WAIT, path_dvdauthor[0],path_dvdauthor[1],'-x',os.path.join(getTempPath(),'dvdauthor.xml')) 2560 2514 if result<>0: 2561 2515 fatalError("Failed while running dvdauthor. Result: %d" % result) … … 2567 2521 def CreateDVDISO(title): 2568 2522 write("Creating ISO image") 2569 2523 checkCancelFlag() 2570 command = path_mkisofs[0]+ ' -dvd-video '2571 command += ' -V ' + quote Filename(title)2572 command += ' -o ' + os.path.join(getTempPath(), 'mythburn.iso')2573 command += " " + os.path.join(getTempPath(),'dvd')2524 command = quoteCmdArg(path_mkisofs[0]) + ' -dvd-video ' 2525 command += ' -V ' + quoteCmdArg(title) 2526 command += ' -o ' + quoteCmdArg(os.path.join(getTempPath(), 'mythburn.iso')) 2527 command += " " + quoteCmdArg(os.path.join(getTempPath(),'dvd')) 2574 2528 2575 2529 result = runCommand(command) 2576 2530 … … 2585 2539 2586 2540 def BurnDVDISO(title): 2587 2541 write( "Burning ISO image to %s" % dvddrivepath) 2588 checkCancelFlag()2589 2542 2590 2543 finished = False 2591 tries = 0 2592 while not finished and tries < 10: 2593 f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK) 2594 drivestatus = ioctl(f,CDROM.CDROM_DRIVE_STATUS, 0) 2595 os.close(f); 2544 while not finished: 2545 # Maybe the user has no appropriate medium or something alike. Give her the chance to cancel. 2546 checkCancelFlag() 2596 2547 2597 if drivestatus == CDROM.CDS_DISC_OK or drivestatus == CDROM.CDS_NO_INFO: 2548 def drivestatus(): 2549 f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK) 2550 return ioctl(f,CDROM.CDROM_DRIVE_STATUS, 0) 2551 os.close(f); 2552 2553 # I drive needs some time (for example to close the tray) give it to it 2554 tries = 0 2555 while drivestatus() == CDROM.CDS_DRIVE_NOT_READY and tries < 6: 2556 time.sleep(5) 2557 tries += 1 2558 2559 if drivestatus() == CDROM.CDS_DISC_OK or drivestatus() == CDROM.CDS_NO_INFO: 2598 2560 2599 2561 # If the frontend has a previously burnt DVD+RW mounted, 2600 2562 # growisofs will fail to burn it, so try to pumount it first... 2601 runCommand("pumount " + dvddrivepath);2563 runCommand("pumount " + quoteCmdArg(dvddrivepath)); 2602 2564 2603 2565 if mediatype == DVD_RW and erasedvdrw == True: 2604 2566 command = path_growisofs[0] + " -dvd-compat " … … 2618 2580 write("Running growisofs to burn DVD") 2619 2581 2620 2582 result = runCommand(command) 2621 if result != 0: 2583 if result == 0: 2584 finished = True 2585 elif result == 252: 2586 write("-"*60) 2587 write("You probably inserted a medium of wrong type.") 2588 if mediatype == DVD_SL: 2589 write("Please insert an empty single-layer disc (DVD+R or DVD-R).") 2590 if mediatype == DVD_DL: 2591 write("Please insert an empty double-layer disc (DVD+R DL or DVD-R DL).") 2592 if mediatype == DVD_RW: 2593 write("Please insert a rewritable disc (DVD+RW or DVD-RW).") 2594 else: 2622 2595 write("-"*60) 2623 2596 write("ERROR: Failed while running growisofs.") 2624 2597 write("Result %d, Command was: %s" % (result, command)) 2625 2598 write("Please check the troubleshooting section of the README for ways to fix this error") 2626 2599 write("-"*60) 2627 2600 write("") 2628 sys.exit(1) 2629 finished = True 2601 write("Going to try it again until canceled by user:") 2602 write("-"*60) 2603 write("") 2630 2604 2631 2605 try: 2632 2606 # eject the burned disc 2607 runCommand("pumount " + quoteCmdArg(dvddrivepath)); 2633 2608 f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK) 2634 2609 r = ioctl(f,CDROM.CDROMEJECT, 0) 2635 2610 os.close(f) … … 2637 2612 write("Failed to eject the disc! " 2638 2613 "Maybe the media monitor has mounted it") 2639 2614 2640 elif drivestatus == CDROM.CDS_TRAY_OPEN: 2641 # Give the user 10secs to close the Tray 2615 elif drivestatus() == CDROM.CDS_TRAY_OPEN: 2642 2616 write("Waiting for tray to close.") 2643 time.sleep(10) 2644 elif drivestatus == CDROM.CDS_NO_DISC: 2617 # Wait until user closes tray or cancels 2618 while drivestatus() == CDROM.CDS_TRAY_OPEN: 2619 checkCancelFlag() 2620 time.sleep(5) 2621 elif drivestatus() == CDROM.CDS_NO_DISC: 2645 2622 # Open the Tray, if there is one. 2646 2623 write("Opening tray to get it fed with a DVD.") 2647 2624 f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK) 2648 2625 ioctl(f,CDROM.CDROMEJECT, 0) 2649 2626 os.close(f); 2650 elif drivestatus == CDROM.CDS_DRIVE_NOT_READY:2651 # Try a hard reset 2627 elif drivestatus() == CDROM.CDS_DRIVE_NOT_READY: 2628 # Try a hard reset if the device is still not ready 2652 2629 write("Trying a hard-reset of the device") 2653 2630 f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK) 2654 2631 ioctl(f,CDROM.CDROMEJECT, 0) 2655 2632 os.close(f); 2656 2633 2657 time.sleep(1)2658 tries += 12659 2660 if not finished:2661 fatalError("Tried 10 times to get a good status from DVD drive - Giving up!")2662 2634 2663 2635 write("Finished burning ISO image") 2664 2636 … … 2669 2641 def deMultiplexMPEG2File(folder, mediafile, video, audio1, audio2): 2670 2642 2671 2643 if getFileType(folder) == "mpegts": 2672 command = "mythreplex --demux --fix_sync -t TS -o %s " % (folder + "/stream")2644 command = "mythreplex --demux --fix_sync -t TS -o %s " % quoteCmdArg(folder + "/stream") 2673 2645 command += "-v %d " % (video[VIDEO_ID]) 2674 2646 2675 2647 if audio1[AUDIO_ID] != -1: … … 2689 2661 command += "-c %d " % (audio2[AUDIO_ID]) 2690 2662 2691 2663 else: 2692 command = "mythreplex --demux --fix_sync -o %s " % (folder + "/stream")2664 command = "mythreplex --demux --fix_sync -o %s " % quoteCmdArg(folder + "/stream") 2693 2665 command += "-v %d " % (video[VIDEO_ID] & 255) 2694 2666 2695 2667 if audio1[AUDIO_ID] != -1: … … 2709 2681 elif audio2[AUDIO_CODEC] == 'EAC3': 2710 2682 command += "-c %d " % (audio2[AUDIO_ID] & 255) 2711 2683 2712 mediafile = quote Filename(mediafile)2684 mediafile = quoteCmdArg(mediafile) 2713 2685 command += mediafile 2714 2686 write("Running: " + command) 2715 2687 … … 2726 2698 M2Vsize0 = os.path.getsize(source) 2727 2699 write("Initial M2Vsize is %.2f Mb , target is %.2f Mb" % ( (float(M2Vsize0)/mega), (float(M2Vsize0)/(factor*mega)) )) 2728 2700 2729 command = path_M2VRequantiser[0]2701 command = quoteCmdArg(path_M2VRequantiser[0]) 2730 2702 command += " %.5f " % factor 2731 2703 command += " %s " % M2Vsize0 2732 command += " < %s " % source2733 command += " > %s " % destination2704 command += " < %s " % quoteCmdArg(source) 2705 command += " > %s " % quoteCmdArg(destination) 2734 2706 2735 2707 write("Running: " + command) 2736 2708 result = runCommand(command) 2709 if result<>0: 2710 fatalError("Failed while running M2VRequantiser. Command was %s" % command) 2737 2711 2738 2712 M2Vsize1 = os.path.getsize(destination) 2739 2713 2740 2714 write("M2Vsize after requant is %.2f Mb " % (float(M2Vsize1)/mega)) 2741 2715 fac1=float(M2Vsize0) / float(M2Vsize1) 2742 2716 write("Factor demanded %.5f, achieved %.5f, ratio %.5f " % ( factor, fac1, fac1/factor)) 2743 2744 if result<>0:2745 fatalError("Failed while running M2VRequantiser. Command was %s" % command)2746 2717 2747 2718 ############################################################# 2748 2719 # Calculates the total size of all the video, audio and menu files … … 3501 3472 height = getScaledAttribute(node, "h") 3502 3473 frames = int(secondsToFrames(menulength)) 3503 3474 3504 command = "mytharchivehelper --createthumbnail --infile %s --thumblist '%s' --outfile '%s' --framecount %d" % (inputfile, starttime, outputfile, frames)3475 command = "mytharchivehelper --createthumbnail --infile %s --thumblist '%s' --outfile %s --framecount %d" % (quoteCmdArg(inputfile), starttime, quoteCmdArg(outputfile), frames) 3505 3476 result = runCommand(command) 3506 3477 if (result != 0): 3507 3478 write( "mytharchivehelper failed with code %d. Command = %s" % (result, command) ) … … 4367 4338 # 2. if there is one or more stream(s) using the 2nd preferred language we use that 4368 4339 # 3. if we still haven't found a stream we use the stream with the lowest PID 4369 4340 # 4. we prefer ac3 over mp2 4370 # 5. if there are more tha tone stream with the chosen language we use the one with the lowest PID4341 # 5. if there are more than one stream with the chosen language we use the one with the lowest PID 4371 4342 4372 4343 write("Preferred audio languages %s and %s" % (preferredlang1, preferredlang2)) 4373 4344 … … 5091 5062 tmpfile = node.attributes["filename"].value 5092 5063 filename = os.path.basename(tmpfile) 5093 5064 5094 res = runCommand("mytharchivehelper --isremote --infile " + quote Filename(tmpfile))5065 res = runCommand("mytharchivehelper --isremote --infile " + quoteCmdArg(tmpfile)) 5095 5066 if res == 2: 5096 5067 # file is on a remote filesystem so copy it to a local file 5097 5068 write("Copying file from " + tmpfile) … … 5156 5127 5157 5128 write( "Final DVD Video format will be " + videomode) 5158 5129 5159 #Ensure the destination dvd folder is empty5160 if doesFileExist(os.path.join(getTempPath(),"dvd")):5161 deleteAllFilesInFolder(os.path.join(getTempPath(),"dvd"))5162 5130 5163 5131 #Loop through all the files 5164 5132 files=media[0].getElementsByTagName("file") … … 5168 5136 5169 5137 if debug_secondrunthrough==False: 5170 5138 #Delete all the temporary files that currently exist 5171 delete AllFilesInFolder(getTempPath())5139 deleteEverythingInFolder(getTempPath()) 5172 5140 5173 5141 #If User wants to, copy remote files to a tmp dir 5174 5142 if copyremoteFiles==True: 5175 5143 if debug_secondrunthrough==False: 5176 5144 localCopyFolder=os.path.join(getTempPath(),"localcopy") 5177 #If it already exists destroy it to remove previous debris5178 if os.path.exists(localCopyFolder):5179 #Remove all the files first5180 deleteAllFilesInFolder(localCopyFolder)5181 #Remove the folder5182 os.rmdir (localCopyFolder)5183 5145 os.makedirs(localCopyFolder) 5184 5146 files=copyRemote(files,getTempPath()) 5185 5147 … … 5193 5155 folder=getItemTempPath(filecount) 5194 5156 5195 5157 if debug_secondrunthrough==False: 5196 #If it already exists destroy it to remove previous debris5197 if os.path.exists(folder):5198 #Remove all the files first5199 deleteAllFilesInFolder(folder)5200 subtitlefolder = os.path.join(folder, "stream.d")5201 if os.path.exists(subtitlefolder):5202 deleteAllFilesInFolder(subtitlefolder)5203 os.rmdir(subtitlefolder)5204 previewfolder = os.path.join(folder, "preview")5205 if os.path.exists(previewfolder):5206 deleteAllFilesInFolder(previewfolder)5207 os.rmdir(previewfolder)5208 #Remove the folder5209 os.rmdir (folder)5210 5158 os.makedirs(folder) 5211 5159 #Do the pre-process work 5212 5160 preProcessFile(node,folder,filecount) … … 5537 5485 5538 5486 if __name__ == "__main__": 5539 5487 main() 5488