Ticket #10071: mythburn_fixes_1.3.2012_for_git_1.3.2012_new.path

File mythburn_fixes_1.3.2012_for_git_1.3.2012_new.path, 30.1 KB (added by t.brackertz@…, 8 years ago)

All fixes mentioned before except the ones concerning audio-formats - error in last file, disregard it

Line 
11a2
2> # -*- coding: utf-8 -*-
333c34
4< # ProjectX - 0.90.4.00
5---
6> # ProjectX - >=0.91
738a40,45
8>
9> # All strings in this file should be unicode, not byte string!! They get converted to utf-8 only
10>
11>
12>
13>
14258a266,267
15>
16>     text = text.encode("utf-8", "replace")
17272a282
18>     write("See mythburn.log for more information.")
19307c317
20<     """return the number of CPU's"""
21---
22>     """return the number of CPUs"""
23341c351
24< # Escape quotes in a filename
25---
26> # Escape quotes in a command line argument
27343,346c353,356
28< def quoteFilename(filename):
29<     filename = filename.replace('"', '\\"')
30<     filename = filename.replace('`', '\\`')
31<     return '"%s"' % filename
32---
33> def quoteCmdArg(arg):
34>     arg = arg.replace('"', '\\"')
35>     arg = arg.replace('`', '\\`')
36>     return '"%s"' % arg
37417a428,440
38> # Romoves all the objects from a directory
39>
40> def deleteEverythingInFolder(folder):
41>     for root, dirs, files in os.walk(folder, topdown=False):
42>         for name in files:
43>                 os.remove(os.path.join(root, name))
44>         for name in dirs:
45>                 if os.path.islink(os.path.join(root, name)):
46>                     os.remove(os.path.join(root, name))
47>                 else:
48>                     os.rmdir(os.path.join(root, name))
49>
50> #############################################################
51436c459,466
52<     result = os.system(command)
53---
54>     # mytharchivehelper needes this locale to work correctly
55>     try:
56>        oldlocale = os.environ["LC_ALL"]
57>     except:
58>        oldlocale = ""
59>     os.putenv("LC_ALL", "en_US.UTF-8")
60>     result = os.system(command.encode('utf-8'))
61>     os.putenv("LC_ALL", oldlocale)
62467,468c497,498
63<     command = path_jpeg2yuv[0] + " -n %s -v0 -I p -f %s -j '%s' | %s -b 5000 -a %s -v 1 -f 8 -o '%s'" \
64<               % (totalframes, framespersecond, background, path_mpeg2enc[0], aspectratio, tempvideo)
65---
66>     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" \
67>               % (totalframes, framespersecond, quoteCmdArg(background), quoteCmdArg(path_mpeg2enc[0]), aspectratio, quoteCmdArg(tempvideo))
68473c503
69<     command = path_mplex[0] + " -f 8 -v 0 -o '%s' '%s' '%s'" % (tempmovie, tempvideo, music)
70---
71>     command = quoteCmdArg(path_mplex[0]) + " -f 8 -v 0 -o %s %s %s" % (quoteCmdArg(tempmovie), quoteCmdArg(tempvideo), quoteCmdArg(music))
72479c509
73<         command = path_spumux[0] + " -m dvd -s 0 '%s' < '%s' > '%s'" % (xmlfile, tempmovie, finaloutput)
74---
75>         command = quoteCmdArg(path_spumux[0]) + " -m dvd -s 0 %s < %s > %s" % (quoteCmdArg(xmlfile), quoteCmdArg(tempmovie), quoteCmdArg(finaloutput))
761434c1464
77<         print "Node = %s, Data = %s" % (k, v)
78---
79>         write( "Node = %s, Data = %s" % (k, v))
801436c1466,1472
81<         node.appendChild(infoDOM.createTextNode(str(v)))
82---
83>         # v may be either an integer. Therefore we have to
84>         # convert it to an unicode-string
85>         # If it is already a string it is not encoded as all
86>         # strings in this script are unicode. As no
87>         # encoding-argument is supplied to unicode() it does
88>         # nothing in this case.
89>         node.appendChild(infoDOM.createTextNode(unicode(v)))
901500c1536
91<         cmd += "-i '%s' -f ac3 -ab 192k -ar 48000 '%s'" % (sourcefile, destinationfile)
92---
93>         cmd += "-i %s -f ac3 -ab 192k -ar 48000 %s" % (quoteCmdArg(sourcefile), quoteCmdArg(destinationfile))
941594c1630
95<         command = os.path.join(scriptpath, "testsubtitlepngs.sh") + " %s/stream.d/spumux.xml" % (os.path.dirname(destination))
96---
97>         command = quoteCmdArg(os.path.join(scriptpath, "testsubtitlepngs.sh")) + " " + quoteCmdArg(os.path.dirname(destination) + "/stream.d/spumux.xml")
981600c1636
99<         command = path_spumux[0] + " -P %s/stream.d/spumux.xml <%s >%s" % (os.path.dirname(destination), destination, os.path.splitext(destination)[0] + "-sub.mpg")
100---
101>         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"))
1021618,1619c1654,1656
103<     filename = quoteFilename(filename)
104<     command = "mytharchivehelper -q -q --getfileinfo --infile %s --outfile %s --method %d" % (filename, xmlFilename, lenMethod)
105---
106>
107>     command = "mytharchivehelper -q -q --getfileinfo --infile %s --outfile %s --method %d" % (quoteCmdArg(filename), quoteCmdArg(xmlFilename), lenMethod)
108>
1091629c1666
110<     write("streaminfo.xml :-\n" + infoDOM.toprettyxml("    ", ""), False)
111---
112>     write(xmlFilename + ":-\n" + infoDOM.toprettyxml("    ", ""), False)
1131675c1712
114<             command = "mythtranscode --mpeg2 --honorcutlist %s --infile %s --outfile %s" % (cutlist_s, localfile, destination)
115---
116>             command = "mythtranscode --mpeg2 --honorcutlist %s --infile %s --outfile %s" % (cutlist_s, quoteCmdArg(localfile), quoteCmdArg(destination))
1171677c1714
118<             command = "mythtranscode --mpeg2 -i %s -o %s" % (localfile, destination)
119---
120>             command = "mythtranscode --mpeg2 --infile %s --outfile %s" % (quoteCmdArg(localfile), quoteCmdArg(destination))
1211680c1717
122<             command = "mythtranscode --mpeg2 --honorcutlist --chanid %s --starttime %s --outfile %s" % (chanid, starttime, destination)
123---
124>             command = "mythtranscode --mpeg2 --honorcutlist --chanid %s --starttime %s --outfile %s" % (chanid, starttime, quoteCmdArg(destination))
1251682c1719
126<             command = "mythtranscode --mpeg2 --chanid %s --starttime %s --outfile %s" % (chanid, starttime, destination)
127---
128>             command = "mythtranscode --mpeg2 --chanid %s --starttime %s --outfile %s" % (chanid, starttime, quoteCmdArg(destination))
1291739,1740d1775
130<     pxbasename = os.path.splitext(os.path.basename(file))[0]
131<
1321745,1751c1780
133<
134<     qdestdir = quoteFilename(folder)
135<     qpxbasename = quoteFilename(pxbasename)
136<     qfile = quoteFilename(file)
137<     qcutlist = os.path.join(folder, "cutlist_x.txt")
138<
139<     command = path_projectx[0] + " -id %s" % getStreamList(folder)
140---
141>     command = quoteCmdArg(path_projectx[0]) + " %s -id '%s' -set ExternPanel.appendPidToFileName=1 -out %s -name stream" % (quoteCmdArg(file), getStreamList(folder), quoteCmdArg(folder))
1421753,1756c1782
143<         command += " -cut %s -out %s -name %s %s" % (qcutlist, qdestdir, qpxbasename, qfile)
144<     else:
145<         command += " -out %s -name %s %s" % (qdestdir, qpxbasename, qfile)
146<
147---
148>         command += " -cut %s" % quoteCmdArg(os.path.join(folder, "cutlist_x.txt"))
1491758d1783
150<
1511768c1793,1849
152<     renameProjectXFiles(folder, pxbasename)
153---
154>     video, audio1, audio2 = selectStreams(folder)
155>     if addSubtitles:
156>         subtitles = selectSubtitleStream(folder)
157>
158>     videoID_hex = "0x%x" % video[VIDEO_ID]
159>     if audio1[AUDIO_ID] != -1:
160>         audio1ID_hex = "0x%x" % audio1[AUDIO_ID]
161>     else:
162>         audio1ID_hex = ""
163>     if audio2[AUDIO_ID] != -1:
164>         audio2ID_hex = "0x%x" % audio2[AUDIO_ID]
165>     else:
166>         audio2ID_hex = ""
167>     if addSubtitles and subtitles[SUBTITLE_ID] != -1:
168>         subtitlesID_hex = "0x%x" % subtitles[SUBTITLE_ID]
169>     else:
170>         subtitlesID_hex = ""
171>
172>
173>     files = os.listdir(folder)
174>     for file in files:
175>         if file[0:9] == "stream{0x": # don't rename files that have already been renamed
176>             PID = file[7:13]
177>             SubID = file[19:23]
178>             if PID == videoID_hex or SubID == videoID_hex:
179>                 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.mv2"))
180>             elif PID == audio1ID_hex or SubID == audio1ID_hex:
181>                 os.rename(os.path.join(folder, file), os.path.join(folder, "stream0." + file[-3:]))
182>             elif PID == audio2ID_hex or SubID == audio2ID_hex:
183>                 os.rename(os.path.join(folder, file), os.path.join(folder, "stream1." + file[-3:]))
184>             elif PID == subtitlesID_hex or SubID == subtitlesID_hex:
185>                 if file[-3:] == "sup":
186>                     os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup"))
187>                 else:
188>                     os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup.IFO"))
189>
190>
191>     # Fallback if assignment and renaming by ID failed
192>     
193>     files = os.listdir(folder)
194>     for file in files:
195>         if file[0:9] == "stream{0x": # don't rename files that have already been renamed
196>             if not os.path.exists(os.path.join(folder, "stream.mv2")) and file[-3:] == "m2v":
197>                 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.mv2"))
198>             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":
199>                 os.rename(os.path.join(folder, file), os.path.join(folder, "stream0.ac3"))
200>             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":
201>                 os.rename(os.path.join(folder, file), os.path.join(folder, "stream0.mp2"))
202>             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":
203>                 os.rename(os.path.join(folder, file), os.path.join(folder, "stream1.ac3"))
204>             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":
205>                 os.rename(os.path.join(folder, file), os.path.join(folder, "stream1.mp2"))
206>             elif not os.path.exists(os.path.join(folder, "stream.sup")) and file[-3:] == "sup":
207>                 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup"))
208>             elif not os.path.exists(os.path.join(folder, "stream.sup.IFO")) and file[-3:] == "IFO":
209>                 os.rename(os.path.join(folder, file), os.path.join(folder, "stream.sup.IFO"))
210>
2111777c1858
212<             command += " --infile %s --ifofile %s --delay 0" % (os.path.join(folder, "stream.sup"), os.path.join(folder, "stream.sup.IFO"))
213---
214>             command += " --infile %s --ifofile %s --delay 0" % (quoteCmdArg(os.path.join(folder, "stream.sup")), quoteCmdArg(os.path.join(folder, "stream.sup.IFO")))
2151792,1912d1872
216< # find the required stream files and rename them
217<
218< def renameProjectXFiles(folder, pxbasename):
219<
220<     write("renameProjectXFiles start -----------------------------------------", False)
221<     logf = open(os.path.join(folder, pxbasename + "_log.txt"))
222<     logdata = logf.readlines()
223<     logf.close()
224<
225<     # find stream PIDs and Files
226<     streamIds = []
227<     streamFiles = []   
228<     for line in logdata:
229<          tokens = line.split()
230<          if len(tokens) > 0:
231<             if tokens[0] == "++>":
232<               # From ProjectX/resources/pjxresources_en.properties:
233<               if tokens[1] == "Mpg":
234<                 if tokens[2] == "Video:":
235<                   write("found MPEG video stream %s" % tokens[4], False)
236<                   streamIds.append(int(tokens[4], 16))
237<                 if tokens[2] == "Audio:":
238<                   write("found MPEG audio stream %s" % tokens[4], False)
239<                   streamIds.append(int(tokens[4], 16))
240<               if tokens[1] == "AC3/DTS":
241<                 write("found AC3/DTS audio stream %s" % tokens[4], False)
242<                 streamIds.append(int(tokens[4], 16))             
243<               if tokens[1] == "LPCM":
244<                 write("found LPCM audio stream %s" % tokens[4], False)
245<                 streamIds.append(int(tokens[4], 16))             
246<               if tokens[1] == "Teletext:":
247<                 write("found Teletext stream %s" % tokens[3], False)
248<                 streamIds.append(int(tokens[3], 16))             
249<               if tokens[1] == "Subpicture:":
250<                 write("found Subpicture stream %s" % tokens[3], False)
251<                 streamIds.append(int(tokens[3], 16))
252<               if tokens[1] == "Generic_VBI:":
253<                 write("found Generic_VBI stream %s" % tokens[3], False)
254<                 streamIds.append(int(tokens[3], 16))                                           
255<             if tokens[0] == "--->":
256<               if tokens[1] == "new":
257<                 if tokens[2] == "File:":
258<                   write("found file for stream 0x%x, %s" % (streamIds[len(streamIds)-1], tokens[3]), False)
259<                   streamFiles.append(tokens[3].replace("'","")) # let's hope the path never has a space in it
260<             if tokens[0] == "-->":
261<               if tokens[1] == "stream":
262<                 if tokens[2] == "omitted":
263<                   write("stream 0x%x omitted" % streamIds[len(streamIds)-1], False)
264<                   streamFiles.append("")
265<                   
266<     write("streadmIds=%s" % streamIds)
267<     write("streamFiles=%s" % streamFiles)
268<
269<     # choose which streams we need
270<     video, audio1, audio2 = selectStreams(folder)
271<
272<     if getFileType(folder) == "mpeg":
273<         videoID  = video[VIDEO_ID] & 255
274<         audio1ID = audio1[AUDIO_ID] & 255
275<         audio2ID = audio2[AUDIO_ID] & 255
276<     else:
277<         videoID  = video[VIDEO_ID]
278<         audio1ID = audio1[AUDIO_ID]
279<         audio2ID = audio2[AUDIO_ID]
280<
281<     # sanity check - we should have a file for each ID
282<     if len(streamIds) == len(streamFiles):
283<         # loop thought the available streams looking for the ones we want
284<         for stream in streamIds:
285<             write("got stream: %d" % stream, False)
286<             if stream == videoID:
287<                 write("found video streamID", False)
288<                 if os.path.exists(streamFiles[streamIds.index(stream)]):
289<                     write("found video stream file", False)
290<                     os.rename(streamFiles[streamIds.index(stream)], os.path.join(folder, "stream.mv2"))
291<
292<             if stream == audio1ID:
293<                 write("found audio1 streamID", False)
294<                 if os.path.exists(streamFiles[streamIds.index(stream)]):
295<                     write("found audio1 stream file", False)
296<                     if audio1[AUDIO_CODEC] == "AC3":
297<                         os.rename(streamFiles[streamIds.index(stream)], os.path.join(folder, "stream0.ac3"))
298<                     else:
299<                         os.rename(streamFiles[streamIds.index(stream)], os.path.join(folder, "stream0.mp2"))
300<
301<             if stream == audio2ID:
302<                 write("found audio2 streamID", False)
303<                 if os.path.exists(streamFiles[streamIds.index(stream)]):
304<                     write("found audio2 stream file", False)
305<                     if audio2[AUDIO_CODEC] == "AC3":
306<                         os.rename(streamFiles[streamIds.index(stream)], os.path.join(folder, "stream1.ac3"))
307<                     else:
308<                         os.rename(streamFiles[streamIds.index(stream)], os.path.join(folder, "stream1.mp2"))
309<
310<     # final chance to find the correct stream files
311<     if not os.path.exists(os.path.join(folder, "stream.mv2")):
312<         if os.path.exists(os.path.join(folder, pxbasename + ".m2v")):
313<             os.rename(os.path.join(folder, pxbasename + ".m2v"), os.path.join(folder, "stream.mv2"))
314<
315<     if not os.path.exists(os.path.join(folder, "stream0.mp2")) or not os.path.exists(os.path.join(folder, "stream0.ac3")):
316<         if os.path.exists(os.path.join(folder, pxbasename + ".mp2")):
317<             os.rename(os.path.join(folder, pxbasename + ".mp2"), os.path.join(folder, "stream0.mp2"))
318<         if os.path.exists(os.path.join(folder, pxbasename + ".ac3")):
319<             os.rename(os.path.join(folder, pxbasename + ".ac3"), os.path.join(folder, "stream0.ac3"))
320<
321<     if not os.path.exists(os.path.join(folder, "stream1.mp2")) or not os.path.exists(os.path.join(folder, "stream1.ac3")):
322<         if os.path.exists(os.path.join(folder, pxbasename + "[1].mp2")):
323<             os.rename(os.path.join(folder, pxbasename + "[1].mp2"), os.path.join(folder, "stream1.mp2"))
324<         if os.path.exists(os.path.join(folder, pxbasename + "[1].ac3")):
325<             os.rename(os.path.join(folder, pxbasename + "[1].ac3"), os.path.join(folder, "stream1.ac3"))
326<
327<     # do we have any subtitle files
328<     if os.path.exists(os.path.join(folder, pxbasename + ".sup")):
329<         os.rename(os.path.join(folder, pxbasename + ".sup"), os.path.join(folder, "stream.sup"))
330<
331<     if os.path.exists(os.path.join(folder, pxbasename + ".sup.IFO")):
332<         os.rename(os.path.join(folder, pxbasename + ".sup.IFO"), os.path.join(folder, "stream.sup.IFO"))
333<
334<     write("renameProjectXFiles end -----------------------------------------", False)
335<
336< #############################################################
3371983,1985c1943
338<         source = quoteFilename(source)
339<
340<         command = "mytharchivehelper -q -q --createthumbnail --infile %s --thumblist '%s' --outfile %s" % (source, seconds, destination)
341---
342>         command = "mytharchivehelper -q -q --createthumbnail --infile %s --thumblist '%s' --outfile %s" % (quoteCmdArg(source), seconds, quoteCmdArg(destination))
3432008,2010c1966,1967
344<     source = quoteFilename(source)
345<
346<     command = "mytharchivehelper -q -q --createthumbnail --infile %s --thumblist '%s' --outfile %s" % (source, thumbList, destination)
347---
348>     command = "mytharchivehelper -q -q --createthumbnail --infile %s --thumblist '%s' --outfile %s" % (quoteCmdArg(source), thumbList, quoteCmdArg(destination))
349>     write(command)
3502039c1996
351<             value = quoteFilename(source)
352---
353>             value = quoteCmdArg(source)
3542041c1998
355<             value = quoteFilename(destvideofile)
356---
357>             value = quoteCmdArg(destvideofile)
3582095c2052
359<         pass1 = string.replace(pass1, "%passlogfile", passLog)
360---
361>         pass1 = string.replace(pass1, "%passlogfile", quoteCmdArg(passLog))
3622217c2174
363<     command += "-f s16le -ar %s -ac %s -i %s " % (samplerate, channels, os.path.join(folder, "audout"))
364---
365>     command += "-f s16le -ar %s -ac %s -i %s " % (samplerate, channels, quoteCmdArg(os.path.join(folder, "audout")))
3662219c2176
367<     command += "-i %s " % os.path.join(folder, "vidout")
368---
369>     command += "-i %s " % quoteCmdArg(os.path.join(folder, "vidout"))
3702227c2184
371<     command += "-f dvd %s" % quoteFilename(destvideofile)
372---
373>     command += "-f dvd %s" % quoteCmdArg(destvideofile)
3742264,2267c2221,2224
375<     command = path_mkisofs[0] + ' -dvd-video '
376<     command += ' -V ' + quoteFilename(title)
377<     command += ' -o ' + os.path.join(getTempPath(), 'mythburn.iso')
378<     command += " " + os.path.join(getTempPath(),'dvd')
379---
380>     command = quoteCmdArg(path_mkisofs[0]) + ' -dvd-video '
381>     command += ' -V ' + quoteCmdArg(title)
382>     command += ' -o ' + quoteCmdArg(os.path.join(getTempPath(), 'mythburn.iso'))
383>     command += " " + quoteCmdArg(os.path.join(getTempPath(),'dvd'))
3842282d2238
385<     checkCancelFlag()
3862284,2286c2240
387<     finished = False
388<     tries = 0
389<     while not finished and tries < 10:
390---
391>     def drivestatus():
3922288,2289c2242,2286
393<         drivestatus = ioctl(f,CDROM.CDROM_DRIVE_STATUS, 0)
394<         os.close(f);
395---
396>         status = ioctl(f,CDROM.CDROM_DRIVE_STATUS, 0)
397>         os.close(f)
398>         return status
399>     def displayneededdisktype():
400>         if mediatype == DVD_SL:
401>           write("Please insert an empty single-layer disc (DVD+R or DVD-R).")
402>         if mediatype == DVD_DL:
403>           write("Please insert an empty double-layer disc (DVD+R DL or DVD-R DL).")
404>         if mediatype == DVD_RW:
405>           write("Please insert a rewritable disc (DVD+RW or DVD-RW).")
406>     def opendrive(drivepath):
407>         # Open the Tray, if there is one.
408>         result = runCommand('eject ' + quoteCmdArg(drivepath))
409>         if result == 0:
410>             return True
411>         else:
412>             # try another method
413>             try:
414>                 f = os.open(drivepath, os.O_RDONLY | os.O_NONBLOCK)
415>                 r = ioctl(f,CDROM.CDROMEJECT, 0)
416>                 os.close(f)
417>                 return True
418>             except:
419>                 write("Failed to eject the disc!")
420>                 return False
421>     def waitForDrive():
422>         tries = 0
423>         while drivestatus() == CDROM.CDS_DRIVE_NOT_READY:
424>             write("Waiting for drive")
425>             time.sleep(5)
426>             tries += 1
427>             if tries > 6:
428>                 # Try a hard reset if the device is still not ready
429>                 write("Trying a hard-reset of the device")
430>                 f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK)
431>                 ioctl(f,CDROM.CDROMEJECT, 0)
432>                 os.close(f);
433>                 tries = 0
434>                 checkCancelFlag()
435>
436>
437>     finished = False
438>     while not finished:
439>         # Maybe the user has no appropriate medium or something alike. Give her the chance to cancel.
440>         checkCancelFlag()
4412291c2288,2291
442<         if drivestatus == CDROM.CDS_DISC_OK or drivestatus == CDROM.CDS_NO_INFO:
443---
444>         # If drive needs some time (for example to close the tray) give it to it
445>         waitForDrive()
446>
447>         if drivestatus() == CDROM.CDS_DISC_OK or drivestatus() == CDROM.CDS_NO_INFO:
4482295c2295
449<             runCommand("pumount " + dvddrivepath);
450---
451>             runCommand("pumount " + quoteCmdArg(dvddrivepath));
4522297,2309d2296
453<             if mediatype == DVD_RW and erasedvdrw == True:
454<                 command = path_growisofs[0] + " -dvd-compat "
455<                 if drivespeed != 0:
456<                     command += "-speed=%d " % drivespeed
457<                 command += " -use-the-force-luke -Z " + dvddrivepath
458<                 command += " -dvd-video -V '" + title.replace("'", "'\\''") + "' "
459<                 command += os.path.join(getTempPath(),'dvd')
460<             else:
461<                 command = path_growisofs[0] + " -dvd-compat "
462<                 if drivespeed != 0:
463<                     command += "-speed=%d " % drivespeed
464<                 command += " -Z " + dvddrivepath + " -dvd-video -V '" + title.replace("'", "'\\''") + "' "
465<                 command += os.path.join(getTempPath(),'dvd')
4662310a2298,2303
467>             command = quoteCmdArg(path_growisofs[0]) + " -dvd-compat"
468>             if drivespeed != 0:
469>                 command += " -speed=%d" % drivespeed
470>             if mediatype == DVD_RW and erasedvdrw == True:
471>                 command += " -use-the-force-luke"
472>             command += " -Z " + quoteCmdArg(dvddrivepath) + " -dvd-video -V " + quoteCmdArg(title) + " " + quoteCmdArg(os.path.join(getTempPath(),'dvd'))
4732315,2323c2308,2340
474<             if result != 0:
475<                 write("-"*60)
476<                 write("ERROR: Failed while running growisofs.")
477<                 write("Result %d, Command was: %s" % (result, command))
478<                 write("Please check the troubleshooting section of the README for ways to fix this error")
479<                 write("-"*60)
480<                 write("")
481<                 sys.exit(1)
482<             finished = True
483---
484>             if result == 0:
485>                 finished = True
486>             else:
487>                 if result == 252:
488>                     write("-"*60)
489>                     write("You probably inserted a medium of wrong type.")
490>                 elif (result == 156):
491>                     write("-"*60)
492>                     write("You probably inserted a non-empty, corrupt or too small medium.")
493>                 elif (result == 144):
494>                     write("-"*60)
495>                     write("You inserted a non-empty medium.")
496>                 else:
497>                     write("-"*60)
498>                     write("ERROR: Failed while running growisofs.")
499>                     write("Result %d, Command was: %s" % (result, command))
500>                     write("Please check mythburn.log for further information")
501>                     write("-"*60)
502>                     write("")
503>                     write("Going to try it again until canceled by user:")
504>                     write("-"*60)
505>                     write("")
506>                 displayneededdisktype()
507>
508>             # eject the disc
509>             waitForDrive()
510>             if os.path.ismount(dvddrivepath):
511>                 try:
512>                     runCommand("pumount " + quoteCmdArg(dvddrivepath));
513>                 except:
514>                     write("Failed to unmount the disc! "
515>                           "Maybe the media monitor has mounted it")
516>             opendrive(dvddrivepath)
5172325,2332d2341
518<             try:
519<                 # eject the burned disc
520<                 f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK)
521<                 r = ioctl(f,CDROM.CDROMEJECT, 0)
522<                 os.close(f)
523<             except:
524<                 write("Failed to eject the disc! "
525<                       "Maybe the media monitor has mounted it")
5262334,2335c2343,2344
527<         elif drivestatus == CDROM.CDS_TRAY_OPEN:
528<             # Give the user 10secs to close the Tray
529---
530>         elif drivestatus() == CDROM.CDS_TRAY_OPEN:
531>             displayneededdisktype()
5322337,2355c2346,2352
533<             time.sleep(10)
534<         elif drivestatus == CDROM.CDS_NO_DISC:
535<             # Open the Tray, if there is one.
536<             write("Opening tray to get it fed with a DVD.")
537<             f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK)
538<             ioctl(f,CDROM.CDROMEJECT, 0)
539<             os.close(f);
540<         elif drivestatus == CDROM.CDS_DRIVE_NOT_READY:
541<             # Try a hard reset
542<             write("Trying a hard-reset of the device")
543<             f = os.open(dvddrivepath, os.O_RDONLY | os.O_NONBLOCK)
544<             ioctl(f,CDROM.CDROMEJECT, 0)
545<             os.close(f);
546<
547<         time.sleep(1)
548<         tries += 1
549<
550<     if not finished:
551<         fatalError("Tried 10 times to get a good status from DVD drive - Giving up!")
552---
553>             # Wait until user closes tray or cancels
554>             while drivestatus() == CDROM.CDS_TRAY_OPEN:
555>                 checkCancelFlag()
556>                 time.sleep(5)
557>         elif drivestatus() == CDROM.CDS_NO_DISC:
558>             displayneededdisktype()
559>             opendrive(dvddrivepath)
5602366c2363
561<         command = "mythreplex --demux --fix_sync -t TS -o %s " % (folder + "/stream")
562---
563>         command = "mythreplex --demux --fix_sync -t TS -o %s " % quoteCmdArg(folder + "/stream")
5642386c2383
565<         command = "mythreplex --demux --fix_sync -o %s " % (folder + "/stream")
566---
567>         command = "mythreplex --demux --fix_sync -o %s " % quoteCmdArg(folder + "/stream")
5682406c2403
569<     mediafile = quoteFilename(mediafile)
570---
571>     mediafile = quoteCmdArg(mediafile)
5722423c2420
573<     command = path_M2VRequantiser[0]   
574---
575>     command = quoteCmdArg(path_M2VRequantiser[0])   
5762426,2427c2423,2424
577<     command += " <  %s " % source
578<     command += " >  %s " % destination
579---
580>     command += " <  %s " % quoteCmdArg(source)
581>     command += " >  %s " % quoteCmdArg(destination)
5822430a2428,2429
583>     if result<>0:
584>         fatalError("Failed while running M2VRequantiser. Command was %s" % command)
5852437,2439d2435
586<             
587<     if result<>0:
588<         fatalError("Failed while running M2VRequantiser. Command was %s" % command)
5893198c3194
590<                 command = "mytharchivehelper -q -q --createthumbnail --infile  %s --thumblist '%s' --outfile '%s' --framecount %d" % (inputfile, starttime, outputfile, frames)
591---
592>                 command = "mytharchivehelper -q -q --createthumbnail --infile  %s --thumblist '%s' --outfile %s --framecount %d" % (quoteCmdArg(inputfile), starttime, quoteCmdArg(outputfile), frames)
5934064c4060
594<     # 5. if there are more that one stream with the chosen language we use the one with the lowest PID
595---
596>     # 5. if there are more than one stream with the chosen language we use the one with the lowest PID
5974788c4784
598<         res = runCommand("mytharchivehelper -q -q --isremote --infile " + quoteFilename(tmpfile))
599---
600>         res = runCommand("mytharchivehelper -q -q --isremote --infile " + quoteCmdArg(tmpfile))
6014853,4855d4848
602<         #Ensure the destination dvd folder is empty
603<         if doesFileExist(os.path.join(getTempPath(),"dvd")):
604<             deleteAllFilesInFolder(os.path.join(getTempPath(),"dvd"))
6054865c4858
606<                 deleteAllFilesInFolder(getTempPath())
607---
608>                 deleteEverythingInFolder(getTempPath())
6094871,4876d4863
610<                     #If it already exists destroy it to remove previous debris
611<                     if os.path.exists(localCopyFolder):
612<                         #Remove all the files first
613<                         deleteAllFilesInFolder(localCopyFolder)
614<                         #Remove the folder
615<                         os.rmdir (localCopyFolder)
6164890,4903d4876
617<                     #If it already exists destroy it to remove previous debris
618<                     if os.path.exists(folder):
619<                         #Remove all the files first
620<                         deleteAllFilesInFolder(folder)
621<                         subtitlefolder = os.path.join(folder, "stream.d")
622<                         if os.path.exists(subtitlefolder):
623<                             deleteAllFilesInFolder(subtitlefolder)
624<                             os.rmdir(subtitlefolder)
625<                         previewfolder = os.path.join(folder, "preview")
626<                         if os.path.exists(previewfolder):
627<                             deleteAllFilesInFolder(previewfolder)
628<                             os.rmdir(previewfolder)
629<                         #Remove the folder
630<                         os.rmdir (folder)
6314990,4992c4963,4977
632<             # convert to ascii and truncate to 32 chars
633<             title = unicodedata.normalize('NFKD', title).encode('ASCII', 'ignore')
634<             title = title[:32]
635---
636>             # replace all non-ascii-cahracters
637>             title.encode('ascii', 'replace').decode('ascii', 'replace')
638>             title.strip()
639>             # replace not-allowed characters
640>             index = 0
641>             title_new = ''
642>             while (index < len(title)) and (index<=7):
643>                 if title[index].isalnum and title[index] != ' ':
644>                     title_new += title[index]
645>                 else:
646>                     title_new += '_'
647>                 index = index + 1
648>             title = title_new.upper()
649>             if len(title) < 1:
650>                 title = 'UNNAMED'