Now shows the progress percentage when converting a file
Added better error checking (still needs to show an error window)
This commit is contained in:
parent
889325aaed
commit
8de307fd73
6 changed files with 86 additions and 50 deletions
|
|
@ -7,6 +7,7 @@
|
|||
<property name="height_request">270</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes">devede</property>
|
||||
<property name="window_position">center</property>
|
||||
<property name="icon_name">devede.svg</property>
|
||||
<property name="type_hint">dialog</property>
|
||||
<child internal-child="vbox">
|
||||
|
|
|
|||
|
|
@ -34,12 +34,15 @@ class avconv_converter(devede.executor.executor):
|
|||
|
||||
@staticmethod
|
||||
def check_is_installed():
|
||||
try:
|
||||
handle = subprocess.Popen(["avconv","-version"], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
|
||||
(stdout, stderr) = handle.communicate()
|
||||
if 0==handle.wait():
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
except:
|
||||
return False
|
||||
|
||||
def __init__(self):
|
||||
|
||||
|
|
@ -312,7 +315,7 @@ class avconv_converter(devede.executor.executor):
|
|||
|
||||
def process_stdout(self,data):
|
||||
|
||||
pass
|
||||
return
|
||||
|
||||
def process_stderr(self,data):
|
||||
|
||||
|
|
@ -321,5 +324,6 @@ class avconv_converter(devede.executor.executor):
|
|||
pos+=5
|
||||
pos2 = data[0].find(" ",pos)
|
||||
if (pos2 != -1):
|
||||
t = float(data[0][pos:pos2])
|
||||
self.progress_bar[1].set_fraction(t / self.final_length)
|
||||
t = float(data[0][pos:pos2]) / self.final_length
|
||||
self.progress_bar[1].set_fraction(t)
|
||||
self.progress_bar[1].set_text("%.1f%%" % (100.0 * t))
|
||||
|
|
@ -83,10 +83,10 @@ class executor(GObject.GObject):
|
|||
def run(self, progress_bar):
|
||||
|
||||
self.progress_bar = progress_bar
|
||||
self.launch_process(self.command_var)
|
||||
self.progress_bar[0].set_label(self.text)
|
||||
self.progress_bar[1].set_fraction(0.0)
|
||||
self.progress_bar[0].show_all()
|
||||
self.launch_process(self.command_var)
|
||||
|
||||
def remove_ansi(self,line):
|
||||
|
||||
|
|
@ -115,14 +115,14 @@ class executor(GObject.GObject):
|
|||
return output
|
||||
|
||||
|
||||
def launch_process(self,command):
|
||||
def launch_process(self,command,redirect_output = True):
|
||||
|
||||
self.launch_command = "Launching:"
|
||||
self.launch_command = "\n\nLaunching:"
|
||||
for e in command:
|
||||
self.launch_command += (e+" ")
|
||||
|
||||
print(self.launch_command)
|
||||
self.launch_command += (" "+e)
|
||||
self.launch_command += "\n"
|
||||
|
||||
try:
|
||||
if (self.stdin_file != None):
|
||||
self.handle = subprocess.Popen(command,stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
|
||||
self.channel_stdin = GLib.IOChannel(self.handle.stdin.fileno())
|
||||
|
|
@ -130,6 +130,14 @@ class executor(GObject.GObject):
|
|||
self.file_in = open(self.stdin_file,"rb")
|
||||
else:
|
||||
self.handle = subprocess.Popen(command,stdout = subprocess.PIPE, stderr = subprocess.PIPE)
|
||||
except Exception as error_launch:
|
||||
self.stderr_data += str(error_launch)
|
||||
self.wait_end()
|
||||
return
|
||||
|
||||
if (redirect_output):
|
||||
self.stdout_buf = ""
|
||||
self.stderr_buf = ""
|
||||
self.channel_stdout = GLib.IOChannel(self.handle.stdout.fileno())
|
||||
self.channel_stderr = GLib.IOChannel(self.handle.stderr.fileno())
|
||||
if (self.stdout_file != None):
|
||||
|
|
@ -138,8 +146,19 @@ class executor(GObject.GObject):
|
|||
else:
|
||||
self.channel_stdout.add_watch(GLib.IO_IN | GLib.IO_HUP,self.read_stdout)
|
||||
self.channel_stderr.add_watch(GLib.IO_IN | GLib.IO_HUP,self.read_stderr)
|
||||
self.stdout_buf = ""
|
||||
self.stderr_buf = ""
|
||||
else:
|
||||
(stdout_r, stderr_r) = self.handle.communicate()
|
||||
self.config.append_log(self.launch_command)
|
||||
try:
|
||||
self.config.append_log(stdout_r.decode("utf-8"))
|
||||
except:
|
||||
self.config.append_log(stdout_r.decode("latin-1"))
|
||||
try:
|
||||
self.config.append_log(stderr_r.decode("utf-8"))
|
||||
except:
|
||||
self.config.append_log(stderr_r.decode("latin-1"))
|
||||
return (stdout_r, stderr_r)
|
||||
|
||||
|
||||
|
||||
def read_stdout_to_file(self,source,condition):
|
||||
|
|
@ -176,7 +195,11 @@ class executor(GObject.GObject):
|
|||
self.wait_end()
|
||||
return False
|
||||
else:
|
||||
line_data = self.stdout_buf+(self.handle.stdout.read1(4096).decode("utf-8"))
|
||||
read_data = self.handle.stdout.read1(4096)
|
||||
try:
|
||||
line_data = self.stdout_buf+(read_data.decode("utf-8"))
|
||||
except:
|
||||
line_data = self.stdout_buf+(read_data.decode("latin-1"))
|
||||
self.stdout_data += line_data
|
||||
data = (line_data).replace("\r","\n").split("\n")
|
||||
if (len(data) == 1):
|
||||
|
|
@ -198,7 +221,11 @@ class executor(GObject.GObject):
|
|||
self.wait_end()
|
||||
return False
|
||||
else:
|
||||
line_data = self.stderr_buf+(self.handle.stderr.read1(4096).decode("utf-8"))
|
||||
read_data = self.handle.stderr.read1(4096)
|
||||
try:
|
||||
line_data = self.stderr_buf+(read_data.decode("utf-8"))
|
||||
except:
|
||||
line_data = self.stderr_buf+(read_data.decode("latin-1"))
|
||||
self.stderr_data += line_data
|
||||
data = (line_data).replace("\r","\n").split("\n")
|
||||
if (len(data) == 1):
|
||||
|
|
@ -226,5 +253,8 @@ class executor(GObject.GObject):
|
|||
self.config.append_log(self.launch_command)
|
||||
self.config.append_log(self.stdout_data)
|
||||
self.config.append_log(self.stderr_data)
|
||||
if self.handle != None:
|
||||
retval = self.handle.wait()
|
||||
else:
|
||||
retval = -1
|
||||
self.emit("ended",retval)
|
||||
|
|
@ -29,15 +29,19 @@ class mplayer_detector(devede.executor.executor):
|
|||
|
||||
@staticmethod
|
||||
def check_is_installed():
|
||||
try:
|
||||
handle = subprocess.Popen(["mplayer","-v"], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
|
||||
(stdout, stderr) = handle.communicate()
|
||||
if 0==handle.wait():
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
except:
|
||||
return False
|
||||
|
||||
def __init__(self):
|
||||
|
||||
devede.executor.executor.__init__(self)
|
||||
self.config = devede.configuration_data.configuration.get_config()
|
||||
|
||||
def get_film_data(self, file_name):
|
||||
|
|
@ -61,8 +65,7 @@ class mplayer_detector(devede.executor.executor):
|
|||
|
||||
command_line = ["mplayer","-loop","1","-identify", "-vo", "null", "-ao", "null", "-frames", frames , file_name]
|
||||
|
||||
handle = subprocess.Popen(command_line, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
|
||||
(stdout, stderr) = handle.communicate()
|
||||
(stdout, stderr) = self.launch_process(command_line, False)
|
||||
|
||||
minimum_audio=-1
|
||||
self.audio_list=[]
|
||||
|
|
@ -75,8 +78,14 @@ class mplayer_detector(devede.executor.executor):
|
|||
self.original_audiorate = 0
|
||||
self.original_audiorate_uncompressed = 0
|
||||
self.original_fps = 0
|
||||
self.original_aspect_ratio = 0
|
||||
|
||||
for line in str(stdout).split("\\n"):
|
||||
try:
|
||||
stdout2 = stdout.decode("utf-8")
|
||||
except:
|
||||
stdout2 = stdout.decode("latin1")
|
||||
|
||||
for line in stdout2.split("\n"):
|
||||
line=self.remove_ansi(line)
|
||||
if line == "":
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -41,13 +41,4 @@ class mux_dvd_menu(devede.executor.executor):
|
|||
|
||||
def process_stderr(self,data):
|
||||
|
||||
print("spumux: "+str(data))
|
||||
return
|
||||
|
||||
pos = data[0].find("time=")
|
||||
if (pos != -1):
|
||||
pos+=5
|
||||
pos2 = data[0].find(" ",pos)
|
||||
if (pos2 != -1):
|
||||
t = float(data[0][pos:pos2])
|
||||
self.progress_bar[1].set_fraction(t / self.sound_length)
|
||||
|
|
@ -51,6 +51,7 @@ class runner(GObject.GObject):
|
|||
f = Gtk.Frame()
|
||||
p = Gtk.ProgressBar()
|
||||
p.set_orientation(Gtk.Orientation.HORIZONTAL)
|
||||
p.set_show_text(True)
|
||||
f.add(p)
|
||||
# A frame, a progress bar, and the process running in that bar
|
||||
self.progress_bars.append([f, p, None])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue