1 # Pyvconv - A simple frontend for ffmpeg/mencoder
2 # Copyright (C) 2008, Kristian Rumberg (kristianrumberg@gmail.com)
4 # Permission to use, copy, modify, and/or distribute this software for any
5 # purpose with or without fee is hereby granted, provided that the above
6 # copyright notice and this permission notice appear in all copies.
8 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 from commands
import Variable
21 class CommandExecuterView
:
25 def starting_conversion(self
, infile
, index
, total
, outfile
):
28 def update_progress(self
, logline
):
31 def finished_conversion(self
, infile
, outfile
):
34 def finished_all(self
):
37 class CommandExecuter
:
38 def __init__(self
, cmdexecview
, command
, infilelist
, outdir
):
39 self
.cmdexecview
= cmdexecview
40 self
.command
= command
41 self
.infilelist
= infilelist
44 thread
.start_new_thread(self
._run
_conversion
, ())
46 def _run_conversion(self
):
48 total
= len(self
.infilelist
)
50 for infile
in self
.infilelist
:
51 outfile
= self
.outdir
+ "/" + os
.path
.basename(infile
) + "_converted"
55 self
.command
.put_var(Variable("in", infile
))
56 self
.command
.put_var(Variable("out", outfile
))
58 self
.cmdexecview
.starting_conversion(infile
, index
, total
, outfile
)
60 p
= subprocess
.Popen(str(self
.command
), shell
= True, universal_newlines
=True, stderr
= subprocess
.PIPE
)
62 newline
= str(chr(32) * 4)
71 if buff
.endswith(newline
):
72 skipc
= (skipc
+ 1) % iskip
74 self
.cmdexecview
.update_progress(buff
.strip())
79 self
.cmdexecview
.finished_conversion(infile
, outfile
)
81 self
.cmdexecview
.finished_all()