#!/usr/bin/env python
-import commands
import optparse
+import re
import subprocess
import sys
import os
-import tempfile
import shutil
+import tempfile
class FatalException(Exception):
pass
+def mkarg(arg):
+ if re.match("^[a-zA-Z0-9\-\\.,/@_:=]*$", arg):
+ return arg
+
+ 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):
self.profile = profile
def do_exec(self, args):
if self.opts.dump:
- print "".join(map(commands.mkarg, args))[1:]
+ print " ".join(map(mkarg, args))
else:
if subprocess.Popen(args).wait() != 0:
raise FatalException("Failure executing command: %s" % args)
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",
),