]> code.delx.au - transcoding/commitdiff
Force the mencoder job to run in a temp directory (this stops the divx log file from...
authorGreg Darke <greg+pc-3w14-0@tsukasa.net.au>
Tue, 25 Nov 2008 02:08:55 +0000 (13:08 +1100)
committerGreg Darke <greg+pc-3w14-0@tsukasa.net.au>
Tue, 25 Nov 2008 02:08:55 +0000 (13:08 +1100)
encode.py

index fc3b7c8944cbee01ed5c00aa874121a96422052c..f56eb545e86aa3d3e2be0ca548e4c5b54ee5dd38 100755 (executable)
--- a/encode.py
+++ b/encode.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-import commands, optparse, subprocess, sys, os
+import commands, optparse, subprocess, sys, os, tempfile, shutil
 
 class MencoderCommand(object):
        codec2opts = {
@@ -139,8 +139,14 @@ def parse_args():
                parser.print_usage()
                sys.exit(1)
        
-       opts.input = input
-       opts.output = output
+       if '://' not in input:
+               opts.input = os.path.join(os.getcwd(), input)
+       else:
+               if opts.dvd:
+                       opts.dvd = os.path.join(os.getcwd(), opts.dvd)
+               opts.input = input
+
+       opts.output = os.path.join(os.getcwd(), output)
        return opts
 
 def run(args, dump):
@@ -157,9 +163,15 @@ def main():
                print >>sys.stderr, "Profile '%s' not found!" % profile_name
                sys.exit(1)
 
-       cmd = profile.CommandClass(profile, opts)
-       if run(cmd.pass1(), opts.dump) == 0 or opts.dump:
-               run(cmd.pass2(), opts.dump)
+       tempdir = tempfile.mkdtemp()
+       try:
+               os.chdir(tempdir)
+               cmd = profile.CommandClass(profile, opts)
+               if run(cmd.pass1(), opts.dump) == 0 or opts.dump:
+                       run(cmd.pass2(), opts.dump)
+       finally:
+               os.chdir('/')
+               shutil.rmtree(tempdir)
 
 if __name__ == "__main__":
        main()