]> code.delx.au - transcoding/commitdiff
Better quoting for --dump
authorJames Bunton <jamesbunton@fastmail.fm>
Mon, 19 Jul 2010 21:51:32 +0000 (07:51 +1000)
committerJames Bunton <jamesbunton@fastmail.fm>
Mon, 19 Jul 2010 21:51:32 +0000 (07:51 +1000)
encode.py

index a6f0cd863335ad1c24e6e4335577a77447bd8345..11e8ebfd12f873ab4f42cd50d68f0205098ad4ef 100755 (executable)
--- a/encode.py
+++ b/encode.py
@@ -1,24 +1,29 @@
 #!/usr/bin/env python
 
-import commands
 import optparse
-import shlex
+import re
 import subprocess
 import sys
 import os
-import tempfile
 import shutil
+import tempfile
 
 class FatalException(Exception):
        pass
 
 def mkarg(arg):
-       quoted_arg = commands.mkarg(arg)
-       arg = quoted_arg[2:-1]
-       if len(shlex.split(arg)) == 1:
+       if re.match("^[a-zA-Z0-9\-\\.,/@_:=]*$", arg):
                return arg
-       else:
-               return quoted_arg[1:]
+
+       if "'" not in arg:
+               return "'%s'" % arg
+       out = "\""
+       for c in arg:
+               if c in "\\$\"`":
+                       out += "\\"
+               out += c
+       out += "\""
+       return out
 
 class Command(object):
        def __init__(self, profile, opts):
@@ -188,7 +193,7 @@ profiles = {
        Profile(
                commands=[Mencoder, MKVMerge],
                vcodec="x264",
-               vopts="pass=%(vpass)d:bitrate=%(vbitrate)d:subq=6:frameref=6:me=umh:partitions=all:bframes=4:b_adapt:qcomp=0.7:keyint=250:threads=2",
+               vopts="pass=%(vpass)d:bitrate=%(vbitrate)d:subq=6:frameref=6:me=umh:partitions=all:bframes=4:b_adapt:qcomp=0.7:keyint=250",
                acodec="mp3lame",
                aopts="abr:br=%(abitrate)d",
        ),