Ticket #10071: mythburn.py_fixes.patch
File mythburn.py_fixes.patch, 37.1 KB (added by , 14 years ago) |
---|
-
(a) mythburn_0.24_fixes.git_4.10.2011.py vs. (b) mythburn_patched
a b 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 -i %s %s %d" % (filename, xmlFilename, lenMethod) 1963 1964 command = "mytharchivehelper -i %s %s %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 2086 2066 2087 result = runCommand(command) … … 2072 2093 2073 2094 2074 2095 # workout which files we need and rename them 2075 renameProjectXFiles(folder, pxbasename) 2096 video, audio1, audio2 = selectStreams(folder) 2097 if addSubtitles: 2098 subtitles = selectSubtitleStream(folder) 2099 2100 videoID_hex = "0x%x" % video[VIDEO_ID] 2101 if audio1[AUDIO_ID] != -1: 2102 audio1ID_hex = "0x%x" % audio1[AUDIO_ID] 2103 else: 2104 audio1ID_hex = "" 2105 if audio2[AUDIO_ID] != -1: 2106 audio2ID_hex = "0x%x" % audio2[AUDIO_ID] 2107 else: 2108 audio2ID_hex = "" 2109 if addSubtitles and subtitles[SUBTITLE_ID] != -1: 2110 subtitlesID_hex = "0x%x" % subtitles[SUBTITLE_ID] 2111 else: 2112 subtitlesID_hex = "" 2113 2114 2115 files = os.listdir(folder) 2116 for file in files: 2117 if file[0:9] == "stream{0x": # don't rename files that have already been renamed 2118 PID = file[7:13] 2119 SubID = file[19:23] 2120 if PID == videoID_hex or SubID == videoID_hex: 2121 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.mv2")) 2122 elif PID == audio1ID_hex or SubID == audio1ID_hex: 2123 os.rename(os.path.join(folder, file), os.path.join(folder, "stream0." + file[-3:])) 2124 elif PID == audio2ID_hex or SubID == audio2ID_hex: 2125 os.rename(os.path.join(folder, file), os.path.join(folder, "stream1." + file[-3:])) 2126 elif PID == subtitlesID_hex or SubID == subtitlesID_hex: 2127 if file[-3:] == "sup": 2128 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup")) 2129 else: 2130 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup.IFO")) 2131 2132 2133 # Fallback if assignment and renaming by ID failed 2134 2135 files = os.listdir(folder) 2136 for file in files: 2137 if file[0:9] == "stream{0x": # don't rename files that have already been renamed 2138 if not os.path.exists(os.path.join(folder, "stream.mv2")) and file[-3:] == "m2v": 2139 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.mv2")) 2140 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": 2141 os.rename(os.path.join(folder, file), os.path.join(folder, "stream0.ac3")) 2142 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": 2143 os.rename(os.path.join(folder, file), os.path.join(folder, "stream0.mp2")) 2144 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": 2145 os.rename(os.path.join(folder, file), os.path.join(folder, "stream1.ac3")) 2146 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": 2147 os.rename(os.path.join(folder, file), os.path.join(folder, "stream1.mp2")) 2148 elif not os.path.exists(os.path.join(folder, "stream.sup")) and file[-3:] == "sup": 2149 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup")) 2150 elif not os.path.exists(os.path.join(folder, "stream.sup.IFO")) and file[-3:] == "IFO": 2151 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup.IFO")) 2152 2076 2153 2077 2154 # if we have some dvb subtitles and the user wants to add them to the DVD 2078 2155 # convert them to pngs and create the spumux xml file … … 2081 2158 os.path.exists(os.path.join(folder, "stream.sup.IFO"))): 2082 2159 write("Found DVB subtitles converting to DVD subtitles") 2083 2160 command = "mytharchivehelper --sup2dast " 2084 command += " %s %s 0" % ( os.path.join(folder, "stream.sup"), os.path.join(folder, "stream.sup.IFO"))2161 command += " %s %s 0" % (quoteCmdArg(os.path.join(folder, "stream.sup")), quoteCmdArg(os.path.join(folder, "stream.sup.IFO"))) 2085 2162 2086 2163 result = runCommand(command) 2087 2164 … … 2096 2173 return True 2097 2174 2098 2175 ############################################################# 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 2176 # convert time stamp to pts 2221 2177 2222 2178 def ts2pts(time): … … 2286 2242 fr=frameratePAL 2287 2243 else: 2288 2244 fr=framerateNTSC 2289 2290 source = quoteFilename(source) 2291 2292 command = "mytharchivehelper -t %s '%s' %s" % (source, seconds, destination) 2245 command = "mytharchivehelper -t %s '%s' %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 -t %s '%s' %s" % (source, thumbList, destination) 2268 command = "mytharchivehelper -v important -t %s '%s' %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 … … 2567 2519 def CreateDVDISO(title): 2568 2520 write("Creating ISO image") 2569 2521 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')2522 command = quoteCmdArg(path_mkisofs[0]) + ' -dvd-video ' 2523 command += ' -V ' + quoteCmdArg(title) 2524 command += ' -o ' + quoteCmdArg(os.path.join(getTempPath(), 'mythburn.iso')) 2525 command += " " + quoteCmdArg(os.path.join(getTempPath(),'dvd')) 2574 2526 2575 2527 result = runCommand(command) 2576 2528 … … 2585 2537 2586 2538 def BurnDVDISO(title): 2587 2539 write( "Burning ISO image to %s" % dvddrivepath) 2588 checkCancelFlag()2589 2540 2590 2541 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); 2542 while not finished: 2543 # Maybe the user has no appropriate medium or something alike. Give her the chance to cancel. 2544 checkCancelFlag() 2596 2545 2597 if drivestatus == CDROM.CDS_DISC_OK or drivestatus == CDROM.CDS_NO_INFO: 2546 def drivestatus(): 2547 f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK) 2548 return ioctl(f,CDROM.CDROM_DRIVE_STATUS, 0) 2549 os.close(f); 2550 2551 # I drive needs some time (for example to close the tray) give it to it 2552 tries = 0 2553 while drivestatus() == CDROM.CDS_DRIVE_NOT_READY and tries < 6: 2554 time.sleep(5) 2555 tries += 1 2556 2557 if drivestatus() == CDROM.CDS_DISC_OK or drivestatus() == CDROM.CDS_NO_INFO: 2598 2558 2599 2559 # If the frontend has a previously burnt DVD+RW mounted, 2600 2560 # growisofs will fail to burn it, so try to pumount it first... 2601 runCommand("pumount " + dvddrivepath);2561 runCommand("pumount " + quoteCmdArg(dvddrivepath)); 2602 2562 2603 2563 if mediatype == DVD_RW and erasedvdrw == True: 2604 2564 command = path_growisofs[0] + " -dvd-compat " … … 2618 2578 write("Running growisofs to burn DVD") 2619 2579 2620 2580 result = runCommand(command) 2621 if result != 0: 2581 if result == 0: 2582 finished = True 2583 elif result == 252: 2584 write("-"*60) 2585 write("You probably inserted a medium of wrong type.") 2586 if mediatype == DVD_SL: 2587 write("Please insert an empty single-layer disc (DVD+R or DVD-R).") 2588 if mediatype == DVD_DL: 2589 write("Please insert an empty double-layer disc (DVD+R DL or DVD-R DL).") 2590 if mediatype == DVD_RW: 2591 write("Please insert a rewritable disc (DVD+RW or DVD-RW).") 2592 else: 2622 2593 write("-"*60) 2623 2594 write("ERROR: Failed while running growisofs.") 2624 2595 write("Result %d, Command was: %s" % (result, command)) 2625 2596 write("Please check the troubleshooting section of the README for ways to fix this error") 2626 2597 write("-"*60) 2627 2598 write("") 2628 sys.exit(1) 2629 finished = True 2599 write("Going to try it again until canceled by user:") 2600 write("-"*60) 2601 write("") 2630 2602 2631 2603 try: 2632 2604 # eject the burned disc 2605 runCommand("pumount " + quoteCmdArg(dvddrivepath)); 2633 2606 f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK) 2634 2607 r = ioctl(f,CDROM.CDROMEJECT, 0) 2635 2608 os.close(f) … … 2637 2610 write("Failed to eject the disc! " 2638 2611 "Maybe the media monitor has mounted it") 2639 2612 2640 elif drivestatus == CDROM.CDS_TRAY_OPEN: 2641 # Give the user 10secs to close the Tray 2613 elif drivestatus() == CDROM.CDS_TRAY_OPEN: 2642 2614 write("Waiting for tray to close.") 2643 time.sleep(10) 2644 elif drivestatus == CDROM.CDS_NO_DISC: 2615 # Wait until user closes tray or cancels 2616 while drivestatus() == CDROM.CDS_TRAY_OPEN: 2617 checkCancelFlag() 2618 time.sleep(5) 2619 elif drivestatus() == CDROM.CDS_NO_DISC: 2645 2620 # Open the Tray, if there is one. 2646 2621 write("Opening tray to get it fed with a DVD.") 2647 2622 f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK) 2648 2623 ioctl(f,CDROM.CDROMEJECT, 0) 2649 2624 os.close(f); 2650 elif drivestatus == CDROM.CDS_DRIVE_NOT_READY:2651 # Try a hard reset 2625 elif drivestatus() == CDROM.CDS_DRIVE_NOT_READY: 2626 # Try a hard reset if the device is still not ready 2652 2627 write("Trying a hard-reset of the device") 2653 2628 f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK) 2654 2629 ioctl(f,CDROM.CDROMEJECT, 0) 2655 2630 os.close(f); 2656 2631 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 2632 2663 2633 write("Finished burning ISO image") 2664 2634 … … 2669 2639 def deMultiplexMPEG2File(folder, mediafile, video, audio1, audio2): 2670 2640 2671 2641 if getFileType(folder) == "mpegts": 2672 command = "mythreplex --demux --fix_sync -t TS -o %s " % (folder + "/stream")2642 command = "mythreplex --demux --fix_sync -t TS -o %s " % quoteCmdArg(folder + "/stream") 2673 2643 command += "-v %d " % (video[VIDEO_ID]) 2674 2644 2675 2645 if audio1[AUDIO_ID] != -1: … … 2689 2659 command += "-c %d " % (audio2[AUDIO_ID]) 2690 2660 2691 2661 else: 2692 command = "mythreplex --demux --fix_sync -o %s " % (folder + "/stream")2662 command = "mythreplex --demux --fix_sync -o %s " % quoteCmdArg(folder + "/stream") 2693 2663 command += "-v %d " % (video[VIDEO_ID] & 255) 2694 2664 2695 2665 if audio1[AUDIO_ID] != -1: … … 2709 2679 elif audio2[AUDIO_CODEC] == 'EAC3': 2710 2680 command += "-c %d " % (audio2[AUDIO_ID] & 255) 2711 2681 2712 mediafile = quote Filename(mediafile)2682 mediafile = quoteCmdArg(mediafile) 2713 2683 command += mediafile 2714 2684 write("Running: " + command) 2715 2685 … … 2726 2696 M2Vsize0 = os.path.getsize(source) 2727 2697 write("Initial M2Vsize is %.2f Mb , target is %.2f Mb" % ( (float(M2Vsize0)/mega), (float(M2Vsize0)/(factor*mega)) )) 2728 2698 2729 command = path_M2VRequantiser[0]2699 command = quoteCmdArg(path_M2VRequantiser[0]) 2730 2700 command += " %.5f " % factor 2731 2701 command += " %s " % M2Vsize0 2732 command += " < %s " % source2733 command += " > %s " % destination2702 command += " < %s " % quoteCmdArg(source) 2703 command += " > %s " % quoteCmdArg(destination) 2734 2704 2735 2705 write("Running: " + command) 2736 2706 result = runCommand(command) 2707 if result<>0: 2708 fatalError("Failed while running M2VRequantiser. Command was %s" % command) 2737 2709 2738 2710 M2Vsize1 = os.path.getsize(destination) 2739 2711 2740 2712 write("M2Vsize after requant is %.2f Mb " % (float(M2Vsize1)/mega)) 2741 2713 fac1=float(M2Vsize0) / float(M2Vsize1) 2742 2714 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 2715 2747 2716 ############################################################# 2748 2717 # Calculates the total size of all the video, audio and menu files … … 3501 3470 height = getScaledAttribute(node, "h") 3502 3471 frames = int(secondsToFrames(menulength)) 3503 3472 3504 command = "mytharchivehelper -t %s '%s' '%s' %d" % (inputfile, starttime, outputfile, frames)3473 command = "mytharchivehelper -t %s '%s' '%s' %d" % (quoteCmdArg(inputfile), starttime, quoteCmdArg(outputfile), frames) 3505 3474 result = runCommand(command) 3506 3475 if (result != 0): 3507 3476 write( "mytharchivehelper failed with code %d. Command = %s" % (result, command) ) … … 4367 4336 # 2. if there is one or more stream(s) using the 2nd preferred language we use that 4368 4337 # 3. if we still haven't found a stream we use the stream with the lowest PID 4369 4338 # 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 PID4339 # 5. if there are more than one stream with the chosen language we use the one with the lowest PID 4371 4340 4372 4341 write("Preferred audio languages %s and %s" % (preferredlang1, preferredlang2)) 4373 4342 … … 5091 5060 tmpfile = node.attributes["filename"].value 5092 5061 filename = os.path.basename(tmpfile) 5093 5062 5094 res = runCommand("mytharchivehelper -r " + quoteFilename(tmpfile)) 5063 res = runCommand("mytharchivehelper -r " + quoteCmdArg(tmpfile)) 5064 5095 5065 if res == 2: 5096 5066 # file is on a remote filesystem so copy it to a local file 5097 5067 write("Copying file from " + tmpfile) … … 5156 5126 5157 5127 write( "Final DVD Video format will be " + videomode) 5158 5128 5159 #Ensure the destination dvd folder is empty5160 if doesFileExist(os.path.join(getTempPath(),"dvd")):5161 deleteAllFilesInFolder(os.path.join(getTempPath(),"dvd"))5162 5129 5163 5130 #Loop through all the files 5164 5131 files=media[0].getElementsByTagName("file") … … 5168 5135 5169 5136 if debug_secondrunthrough==False: 5170 5137 #Delete all the temporary files that currently exist 5171 delete AllFilesInFolder(getTempPath())5138 deleteEverythingInFolder(getTempPath()) 5172 5139 5173 5140 #If User wants to, copy remote files to a tmp dir 5174 5141 if copyremoteFiles==True: 5175 5142 if debug_secondrunthrough==False: 5176 5143 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 5144 os.makedirs(localCopyFolder) 5184 5145 files=copyRemote(files,getTempPath()) 5185 5146 … … 5193 5154 folder=getItemTempPath(filecount) 5194 5155 5195 5156 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 5157 os.makedirs(folder) 5211 5158 #Do the pre-process work 5212 5159 preProcessFile(node,folder,filecount)