Ticket #10071: mythburn20111006.patch
File mythburn20111006.patch, 54.0 KB (added by , 13 years ago) |
---|
-
.py
old new 1 1 2 #!/usr/bin/env python2.7 3 # -*- coding: utf-8 -*- 2 4 # mythburn.py 3 5 # The ported MythBurn scripts which feature: 4 6 … … 26 28 27 29 #Optional for shrink-to-fit requantisation 28 30 #M2VRequantiser (from flexion, based on the newer code from Metakine) 31 # Download available from https://launchpad.net/m2vrequantiser/ 29 32 30 33 #Optional (for Right To Left languages) 31 34 #pyfribidi 32 35 33 36 #Optional (alternate demuxer) 34 #ProjectX - 0.90.4.0037 #ProjectX >= 0.91 from http://project-x.cvs.sourceforge.net/project-x/Project-X/ 35 38 36 39 #****************************************************************************** 37 40 #****************************************************************************** 38 41 #****************************************************************************** 39 42 43 44 # All strings in this file should be unicode, not byte string!! They get converted to utf-8 only 45 40 46 # version of script - change after each update 41 VERSION="0.1.20101206-1" 47 VERSION="0.1.20101206-1jp-0.24framecutlist+ticket10071" 48 49 # Local setting. Set location of generated iso image, preferably not on the arctmp spindle 50 isopath="/mnt/f10store/myth/arctmp/isos/mythburn.iso" # is not stored in the db 42 51 43 52 # keep all temporary files for debugging purposes 44 53 # set this to True before a first run through when testing … … 94 103 95 104 #Single and dual layer recordable DVD free space in MBytes 96 105 dvdrsize=(4482,8106) 106 #dvdrsize=(400,8106) 97 107 98 108 frameratePAL=25 99 109 framerateNTSC=29.97 … … 102 112 aspectRatioThreshold = 1.4 103 113 104 114 #Just blank globals at startup 115 105 116 temppath="" 106 117 logpath="" 107 118 scriptpath="" … … 239 250 240 251 def write(text, progress=True): 241 252 """Simple place to channel all text output through""" 253 254 text = text.encode("utf-8", "replace") 242 255 sys.stdout.write(text + "\n") 243 256 sys.stdout.flush() 244 257 245 258 if progress == True and progresslog != "": 246 progressfile.write(time.strftime("%Y-%m-%d %H:%M:%S ") + text + "\n") 247 progressfile.flush() 259 if len(text)<30 : 260 progressfile.write(time.strftime("%H:%M:%S %Y-%m-%d ") + text + "\n") 261 else: 262 progressfile.write(time.strftime("%H:%M:%S ") + text + "\n") 263 264 progressfile.flush() 248 265 249 266 ############################################################# 250 267 # Display an error message and exit … … 253 270 """Display an error message and exit app""" 254 271 write("*"*60) 255 272 write("ERROR: " + msg) 273 write("See mythburn.log for more information.") 256 274 write("*"*60) 257 275 write("") 258 276 saveSetting("MythArchiveLastRunResult", "Failed: " + quoteString(msg)); … … 287 305 # Try to work out how many cpus we have available 288 306 289 307 def getCPUCount(): 290 """return the number of CPU 's"""308 """return the number of CPUs""" 291 309 cpustat = open("/proc/cpuinfo") 292 310 cpudata = cpustat.readlines() 293 311 cpustat.close() … … 349 367 350 368 def getDatabaseConnection(): 351 369 """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')370 return MySQLdb.connect(host=mysql_host, user=mysql_user, passwd=mysql_passwd, db=mysql_db, charset="utf8", use_unicode=True) 353 371 354 372 ############################################################# 355 373 # Returns true/false if a given file or path exists. … … 359 377 return os.path.exists( file ) 360 378 361 379 ############################################################# 362 # Escape quotes in a filename380 # Escape quotes in a command line argument 363 381 364 def quote Filename(filename):365 filename = filename.replace('"', '\\"')366 filename = filename.replace('`', '\\`')367 return '"%s"' % filename382 def quoteCmdArg(arg): 383 arg = arg.replace('"', '\\"') 384 arg = arg.replace('`', '\\`') 385 return '"%s"' % arg 368 386 369 387 ############################################################# 370 388 # Returns the text contents from a given XML element. … … 436 454 os.remove(os.path.join(root, name)) 437 455 438 456 ############################################################# 457 # Romoves all the objects from a directory 458 459 def deleteEverythingInFolder(folder): 460 for root, dirs, files in os.walk(folder, topdown=False): 461 for name in files: 462 os.remove(os.path.join(root, name)) 463 for name in dirs: 464 if os.path.islink(os.path.join(root, name)): 465 os.remove(os.path.join(root, name)) 466 else: 467 os.rmdir(os.path.join(root, name)) 468 469 ############################################################# 439 470 # Check to see if the user has cancelled the DVD creation process 440 471 441 472 def checkCancelFlag(): … … 454 485 def runCommand(command): 455 486 checkCancelFlag() 456 487 457 result = os.system(command) 488 # mytharchivehelper needes this locale to work correctly 489 try: 490 oldlocale = os.environ["LC_ALL"] 491 except: 492 oldlocale = "" 493 os.putenv("LC_ALL", "en_US.UTF-8") 494 result = os.system(command.encode('utf-8')) 495 os.putenv("LC_ALL", oldlocale) 458 496 459 497 if os.WIFEXITED(result): 460 498 result = os.WEXITSTATUS(result) 461 499 checkCancelFlag() 462 500 return result 501 502 ############################################################ 503 # Truncate to even value ( to silence 'odd y-coordinate' complaints) 504 505 def even(num): 506 evennum = int(num / 2) * 2 507 return evennum 508 463 509 464 510 ############################################################# 465 511 # Convert a time in seconds to a frame number … … 485 531 486 532 totalframes=int(musiclength * framespersecond) 487 533 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) 534 command = "ionice -c3 " 535 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" \ 536 % (totalframes, framespersecond, quoteCmdArg(background), quoteCmdArg(path_mpeg2enc[0]), aspectratio, quoteCmdArg(tempvideo)) 490 537 result = runCommand(command) 491 538 if result<>0: 492 539 fatalError("Failed while running jpeg2yuv - %s" % command) 493 540 494 command = path_mplex[0] + " -f 8 -v 0 -o '%s' '%s' '%s'" % (tempmovie, tempvideo, music) 541 command = "ionice -c3 " 542 command += quoteCmdArg(path_mplex[0]) + " -f 8 -v 0 -o %s %s %s" % (quoteCmdArg(tempmovie), quoteCmdArg(tempvideo), quoteCmdArg(music)) 495 543 result = runCommand(command) 496 544 if result<>0: 497 545 fatalError("Failed while running mplex - %s" % command) 498 546 499 547 if xmlfile != "": 500 command = path_spumux[0] + " -m dvd -s 0 '%s' < '%s' > '%s'" % (xmlfile, tempmovie, finaloutput) 548 command = "ionice -c3 " 549 command += quoteCmdArg(path_spumux[0]) + " -m dvd -s 0 %s < %s > %s" % (quoteCmdArg(xmlfile), quoteCmdArg(tempmovie), quoteCmdArg(finaloutput)) 501 550 result = runCommand(command) 502 551 if result<>0: 503 552 fatalError("Failed while running spumux - %s" % command) … … 1509 1558 top_element.appendChild(node) 1510 1559 1511 1560 node = infoDOM.createElement("title") 1512 node.appendChild(infoDOM.createTextNode( unicode(record[6], "UTF-8")))1561 node.appendChild(infoDOM.createTextNode(record[6])) 1513 1562 top_element.appendChild(node) 1514 1563 1515 1564 #date time is returned as 2005-12-19 00:15:00 … … 1523 1572 top_element.appendChild(node) 1524 1573 1525 1574 node = infoDOM.createElement("subtitle") 1526 node.appendChild(infoDOM.createTextNode(unicode(record[5], "UTF-8"))) 1575 node.appendChild(infoDOM.createTextNode(record[5])) 1576 1527 1577 top_element.appendChild(node) 1528 1578 1529 1579 node = infoDOM.createElement("description") 1530 node.appendChild(infoDOM.createTextNode(unicode(record[4], "UTF-8"))) 1580 node.appendChild(infoDOM.createTextNode(record[4])) 1581 1531 1582 top_element.appendChild(node) 1532 1583 1533 1584 node = infoDOM.createElement("rating") … … 1630 1681 top_element.appendChild(node) 1631 1682 1632 1683 node = infoDOM.createElement("title") 1633 node.appendChild(infoDOM.createTextNode( unicode(record[0], "UTF-8")))1684 node.appendChild(infoDOM.createTextNode(record[0])) 1634 1685 top_element.appendChild(node) 1635 1686 1636 1687 node = infoDOM.createElement("recordingdate") … … 1647 1698 top_element.appendChild(node) 1648 1699 1649 1700 node = infoDOM.createElement("subtitle") 1650 node.appendChild(infoDOM.createTextNode( unicode(record[9], "UTF-8")))1701 node.appendChild(infoDOM.createTextNode(record[9])) 1651 1702 top_element.appendChild(node) 1652 1703 1653 1704 node = infoDOM.createElement("description") 1654 1705 if record[2] != None: 1655 desc = unicode(record[2], "UTF-8")1706 desc = record[2] 1656 1707 if desc != "None": 1657 1708 node.appendChild(infoDOM.createTextNode(desc)) 1658 1709 else: … … 1805 1856 def encodeAudio(format, sourcefile, destinationfile, deletesourceafterencode): 1806 1857 write( "Encoding audio to "+format) 1807 1858 if format == "ac3": 1808 cmd = path_ffmpeg[0]+ " -v 0 -y "1859 cmd = quoteCmdArg(path_ffmpeg[0]) + " -v 0 -y " 1809 1860 1810 1861 if cpuCount > 1: 1811 1862 cmd += "-threads %d " % cpuCount 1812 1863 1813 cmd += "-i '%s' -f ac3 -ab 192k -ar 48000 '%s'" % (sourcefile, destinationfile)1864 cmd += "-i %s -f ac3 -ab 192k -ar 48000 %s" % (quoteCmdArg(sourcefile), quoteCmdArg(destinationfile)) 1814 1865 result = runCommand(cmd) 1815 1866 1816 1867 if result != 0: … … 1899 1950 return result 1900 1951 else: 1901 1952 if result != 0: 1902 fatalError("mplex failed with result %d" % result)1953 nonfatalError("mplex failed with result %d" % result) 1903 1954 1904 1955 # run spumux to add subtitles if they exist 1905 1956 if os.path.exists(os.path.dirname(destination) + "/stream.d/spumux.xml"): 1906 1957 write("Checking integrity of subtitle pngs") 1907 command = os.path.join(scriptpath, "testsubtitlepngs.sh") + " %s/stream.d/spumux.xml" % (os.path.dirname(destination))1958 command = quoteCmdArg(os.path.join(scriptpath, "testsubtitlepngs.sh")) + " " + quoteCmdArg(os.path.dirname(destination) + "/stream.d/spumux.xml") 1908 1959 result = runCommand(command) 1909 1960 if result<>0: 1910 1961 fatalError("Failed while running testsubtitlepngs.sh - %s" % command) 1911 1962 1912 1963 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") 1964 1965 command = "ionice -c3 " 1966 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 1967 result = runCommand(command) 1915 1968 if result<>0: 1916 1969 nonfatalError("Failed while running spumux.\n" … … 1928 1981 1929 1982 def getStreamInformation(filename, xmlFilename, lenMethod): 1930 1983 """create a stream.xml file for filename""" 1931 filename = quoteFilename(filename) 1932 command = "mytharchivehelper -i %s %s %d" % (filename, xmlFilename, lenMethod) 1984 1985 command = "mytharchivehelper -i %s %s %d" % (quoteCmdArg(filename), quoteCmdArg(xmlFilename), lenMethod) 1986 write(command) 1933 1987 1934 1988 result = runCommand(command) 1935 1989 … … 1938 1992 1939 1993 # print out the streaminfo.xml file to the log 1940 1994 infoDOM = xml.dom.minidom.parse(xmlFilename) 1941 write( "streaminfo.xml:-\n" + infoDOM.toprettyxml(" ", ""), False)1995 write(xmlFilename + ":-\n" + infoDOM.toprettyxml(" ", ""), False) 1942 1996 1943 1997 ############################################################# 1944 1998 # Gets the video width and height from a file's stream xml file … … 1971 2025 """Use mythtranscode to cut commercials and/or clean up an mpeg2 file""" 1972 2026 1973 2027 if localfile != "": 1974 localfile = quoteFilename(localfile)1975 2028 if usecutlist == True: 1976 command = "mythtranscode --mpeg2 --honorcutlist -i %s -o %s" % ( localfile, destination)2029 command = "mythtranscode --mpeg2 --honorcutlist -i %s -o %s" % (quoteCmdArg(localfile), quoteCmdArg(destination)) 1977 2030 else: 1978 command = "mythtranscode --mpeg2 -i %s -o %s" % ( localfile, destination)2031 command = "mythtranscode --mpeg2 -i %s -o %s" % (quoteCmdArg(localfile), quoteCmdArg(destination)) 1979 2032 else: 1980 2033 if usecutlist == True: 1981 command = "mythtranscode --mpeg2 --honorcutlist -c %s -s %s -o %s" % (chanid, starttime, destination)2034 command = "mythtranscode --mpeg2 --honorcutlist -c %s -s %s -o %s" % (chanid, starttime, quoteCmdArg(destination)) 1982 2035 else: 1983 command = "mythtranscode --mpeg2 -c %s -s %s -o %s" % (chanid, starttime, destination)2036 command = "mythtranscode --mpeg2 -c %s -s %s -o %s" % (chanid, starttime, quoteCmdArg(destination)) 1984 2037 1985 2038 result = runCommand(command) 1986 2039 … … 1998 2051 def generateProjectXCutlist(chanid, starttime, folder): 1999 2052 """generate cutlist_x.txt for ProjectX""" 2000 2053 2001 sqlstatement = """SELECT mark FROM recordedmarkup 2002 WHERE chanid = '%s' AND starttime = '%s' 2054 sqlstatement = """SELECT mark FROM recordedmarkup 2055 WHERE chanid = '%s' AND starttime = '%s' 2003 2056 AND type IN (0,1) ORDER BY mark""" % (chanid, starttime) 2004 2057 2005 2058 db = getDatabaseConnection() … … 2014 2067 db.close() 2015 2068 del db 2016 2069 del cursor 2017 return False 2070 return False 2071 2072 sqlstatement = """SELECT mark FROM recordedmarkup 2073 WHERE chanid = '%s' AND starttime = '%s' 2074 AND type=1 ORDER BY mark LIMIT 1 """ % (chanid, starttime) 2075 2076 cursor.execute(sqlstatement) 2077 firstcut = cursor.fetchall() 2078 2079 sqlstatement = """SELECT mark FROM recordedmarkup 2080 WHERE chanid = '%s' AND starttime = '%s' 2081 AND type IN (0,1) ORDER BY mark LIMIT 1 """ % (chanid, starttime) 2018 2082 2083 cursor.execute(sqlstatement) 2084 firstedit = cursor.fetchall() 2085 2019 2086 cutlist_f=open(os.path.join(folder, "cutlist_x.txt"), 'w') 2020 2087 cutlist_f.write("CollectionPanel.CutMode=2\n") 2021 2088 2089 if firstcut == firstedit: 2090 cutlist_f.write("0\n") 2091 2022 2092 # iterate through resultset 2023 2093 for i in range(len(result)): 2024 if i == 0:2025 if result[i][0] <> 0 and result[i][0] != "":2026 cutlist_f.write("0\n")2027 2094 if result[i][0] != "" and result[i][0] <> 0: 2028 2095 cutlist_f.write("%d\n" % result[i]) 2029 2096 … … 2043 2110 write("Failed to generate Project-X cutlist.") 2044 2111 return False 2045 2112 2046 pxbasename = os.path.splitext(os.path.basename(file))[0]2047 2048 2113 if os.path.exists(file) != True: 2049 2114 write("Error: input file doesn't exist on local filesystem") 2050 2115 return False 2051 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) 2116 2117 command = "ionice -c3 java -jar " 2118 command += quoteCmdArg(path_projectx[0]) + " %s -id '%s' -set ExternPanel.appendPidToFileName=1 -out %s -name stream" % (quoteCmdArg(file), getStreamList(folder), quoteCmdArg(folder)) 2059 2119 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 2120 command += " -cut %s" % quoteCmdArg(os.path.join(folder, "cutlist_x.txt")) 2064 2121 write(command) 2065 2122 2066 2123 result = runCommand(command) … … 2072 2129 2073 2130 2074 2131 # workout which files we need and rename them 2075 renameProjectXFiles(folder, pxbasename) 2132 video, audio1, audio2 = selectStreams(folder) 2133 if addSubtitles: 2134 subtitles = selectSubtitleStream(folder) 2135 2136 videoID_hex = "0x%x" % video[VIDEO_ID] 2137 if audio1[AUDIO_ID] != -1: 2138 audio1ID_hex = "0x%x" % audio1[AUDIO_ID] 2139 else: 2140 audio1ID_hex = "" 2141 if audio2[AUDIO_ID] != -1: 2142 audio2ID_hex = "0x%x" % audio2[AUDIO_ID] 2143 else: 2144 audio2ID_hex = "" 2145 if addSubtitles and subtitles[SUBTITLE_ID] != -1: 2146 subtitlesID_hex = "0x%x" % subtitles[SUBTITLE_ID] 2147 else: 2148 subtitlesID_hex = "" 2149 2150 2151 files = os.listdir(folder) 2152 for file in files: 2153 if file[0:9] == "stream{0x": # don't rename files that have already been renamed 2154 PID = file[7:13] 2155 SubID = file[19:23] 2156 if PID == videoID_hex or SubID == videoID_hex: 2157 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.mv2")) 2158 elif PID == audio1ID_hex or SubID == audio1ID_hex: 2159 os.rename(os.path.join(folder, file), os.path.join(folder, "stream0." + file[-3:])) 2160 elif PID == audio2ID_hex or SubID == audio2ID_hex: 2161 os.rename(os.path.join(folder, file), os.path.join(folder, "stream1." + file[-3:])) 2162 elif PID == subtitlesID_hex or SubID == subtitlesID_hex: 2163 if file[-3:] == "sup": 2164 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup")) 2165 else: 2166 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup.IFO")) 2167 2168 2169 # Fallback if assignment and renaming by ID failed 2170 2171 files = os.listdir(folder) 2172 for file in files: 2173 if file[0:9] == "stream{0x": # don't rename files that have already been renamed 2174 if not os.path.exists(os.path.join(folder, "stream.mv2")) and file[-3:] == "m2v": 2175 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.mv2")) 2176 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": 2177 os.rename(os.path.join(folder, file), os.path.join(folder, "stream0.ac3")) 2178 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": 2179 os.rename(os.path.join(folder, file), os.path.join(folder, "stream0.mp2")) 2180 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": 2181 os.rename(os.path.join(folder, file), os.path.join(folder, "stream1.ac3")) 2182 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": 2183 os.rename(os.path.join(folder, file), os.path.join(folder, "stream1.mp2")) 2184 elif not os.path.exists(os.path.join(folder, "stream.sup")) and file[-3:] == "sup": 2185 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup")) 2186 elif not os.path.exists(os.path.join(folder, "stream.sup.IFO")) and file[-3:] == "IFO": 2187 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup.IFO")) 2188 2076 2189 2077 2190 # if we have some dvb subtitles and the user wants to add them to the DVD 2078 2191 # convert them to pngs and create the spumux xml file … … 2081 2194 os.path.exists(os.path.join(folder, "stream.sup.IFO"))): 2082 2195 write("Found DVB subtitles converting to DVD subtitles") 2083 2196 command = "mytharchivehelper --sup2dast " 2084 command += " %s %s 0" % ( os.path.join(folder, "stream.sup"), os.path.join(folder, "stream.sup.IFO"))2197 command += " %s %s 0" % (quoteCmdArg(os.path.join(folder, "stream.sup")), quoteCmdArg(os.path.join(folder, "stream.sup.IFO"))) 2085 2198 2086 2199 result = runCommand(command) 2087 2200 … … 2096 2209 return True 2097 2210 2098 2211 ############################################################# 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 2212 # convert time stamp to pts 2221 2213 2222 2214 def ts2pts(time): … … 2287 2279 else: 2288 2280 fr=framerateNTSC 2289 2281 2290 source = quoteFilename(source) 2291 2292 command = "mytharchivehelper -t %s '%s' %s" % (source, seconds, destination) 2282 command = "ionice -c3 " 2283 command += "mytharchivehelper -t %s '%s' %s" % (quoteCmdArg(source),seconds, quoteCmdArg(destination)) 2293 2284 result = runCommand(command) 2294 2285 if result <> 0: 2295 2286 fatalError("Failed while running mytharchivehelper to get thumbnails.\n" … … 2312 2303 write("Extracting thumbnail images from: %s - at %s" % (source, thumbList)) 2313 2304 write("Destination file %s" % destination) 2314 2305 2315 source = quoteFilename(source)2316 2306 2317 command = "mytharchivehelper -v important -t %s '%s' %s" % (source, thumbList, destination) 2307 command = "ionice -c3 " 2308 command += "mytharchivehelper -v important -t %s '%s' %s" % (quoteCmdArg(source), thumbList, quoteCmdArg(destination)) 2309 write(command) 2310 2318 2311 result = runCommand(command) 2319 2312 if result <> 0: 2320 fatalError("Failed while running mytharchivehelper to get thumbnails") 2313 fatalError("Failed while running mytharchivehelper to get thumbnails. \n" 2314 "Result: %d, Command was %s" % (result, command)) 2321 2315 2322 2316 ############################################################# 2323 2317 # Re-encodes a file to mpeg2 … … 2329 2323 2330 2324 passes = int(getText(profileNode.getElementsByTagName("passes")[0])) 2331 2325 2332 command = path_ffmpeg[0]2326 command = quoteCmdArg(path_ffmpeg[0]) 2333 2327 2334 2328 if cpuCount > 1: 2335 2329 command += " -threads %d" % cpuCount … … 2342 2336 2343 2337 # do some parameter substitution 2344 2338 if value == "%inputfile": 2345 value = quote Filename(source)2339 value = quoteCmdArg(source) 2346 2340 if value == "%outputfile": 2347 value = quote Filename(destvideofile)2341 value = quoteCmdArg(destvideofile) 2348 2342 if value == "%aspect": 2349 2343 value = aspectratio 2350 2344 … … 2398 2392 passLog = os.path.join(getTempPath(), 'pass') 2399 2393 2400 2394 pass1 = string.replace(command, "%passno","1") 2401 pass1 = string.replace(pass1, "%passlogfile", passLog)2395 pass1 = string.replace(pass1, "%passlogfile", quoteCmdArg(passLog)) 2402 2396 write("Pass 1 - " + pass1) 2403 2397 result = runCommand(pass1) 2404 2398 … … 2410 2404 os.remove(destvideofile) 2411 2405 2412 2406 pass2 = string.replace(command, "%passno","2") 2413 pass2 = string.replace(pass2, "%passlogfile", passLog)2407 pass2 = string.replace(pass2, "%passlogfile", quoteCmdArg(passLog)) 2414 2408 write("Pass 2 - " + pass2) 2415 2409 result = runCommand(pass2) 2416 2410 … … 2515 2509 samplerate, channels = getAudioParams(folder) 2516 2510 videores, fps, aspectratio = getVideoParams(folder) 2517 2511 2518 command = path_ffmpeg[0]+ " -y "2512 command = quoteCmdArg(path_ffmpeg[0]) + " -y " 2519 2513 2520 2514 if cpuCount > 1: 2521 2515 command += "-threads %d " % cpuCount 2522 2516 2523 command += "-f s16le -ar %s -ac %s -i %s " % (samplerate, channels, os.path.join(folder, "audout"))2517 command += "-f s16le -ar %s -ac %s -i %s " % (samplerate, channels, quoteCmdArg(os.path.join(folder, "audout"))) 2524 2518 command += "-f rawvideo -pix_fmt yuv420p -s %s -aspect %s -r %s " % (videores, aspectratio, fps) 2525 command += "-i %s " % os.path.join(folder, "vidout")2519 command += "-i %s " % quoteCmdArg(os.path.join(folder, "vidout")) 2526 2520 command += "-aspect %s -r %s " % (aspectratio, fps) 2527 2521 if (deinterlace == 1): 2528 2522 command += "-deinterlace " … … 2530 2524 command += "-s %s -b %s -vcodec mpeg2video " % (outvideores, outvideobitrate) 2531 2525 command += "-qmin %s -qmax %s -qdiff %s " % (qmin, qmax, qdiff) 2532 2526 command += "-ab %s -ar %s -acodec %s " % (outaudiobitrate, outaudiosamplerate, outaudiocodec) 2533 command += "-f dvd %s" % quote Filename(destvideofile)2527 command += "-f dvd %s" % quoteCmdArg(destvideofile) 2534 2528 2535 2529 #wait for mythtranscode to create the fifos 2536 2530 tries = 30 … … 2555 2549 2556 2550 def runDVDAuthor(): 2557 2551 write( "Starting dvdauthor") 2558 checkCancelFlag() 2559 result=os.spawnlp(os.P_WAIT, path_dvdauthor[0],path_dvdauthor[1],'-x',os.path.join(getTempPath(),'dvdauthor.xml')) 2552 # checkCancelFlag() 2553 # result=os.spawnlp(os.P_WAIT, path_dvdauthor[0],path_dvdauthor[1],'-x',os.path.join(getTempPath(),'dvdauthor.xml')) 2554 command ="ionice -c3 " 2555 command += path_dvdauthor[0] + ' -x ' + os.path.join(getTempPath(),'dvdauthor.xml') 2556 2557 write("Command is %s " % command) 2558 result = runCommand(command) 2559 2560 2560 if result<>0: 2561 2561 nonfatalError("Failed while running dvdauthor. Result: %d" % result) 2562 2562 write( "Finished dvdauthor") 2563 2563 2564 2564 2565 ############################################################# 2566 2565 2567 # Creates an ISO image from the contents of a directory 2566 2568 2567 2569 def CreateDVDISO(title): 2568 2570 write("Creating ISO image") 2569 2571 checkCancelFlag() 2570 command = path_mkisofs[0] + ' -dvd-video '2571 command += ' -V ' + quoteFilename(title)2572 command += ' -o ' + os.path.join(getTempPath(), 'mythburn.iso')2573 command += " " + os.path.join(getTempPath(),'dvd')2574 2572 2573 command = "ionice -c3 " 2574 command += quoteCmdArg(path_mkisofs[0]) + ' -dvd-video ' 2575 command += ' -V ' + quoteCmdArg(title) 2576 command += ' -o ' + quoteCmdArg(isopath) 2577 command += " " + quoteCmdArg(os.path.join(getTempPath(),'dvd')) 2578 2579 write("Command is %s " % command) 2575 2580 result = runCommand(command) 2576 2581 2577 2582 if result<>0: 2578 2583 fatalError("Failed while running mkisofs.\n" 2579 2584 "Command was %s" % command) 2580 2585 2581 write("Finished creating ISO image") 2586 # vobsize = os.path.getsize(path.join(getTempPath(), 'mythburn.iso')) 2587 vobsize= os.path.getsize(isopath) 2588 write("Finished creating mythburn.iso, size %.2f Mb." % (float(vobsize)/(1024.0*1024.0)) ) 2589 write("DVD capacities are %s, %s Mb " % ( dvdrsize[0], dvdrsize[1]) ) 2582 2590 2591 2583 2592 ############################################################# 2584 2593 # Burns the contents of a directory to create a DVD 2585 2594 2586 2595 def BurnDVDISO(title): 2587 2596 write( "Burning ISO image to %s" % dvddrivepath) 2588 checkCancelFlag()2589 2597 2590 2598 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); 2599 while not finished: 2600 # Maybe the user has no appropriate medium or something alike. Give her the chance to cancel. 2601 checkCancelFlag() 2602 2603 def drivestatus(): 2604 f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK) 2605 return ioctl(f,CDROM.CDROM_DRIVE_STATUS, 0) 2606 os.close(f); 2607 2608 # I drive needs some time (for example to close the tray) give it to it 2609 tries = 0 2610 while drivestatus() == CDROM.CDS_DRIVE_NOT_READY and tries < 6: 2611 time.sleep(5) 2612 tries += 1 2596 2613 2597 if drivestatus == CDROM.CDS_DISC_OK or drivestatus== CDROM.CDS_NO_INFO:2614 if drivestatus() == CDROM.CDS_DISC_OK or drivestatus() == CDROM.CDS_NO_INFO: 2598 2615 2599 2616 # If the frontend has a previously burnt DVD+RW mounted, 2600 2617 # growisofs will fail to burn it, so try to pumount it first... 2601 runCommand("pumount " + dvddrivepath);2618 runCommand("pumount " + quoteCmdArg(dvddrivepath)); 2602 2619 2603 2620 if mediatype == DVD_RW and erasedvdrw == True: 2604 2621 command = path_growisofs[0] + " -dvd-compat " … … 2618 2635 write("Running growisofs to burn DVD") 2619 2636 2620 2637 result = runCommand(command) 2621 if result != 0: 2638 if result == 0: 2639 finished = True 2640 elif result == 252: 2641 write("-"*60) 2642 write("You probably inserted a medium of wrong type.") 2643 if mediatype == DVD_SL: 2644 write("Please insert an empty single-layer disc (DVD+R or DVD-R).") 2645 if mediatype == DVD_DL: 2646 write("Please insert an empty double-layer disc (DVD+R DL or DVD-R DL).") 2647 if mediatype == DVD_RW: 2648 write("Please insert a rewritable disc (DVD+RW or DVD-RW).") 2649 else: 2622 2650 write("-"*60) 2623 2651 write("ERROR: Failed while running growisofs.") 2624 2652 write("Result %d, Command was: %s" % (result, command)) 2625 2653 write("Please check the troubleshooting section of the README for ways to fix this error") 2626 2654 write("-"*60) 2627 2655 write("") 2628 sys.exit(1) 2629 finished = True 2656 write("Going to try it again until canceled by user:") 2657 write("-"*60) 2658 write("") 2630 2659 2631 2660 try: 2632 2661 # eject the burned disc 2662 runCommand("pumount " + quoteCmdArg(dvddrivepath)); 2633 2663 f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK) 2634 2664 r = ioctl(f,CDROM.CDROMEJECT, 0) 2635 2665 os.close(f) … … 2637 2667 write("Failed to eject the disc! " 2638 2668 "Maybe the media monitor has mounted it") 2639 2669 2640 elif drivestatus == CDROM.CDS_TRAY_OPEN: 2641 # Give the user 10secs to close the Tray 2670 elif drivestatus() == CDROM.CDS_TRAY_OPEN: 2642 2671 write("Waiting for tray to close.") 2643 time.sleep(10) 2644 elif drivestatus == CDROM.CDS_NO_DISC: 2672 # Wait until user closes tray or cancels 2673 while drivestatus() == CDROM.CDS_TRAY_OPEN: 2674 checkCancelFlag() 2675 time.sleep(5) 2676 elif drivestatus() == CDROM.CDS_NO_DISC: 2645 2677 # Open the Tray, if there is one. 2646 2678 write("Opening tray to get it fed with a DVD.") 2647 2679 f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK) 2648 2680 ioctl(f,CDROM.CDROMEJECT, 0) 2649 2681 os.close(f); 2650 elif drivestatus == CDROM.CDS_DRIVE_NOT_READY:2651 # Try a hard reset 2682 elif drivestatus() == CDROM.CDS_DRIVE_NOT_READY: 2683 # Try a hard reset if the device is still not ready 2652 2684 write("Trying a hard-reset of the device") 2653 2685 f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK) 2654 2686 ioctl(f,CDROM.CDROMEJECT, 0) 2655 2687 os.close(f); 2656 2688 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 2689 2663 2690 write("Finished burning ISO image") 2664 2691 … … 2669 2696 def deMultiplexMPEG2File(folder, mediafile, video, audio1, audio2): 2670 2697 2671 2698 if getFileType(folder) == "mpegts": 2672 command = "mythreplex --demux --fix_sync -t TS -o %s " % (folder + "/stream")2699 command = "mythreplex --demux --fix_sync -t TS -o %s " % quoteCmdArg(folder + "/stream") 2673 2700 command += "-v %d " % (video[VIDEO_ID]) 2674 2701 2675 2702 if audio1[AUDIO_ID] != -1: … … 2689 2716 command += "-c %d " % (audio2[AUDIO_ID]) 2690 2717 2691 2718 else: 2692 command = "mythreplex --demux --fix_sync -o %s " % (folder + "/stream")2719 command = "mythreplex --demux --fix_sync -o %s " % quoteCmdArg(folder + "/stream") 2693 2720 command += "-v %d " % (video[VIDEO_ID] & 255) 2694 2721 2695 2722 if audio1[AUDIO_ID] != -1: … … 2709 2736 elif audio2[AUDIO_CODEC] == 'EAC3': 2710 2737 command += "-c %d " % (audio2[AUDIO_ID] & 255) 2711 2738 2712 mediafile = quote Filename(mediafile)2739 mediafile = quoteCmdArg(mediafile) 2713 2740 command += mediafile 2714 2741 write("Running: " + command) 2715 2742 … … 2726 2753 M2Vsize0 = os.path.getsize(source) 2727 2754 write("Initial M2Vsize is %.2f Mb , target is %.2f Mb" % ( (float(M2Vsize0)/mega), (float(M2Vsize0)/(factor*mega)) )) 2728 2755 2729 command = path_M2VRequantiser[0]2756 command = quoteCmdArg(path_M2VRequantiser[0]) 2730 2757 command += " %.5f " % factor 2731 2758 command += " %s " % M2Vsize0 2732 command += " < %s " % source2733 command += " > %s " % destination2759 command += " < %s " % quoteCmdArg(source) 2760 command += " > %s " % quoteCmdArg(destination) 2734 2761 2735 2762 write("Running: " + command) 2736 2763 result = runCommand(command) 2764 if result<>0: 2765 fatalError("Failed while running M2VRequantiser. Command was %s" % command) 2737 2766 2738 2767 M2Vsize1 = os.path.getsize(destination) 2739 2768 2740 2769 write("M2Vsize after requant is %.2f Mb " % (float(M2Vsize1)/mega)) 2741 2770 fac1=float(M2Vsize0) / float(M2Vsize1) 2742 2771 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) 2772 2746 2773 2747 2774 ############################################################# 2748 2775 # Calculates the total size of all the video, audio and menu files … … 2833 2860 fatalError("Audio and menu files are too big. No room for video. Giving up!") 2834 2861 2835 2862 if totalvideosize>mv2space: 2836 write( " Video files are %.1f Mb too big. Need to shrink." % ((totalvideosize - mv2space)/mega) )2863 write( "***** Video files are %.1f Mb too big. Need to shrink." % ((totalvideosize - mv2space)/mega) ) 2837 2864 2838 2865 if path_M2VRequantiser[0] == "": 2839 2866 fatalError("M2VRequantiser is not available to resize the files. Giving up!") … … 2884 2911 progvsize=os.path.getsize(file) 2885 2912 progduration=getLengthOfVideo(filecount) 2886 2913 progvbitrate=progvsize/progduration 2887 write( " File %s, size %.2f Mb, rate %.2f, limit %.2f kb/s " %( filecount, float(progvsize)/mega, progvbitrate/1000.0, vrate/1000.0 ))2914 write( "*** File %s, size %.2f Mb, rate %.2f, limit %.2f kb/s " %( filecount, float(progvsize)/mega, progvbitrate/1000.0, vrate/1000.0 )) 2888 2915 if progvbitrate>vrate : 2889 2916 scalefactor=1.0+(fudge_requant*float(progvbitrate-vrate)/float(vrate)) 2890 2917 if scalefactor>3.0 : … … 2893 2920 os.remove(os.path.join(getItemTempPath(filecount),"stream.mv2")) 2894 2921 os.rename(os.path.join(getItemTempPath(filecount),"stream.small.mv2"),os.path.join(getItemTempPath(filecount),"stream.mv2")) 2895 2922 else: 2896 write( " Unpackaged total %.2f Mb. About %.0f Mb will be unused." % ((allfiles/mega),(mv2space-totalvideosize)/mega))2923 write( "*** No need to shrink. *** Unpackaged total %.2f Mb. About %.0f Mb will be unused." % ((allfiles/mega),(mv2space-totalvideosize)/mega)) 2897 2924 2898 2925 ############################################################# 2899 2926 # Creates the DVDAuthor xml file used to create a standard DVD with menus … … 3501 3528 height = getScaledAttribute(node, "h") 3502 3529 frames = int(secondsToFrames(menulength)) 3503 3530 3504 command = "mytharchivehelper -t %s '%s' '%s' %d" % (inputfile, starttime, outputfile, frames)3531 command = "mytharchivehelper -t %s '%s' '%s' %d" % (quoteCmdArg(inputfile), starttime, quoteCmdArg(outputfile), frames) 3505 3532 result = runCommand(command) 3506 3533 if (result != 0): 3507 3534 write( "mytharchivehelper failed with code %d. Command = %s" % (result, command) ) … … 3613 3640 button = spumuxdom.createElement("button") 3614 3641 button.setAttribute("name","previous") 3615 3642 button.setAttribute("x0","%s" % getScaledAttribute(node, "x")) 3616 button.setAttribute("y0","%s" % getScaledAttribute(node, "y"))3643 button.setAttribute("y0","%s" % even(getScaledAttribute(node, "y"))) 3617 3644 button.setAttribute("x1","%s" % (getScaledAttribute(node, "x") + 3618 3645 getScaledAttribute(node, "w"))) 3619 button.setAttribute("y1","%s" % (getScaledAttribute(node, "y") +3646 button.setAttribute("y1","%s" % even(getScaledAttribute(node, "y") + 3620 3647 getScaledAttribute(node, "h"))) 3621 3648 spunode.appendChild(button) 3622 3649 … … 3637 3664 button = spumuxdom.createElement("button") 3638 3665 button.setAttribute("name","next") 3639 3666 button.setAttribute("x0","%s" % getScaledAttribute(node, "x")) 3640 button.setAttribute("y0","%s" % getScaledAttribute(node, "y"))3667 button.setAttribute("y0","%s" % even(getScaledAttribute(node, "y"))) 3641 3668 button.setAttribute("x1","%s" % (getScaledAttribute(node, "x") + 3642 3669 getScaledAttribute(node, "w"))) 3643 button.setAttribute("y1","%s" % (getScaledAttribute(node, "y") +3644 getScaledAttribute(node, "h"))) 3670 button.setAttribute("y1","%s" % even((getScaledAttribute(node, "y") + 3671 getScaledAttribute(node, "h")))) 3645 3672 spunode.appendChild(button) 3646 3673 3647 3674 write("Added next page button") … … 3658 3685 button = spumuxdom.createElement("button") 3659 3686 button.setAttribute("name","playall") 3660 3687 button.setAttribute("x0","%s" % getScaledAttribute(node, "x")) 3661 button.setAttribute("y0","%s" % getScaledAttribute(node, "y"))3688 button.setAttribute("y0","%s" % even(getScaledAttribute(node, "y"))) 3662 3689 button.setAttribute("x1","%s" % (getScaledAttribute(node, "x") + 3663 3690 getScaledAttribute(node, "w"))) 3664 button.setAttribute("y1","%s" % (getScaledAttribute(node, "y") +3665 getScaledAttribute(node, "h"))) 3691 button.setAttribute("y1","%s" % even((getScaledAttribute(node, "y") + 3692 getScaledAttribute(node, "h")))) 3666 3693 spunode.appendChild(button) 3667 3694 3668 3695 write("Added playall button") … … 3681 3708 button = spumuxdom.createElement("button") 3682 3709 button.setAttribute("name","titlemenu") 3683 3710 button.setAttribute("x0","%s" % getScaledAttribute(node, "x")) 3684 button.setAttribute("y0","%s" % getScaledAttribute(node, "y"))3711 button.setAttribute("y0","%s" % even(getScaledAttribute(node, "y"))) 3685 3712 button.setAttribute("x1","%s" % (getScaledAttribute(node, "x") + 3686 3713 getScaledAttribute(node, "w"))) 3687 button.setAttribute("y1","%s" % (getScaledAttribute(node, "y") +3688 getScaledAttribute(node, "h"))) 3714 button.setAttribute("y1","%s" % even((getScaledAttribute(node, "y") + 3715 getScaledAttribute(node, "h")))) 3689 3716 spunode.appendChild(button) 3690 3717 3691 3718 write( "Added titlemenu button") … … 3730 3757 else: 3731 3758 node.setAttribute("name","%s" % itemnum) 3732 3759 node.setAttribute("x0","%d" % int(boundarybox[0])) 3733 node.setAttribute("y0","%d" % int(boundarybox[1]))3760 node.setAttribute("y0","%d" % even(boundarybox[1])) 3734 3761 node.setAttribute("x1","%d" % int(boundarybox[2] + 1)) 3735 node.setAttribute("y1","%d" % int(boundarybox[3] + 1))3762 node.setAttribute("y1","%d" % even(boundarybox[3] + 1)) 3736 3763 spunode.appendChild(node) 3737 3764 3738 3765 ############################################################# … … 3768 3795 highlightcolor = menunode.attributes["highlightcolor"].value 3769 3796 3770 3797 #Get menu music 3771 menumusic = "menumusic.ac3" 3772 if menunode.hasAttribute("music"): 3773 menumusic = menunode.attributes["music"].value 3798 menumusic = "menumusic.mp2" 3799 # menumusic = "menumusic.ac3" 3800 # if menunode.hasAttribute("music"): 3801 # menumusic = menunode.attributes["music"].value 3774 3802 3775 3803 #Get menu length 3776 3804 menulength = 15 … … 3979 4007 if menunode.hasAttribute("highlightcolor"): 3980 4008 highlightcolor = menunode.attributes["highlightcolor"].value 3981 4009 4010 3982 4011 #Get menu music 3983 menumusic = "menumusic.ac3" 3984 if menunode.hasAttribute("music"): 3985 menumusic = menunode.attributes["music"].value 4012 menumusic = "menumusic.mp2" 4013 # menumusic = "menumusic.ac3" 4014 # if menunode.hasAttribute("music"): 4015 # menumusic = menunode.attributes["music"].value 3986 4016 3987 4017 #Get menu length 3988 4018 menulength = 15 … … 4175 4205 fatalError("Background image not found (%s)" % backgroundfilename) 4176 4206 4177 4207 #Get menu music 4178 menumusic = "menumusic.ac3" 4179 if detailnode.hasAttribute("music"): 4180 menumusic = detailnode.attributes["music"].value 4208 menumusic = "menumusic.mp2" 4209 # menumusic = "menumusic.ac3" 4210 # if detailnode.hasAttribute("music"): 4211 # menumusic = detailnode.attributes["music"].value 4181 4212 4182 4213 #Get menu length 4183 4214 menulength = 15 … … 4367 4398 # 2. if there is one or more stream(s) using the 2nd preferred language we use that 4368 4399 # 3. if we still haven't found a stream we use the stream with the lowest PID 4369 4400 # 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 PID4401 # 5. if there are more than one stream with the chosen language we use the one with the lowest PID 4371 4402 4372 4403 write("Preferred audio languages %s and %s" % (preferredlang1, preferredlang2)) 4373 4404 … … 4511 4542 4512 4543 found = False 4513 4544 # first try to find a stream with preferred language 1 4545 # inc Pontoppidan patch dvbsub > DVBSUB 4514 4546 for node in nodes: 4515 4547 index = int(node.attributes["ffmpegindex"].value) 4516 4548 lang = node.attributes["language"].value 4517 4549 format = string.upper(node.attributes["codec"].value) 4518 4550 pid = int(node.attributes["id"].value) 4519 if not found and lang == preferredlang1 and format == " dvbsub":4551 if not found and lang == preferredlang1 and format == "DVBSUB": 4520 4552 subtitle = (index, format, pid, lang) 4521 4553 found = True 4522 4554 … … 4527 4559 lang = node.attributes["language"].value 4528 4560 format = string.upper(node.attributes["codec"].value) 4529 4561 pid = int(node.attributes["id"].value) 4530 if not found and lang == preferredlang2 and format == " dvbsub":4562 if not found and lang == preferredlang2 and format == "DVBSUB": 4531 4563 subtitle = (index, format, pid, lang) 4532 4564 found = True 4533 4565 … … 4707 4739 def doProcessFile(file, folder, count): 4708 4740 """Process a single video/recording file ready for burning.""" 4709 4741 4710 write( "*************************************************************")4742 # write( "*************************************************************") 4711 4743 write( "Processing %s %d: '%s'" % (file.attributes["type"].value, count, file.attributes["filename"].value)) 4712 write( "*************************************************************")4744 # write( "*************************************************************") 4713 4745 4714 4746 #As part of this routine we need to pre-process the video this MAY mean: 4715 4747 #1. removing commercials/cleaning up mpeg2 stream … … 4907 4939 else: 4908 4940 extractVideoFrame(os.path.join(folder, "stream.mv2"), titleImage, thumboffset) 4909 4941 4910 write( "*************************************************************")4911 write( " Finished processing '%s'" % file.attributes["filename"].value)4912 write( "*************************************************************")4942 # write( "*************************************************************") 4943 write( "*** Finished processing '%s'" % file.attributes["filename"].value) 4944 # write( "*************************************************************") 4913 4945 4914 4946 4915 4947 ############################################################# … … 4921 4953 4922 4954 write( "*************************************************************") 4923 4955 write( "Processing %s %d: '%s'" % (file.attributes["type"].value, count, file.attributes["filename"].value)) 4924 write( "*************************************************************")4956 # write( "*************************************************************") 4925 4957 4926 4958 #As part of this routine we need to pre-process the video this MAY mean: 4927 4959 #1. encoding to mpeg2 (if its an avi for instance or isn't DVD compatible) … … 5076 5108 else: 5077 5109 extractVideoFrame(os.path.join(folder, "stream.mv2"), titleImage, thumboffset) 5078 5110 5079 write( "*************************************************************")5080 write( " Finished processing file '%s'" % file.attributes["filename"].value)5081 write( "*************************************************************")5111 # write( "*************************************************************") 5112 write( "*** Finished processing file '%s'" % file.attributes["filename"].value) 5113 # write( "*************************************************************") 5082 5114 5083 5115 ############################################################# 5084 5116 # copy files on remote filesystems to the local filesystem … … 5091 5123 tmpfile = node.attributes["filename"].value 5092 5124 filename = os.path.basename(tmpfile) 5093 5125 5094 res = runCommand("mytharchivehelper -r " + quoteFilename(tmpfile)) 5126 res = runCommand("mytharchivehelper -r " + quoteCmdArg(tmpfile)) 5127 5095 5128 if res == 2: 5096 5129 # file is on a remote filesystem so copy it to a local file 5097 5130 write("Copying file from " + tmpfile) … … 5156 5189 5157 5190 write( "Final DVD Video format will be " + videomode) 5158 5191 5159 #Ensure the destination dvd folder is empty5160 if doesFileExist(os.path.join(getTempPath(),"dvd")):5161 deleteAllFilesInFolder(os.path.join(getTempPath(),"dvd"))5162 5192 5163 5193 #Loop through all the files 5164 5194 files=media[0].getElementsByTagName("file") … … 5168 5198 5169 5199 if debug_secondrunthrough==False: 5170 5200 #Delete all the temporary files that currently exist 5171 delete AllFilesInFolder(getTempPath())5201 deleteEverythingInFolder(getTempPath()) 5172 5202 5173 5203 #If User wants to, copy remote files to a tmp dir 5174 5204 if copyremoteFiles==True: 5175 5205 if debug_secondrunthrough==False: 5176 5206 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 5207 os.makedirs(localCopyFolder) 5184 5208 files=copyRemote(files,getTempPath()) 5185 5209 … … 5193 5217 folder=getItemTempPath(filecount) 5194 5218 5195 5219 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 5220 os.makedirs(folder) 5211 5221 #Do the pre-process work 5212 5222 preProcessFile(node,folder,filecount) … … 5518 5528 saveSetting("MythArchiveLastRunStatus", "Success") 5519 5529 saveSetting("MythArchiveLastRunEnd", time.strftime("%Y-%m-%d %H:%M:%S ")) 5520 5530 write("Finished processing jobs!!!") 5531 # Show bigger end marker. Display and editor font widths differ. 5532 write(" ") 5533 write(" OO K K") 5534 write(" O O K K") 5535 write(" O O K K") 5536 write(" O O K K") 5537 write(" OO K K") 5538 write(" ") 5521 5539 finally: 5522 5540 # remove our lock file 5523 5541 os.remove(lckpath)