Store window size and use template in transcoder
This commit is contained in:
parent
4a6d85f7ea
commit
36bf30e314
1 changed files with 20 additions and 4 deletions
|
@ -4,7 +4,7 @@ import subprocess
|
||||||
import re
|
import re
|
||||||
import signal
|
import signal
|
||||||
|
|
||||||
from gi.repository import GLib, GObject
|
from gi.repository import GLib, GObject, Gio
|
||||||
from recoder.models import FileStatus, FileItem
|
from recoder.models import FileStatus, FileItem
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,6 +25,9 @@ class Transcoder(GObject.GObject):
|
||||||
batch_progress = GObject.Property(type=int, minimum=0, maximum=100, default=0)
|
batch_progress = GObject.Property(type=int, minimum=0, maximum=100, default=0)
|
||||||
batch_status = GObject.Property(type=BatchStatus, default=BatchStatus.IDLE)
|
batch_status = GObject.Property(type=BatchStatus, default=BatchStatus.IDLE)
|
||||||
|
|
||||||
|
# Property bound to GSettings key for output folder template
|
||||||
|
output_folder_template = GObject.Property(type=str, default="transcoded")
|
||||||
|
|
||||||
def __init__(self, file_items):
|
def __init__(self, file_items):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.file_items = file_items
|
self.file_items = file_items
|
||||||
|
@ -34,6 +37,20 @@ class Transcoder(GObject.GObject):
|
||||||
self._paused.set()
|
self._paused.set()
|
||||||
self._process = None
|
self._process = None
|
||||||
|
|
||||||
|
self.settings = Gio.Settings.new("net.jeena.recoder.preferences")
|
||||||
|
self.settings.bind(
|
||||||
|
"output-folder-template", self,
|
||||||
|
"output_folder_template",
|
||||||
|
Gio.SettingsBindFlags.DEFAULT
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_output_folder(self, path):
|
||||||
|
source_folder = os.path.basename(os.path.dirname(path))
|
||||||
|
folder_name = self.output_folder_template.replace("{{source_folder_name}}", source_folder)
|
||||||
|
folder_name = os.path.expanduser(folder_name)
|
||||||
|
output_folder = os.path.join(os.path.dirname(path), folder_name)
|
||||||
|
return output_folder
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
if self.is_processing:
|
if self.is_processing:
|
||||||
return
|
return
|
||||||
|
@ -76,14 +93,13 @@ class Transcoder(GObject.GObject):
|
||||||
GLib.idle_add(file_item.set_property, "status", FileStatus.PROCESSING)
|
GLib.idle_add(file_item.set_property, "status", FileStatus.PROCESSING)
|
||||||
GLib.idle_add(file_item.set_property, "progress", 0)
|
GLib.idle_add(file_item.set_property, "progress", 0)
|
||||||
|
|
||||||
success, _ = self._transcode_file(path, os.path.join(os.path.dirname(path), "transcoded"),
|
output_folder = self.get_output_folder(path)
|
||||||
base, idx, total, file_item)
|
success, _ = self._transcode_file(path, output_folder, base, idx, total, file_item)
|
||||||
|
|
||||||
new_status = FileStatus.DONE if success else FileStatus.ERROR
|
new_status = FileStatus.DONE if success else FileStatus.ERROR
|
||||||
GLib.idle_add(file_item.set_property, "status", new_status)
|
GLib.idle_add(file_item.set_property, "status", new_status)
|
||||||
GLib.idle_add(file_item.set_property, "progress", 100 if success else 0)
|
GLib.idle_add(file_item.set_property, "progress", 100 if success else 0)
|
||||||
|
|
||||||
# Fix: Only set ERROR if not stopped by user
|
|
||||||
if not success and not self._stop_requested:
|
if not success and not self._stop_requested:
|
||||||
self.batch_status = BatchStatus.ERROR
|
self.batch_status = BatchStatus.ERROR
|
||||||
break
|
break
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue