optimised filechooser and fixed multiple bugs
This commit is contained in:
@@ -18,24 +18,39 @@ class Checks:
|
|||||||
try:
|
try:
|
||||||
self.custom_quality = float(custom_q)
|
self.custom_quality = float(custom_q)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
if str(custom_q)[len(custom_q) - 1:] == "x":
|
||||||
|
print("x found")
|
||||||
|
try:
|
||||||
|
self.custom_quality = float(str(custom_q)[:len(custom_q) - 1])
|
||||||
|
except ValueError:
|
||||||
|
print("invalid custom quality multiplier")
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
|
print("invalid letter in custom quality multiplier!")
|
||||||
|
return False
|
||||||
|
if 4 >= self.custom_quality >= 1:
|
||||||
|
print("quality selction ok")
|
||||||
return True
|
return True
|
||||||
|
else:
|
||||||
|
print("invalid range for multiplier!")
|
||||||
|
|
||||||
def file_checks(self, i_fp, o_fp):
|
def file_checks(self, i_fp, o_fp):
|
||||||
self.i_file_extension = str(i_fp)[len(i_fp) - 4:]
|
self.i_file_extension = str(i_fp)[len(i_fp) - 4:]
|
||||||
if self.i_file_extension == ".png" or self.i_file_extension == ".jpg":
|
if self.i_file_extension == ".png" or self.i_file_extension == ".jpg":
|
||||||
pass
|
print("file extensions ok (image)")
|
||||||
elif self.i_file_extension == "jpeg":
|
elif self.i_file_extension == "jpeg":
|
||||||
if str(i_fp)[len(i_fp) - 5:] == ".jpeg":
|
if str(i_fp)[len(i_fp) - 5:] == ".jpeg":
|
||||||
pass
|
print("file extensions ok (image)")
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
elif self.i_file_extension == ".mp4" or self.i_file_extension == ".mkv":
|
elif self.i_file_extension == ".mp4" or self.i_file_extension == ".mkv":
|
||||||
pass
|
print("file extensions ok (video)")
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if str(i_fp)[len(i_fp) - 4:] == str(o_fp)[len(o_fp) - 4:]:
|
if str(i_fp)[len(i_fp) - 4:] == str(o_fp)[len(o_fp) - 4:]:
|
||||||
|
print("file extensions are the same in output and input")
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
print("files don't have same extension!")
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import time
|
|||||||
|
|
||||||
# Loading the config file to get user preferred temp path
|
# Loading the config file to get user preferred temp path
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read('../config/settings.ini')
|
config.read('./config/settings.ini')
|
||||||
|
|
||||||
|
|
||||||
class Handler:
|
class Handler:
|
||||||
@@ -29,12 +29,14 @@ class Handler:
|
|||||||
def handler(self, fsrpath, filepath, quality_mode, quality_setting, output_path, ffmpegpath):
|
def handler(self, fsrpath, filepath, quality_mode, quality_setting, output_path, ffmpegpath):
|
||||||
# Function to be called when using this class as this function automatically determines if file is video or image
|
# Function to be called when using this class as this function automatically determines if file is video or image
|
||||||
if self.os_type == "linux":
|
if self.os_type == "linux":
|
||||||
self.tmppath = "/tmp/fsru/" # config["PathSettings"]["tmpPathLinux"]
|
self.tmppath = config["PathSettings"]["tmpPathLinux"]
|
||||||
elif self.os_type == "win32":
|
elif self.os_type == "win32":
|
||||||
self.tmppath = config["PathSettings"]["tmpPathWindows"]
|
self.tmppath = config["PathSettings"]["tmpPathWindows"]
|
||||||
else:
|
else:
|
||||||
print("OS CURRENTLY UNSUPPORTED!")
|
print("OS CURRENTLY UNSUPPORTED!")
|
||||||
return False
|
return False
|
||||||
|
self.tmppath += "fsru/"
|
||||||
|
print(self.tmppath)
|
||||||
# checking for spaces in filepath (for use with terminal commands)
|
# checking for spaces in filepath (for use with terminal commands)
|
||||||
self.filepath = ""
|
self.filepath = ""
|
||||||
for self.letter in filepath:
|
for self.letter in filepath:
|
||||||
@@ -83,9 +85,14 @@ class Handler:
|
|||||||
# Retrieving Video metadata
|
# Retrieving Video metadata
|
||||||
self.duration = self.videometa.get("duration")
|
self.duration = self.videometa.get("duration")
|
||||||
self.frames = self.videometa.get("nb_frames")
|
self.frames = self.videometa.get("nb_frames")
|
||||||
|
try:
|
||||||
self.framerate = round(float(self.frames) / float(self.duration), 1)
|
self.framerate = round(float(self.frames) / float(self.duration), 1)
|
||||||
|
except TypeError:
|
||||||
|
self.infos = str(self.videometa.get("r_frame_rate"))
|
||||||
|
self.framerate = float(self.infos[:len(self.infos) - 2])
|
||||||
|
|
||||||
# Splitting video into frames
|
# Splitting video into frames
|
||||||
|
os.remove(self.tmppath)
|
||||||
try:
|
try:
|
||||||
os.mkdir(self.tmppath)
|
os.mkdir(self.tmppath)
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
@@ -93,9 +100,9 @@ class Handler:
|
|||||||
|
|
||||||
if self.os_type == "linux":
|
if self.os_type == "linux":
|
||||||
print("linux")
|
print("linux")
|
||||||
self.command = f"ffmpeg -i {str(self.filepath)} {self.tmppath}thumb%04d.jpg -hide_banner"
|
self.command = f"ffmpeg -i {str(self.filepath)} {self.tmppath}thumb%08d.jpg"
|
||||||
elif self.os_type == "win32":
|
elif self.os_type == "win32":
|
||||||
self.command = f"{ffmpegpath} -i {str(self.filepath)} {self.tmppath}thumb%04d.jpg -hide_banner"
|
self.command = f"{ffmpegpath} -i {str(self.filepath)} {self.tmppath}thumb%08d.jpg"
|
||||||
else:
|
else:
|
||||||
print("OS CURRENTLY UNSUPPORTED!")
|
print("OS CURRENTLY UNSUPPORTED!")
|
||||||
return False
|
return False
|
||||||
@@ -110,13 +117,12 @@ class Handler:
|
|||||||
self.number = 0
|
self.number = 0
|
||||||
for self.file in self.filelist:
|
for self.file in self.filelist:
|
||||||
self.number += 1
|
self.number += 1
|
||||||
self.files += f"{self.tmppath}{self.file} {self.tmppath}upscaled/USImage{str(self.number).zfill(4)}.jpg "
|
self.files += f"{self.tmppath}{self.file} {self.tmppath}upscaled/USImage{str(self.number).zfill(8)}.jpg "
|
||||||
self.maxlength = 32000
|
self.maxlength = 32000
|
||||||
self.pos = 1
|
self.pos = 1
|
||||||
|
|
||||||
# Refactoring of commands that are longer than 32K characters
|
# Refactoring of commands that are longer than 32K characters
|
||||||
if len(self.files) > self.maxlength:
|
if len(self.files) > self.maxlength:
|
||||||
print("shrinking command length")
|
|
||||||
self.fileout = []
|
self.fileout = []
|
||||||
|
|
||||||
while self.files[self.maxlength - self.pos:self.maxlength - self.pos + 1] != " ":
|
while self.files[self.maxlength - self.pos:self.maxlength - self.pos + 1] != " ":
|
||||||
@@ -157,7 +163,6 @@ class Handler:
|
|||||||
self.fileout.append(self.files[self.maxlength - self.pos:])
|
self.fileout.append(self.files[self.maxlength - self.pos:])
|
||||||
else:
|
else:
|
||||||
self.fileout.append(self.files)
|
self.fileout.append(self.files)
|
||||||
print("filepath assembled")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.mkdir(f"{self.tmppath}upscaled/")
|
os.mkdir(f"{self.tmppath}upscaled/")
|
||||||
@@ -185,7 +190,6 @@ class Handler:
|
|||||||
else:
|
else:
|
||||||
print("OS CURRENTLY UNSUPPORTED!")
|
print("OS CURRENTLY UNSUPPORTED!")
|
||||||
return False
|
return False
|
||||||
print(self.command, "\n\n\nCOMMAND to EXECUTE\n\n\n")
|
|
||||||
os.system(self.command)
|
os.system(self.command)
|
||||||
print("Finished upscaling this section.")
|
print("Finished upscaling this section.")
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
@@ -209,9 +213,9 @@ class Handler:
|
|||||||
# reassemble Video
|
# reassemble Video
|
||||||
print("Reassembling Video... with framerate @", self.framerate)
|
print("Reassembling Video... with framerate @", self.framerate)
|
||||||
if self.os_type == "linux":
|
if self.os_type == "linux":
|
||||||
self.command = f"ffmpeg -framerate {self.framerate} -i {self.tmppath}upscaled/USImage%04d.jpg {output_path} -i {self.tmppath}audio.aac"
|
self.command = f"ffmpeg -framerate {self.framerate} -i {self.tmppath}upscaled/USImage%08d.jpg {output_path} -i {self.tmppath}audio.aac"
|
||||||
elif self.os_type == "win32":
|
elif self.os_type == "win32":
|
||||||
self.command = f"{ffmpegpath} -framerate {self.framerate} -i {self.tmppath}upscaled/USImage%04d.jpg {output_path} -i {self.tmppath}audio.aac"
|
self.command = f"{ffmpegpath} -framerate {self.framerate} -i {self.tmppath}upscaled/USImage%08d.jpg {output_path} -i {self.tmppath}audio.aac"
|
||||||
else:
|
else:
|
||||||
print("OS CURRENTLY UNSUPPORTED!")
|
print("OS CURRENTLY UNSUPPORTED!")
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
# Developed 2022 by Janis Hutz
|
# Developed 2022 by Janis Hutz
|
||||||
#
|
#
|
||||||
###########################################################
|
###########################################################
|
||||||
|
import sys
|
||||||
import gi
|
import gi
|
||||||
import bin.handler
|
import bin.handler
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
@@ -28,7 +28,7 @@ class ProgressIndicator(Gtk.Dialog):
|
|||||||
self.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK)
|
self.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK)
|
||||||
self.set_default_size(150, 100)
|
self.set_default_size(150, 100)
|
||||||
self.spinner = Gtk.Spinner()
|
self.spinner = Gtk.Spinner()
|
||||||
self.label = Gtk.Label(label=" Upscaling. This process will take long (if a Video). \n Duration depends on your Hardware and length and resolution of video \n You may see the output of the app, if you switch to the other window that is behind it. ")
|
self.label = Gtk.Label(label=" Upscaling. This process will take long (if a Video). \n Duration depends on your Hardware and length and resolution of video \n You may see the output of the app, if you switch to the other window that is behind it. \n\n\n click \"ok\" to start upscaling")
|
||||||
self.box = self.get_content_area()
|
self.box = self.get_content_area()
|
||||||
self.box.pack_start(self.label, True, True, 20)
|
self.box.pack_start(self.label, True, True, 20)
|
||||||
self.box.pack_start(self.spinner, True, True, 20)
|
self.box.pack_start(self.spinner, True, True, 20)
|
||||||
@@ -41,7 +41,7 @@ class ErrorDialogFileMissing(Gtk.Dialog):
|
|||||||
super().__init__(title="Error", transient_for=parent, flags=0)
|
super().__init__(title="Error", transient_for=parent, flags=0)
|
||||||
self.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK)
|
self.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK)
|
||||||
self.set_default_size(150, 100)
|
self.set_default_size(150, 100)
|
||||||
self.label = Gtk.Label(label=" No file specified. Please select a input AND output file! ")
|
self.label = Gtk.Label(label=" No file specified. Please select an input AND output file! ")
|
||||||
self.box = self.get_content_area()
|
self.box = self.get_content_area()
|
||||||
self.box.pack_start(self.label, True, True, 20)
|
self.box.pack_start(self.label, True, True, 20)
|
||||||
self.show_all()
|
self.show_all()
|
||||||
@@ -63,7 +63,7 @@ class ErrorDialogCheckFail(Gtk.Dialog):
|
|||||||
super().__init__(title="Error", transient_for=parent, flags=0)
|
super().__init__(title="Error", transient_for=parent, flags=0)
|
||||||
self.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK)
|
self.add_buttons(Gtk.STOCK_OK, Gtk.ResponseType.OK)
|
||||||
self.set_default_size(150, 100)
|
self.set_default_size(150, 100)
|
||||||
self.label = Gtk.Label(label=" Filechecks failed. Make sure to specify the same file extension in the output like in the input ")
|
self.label = Gtk.Label(label=" File and settings check failed. \n Make sure to specify the same file extension in the output like in the input \n make sure that the entries you made as settings are valid! (4 >= scale >= 1) ")
|
||||||
self.box = self.get_content_area()
|
self.box = self.get_content_area()
|
||||||
self.box.pack_start(self.label, True, True, 20)
|
self.box.pack_start(self.label, True, True, 20)
|
||||||
self.show_all()
|
self.show_all()
|
||||||
@@ -72,6 +72,7 @@ class ErrorDialogCheckFail(Gtk.Dialog):
|
|||||||
class HomeWindow(Gtk.Window):
|
class HomeWindow(Gtk.Window):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(title="Test")
|
super().__init__(title="Test")
|
||||||
|
self.os_type = sys.platform
|
||||||
self.save_file = ""
|
self.save_file = ""
|
||||||
self.open_file = ""
|
self.open_file = ""
|
||||||
|
|
||||||
@@ -124,7 +125,7 @@ class HomeWindow(Gtk.Window):
|
|||||||
self.quality_select_box.pack_start(self.quality_select_shrink, True, True, 20)
|
self.quality_select_box.pack_start(self.quality_select_shrink, True, True, 20)
|
||||||
|
|
||||||
# Custom Quality Selector
|
# Custom Quality Selector
|
||||||
self.custom_quality_selector_title = Gtk.Label(label="Custom Upscaling Multiplier")
|
self.custom_quality_selector_title = Gtk.Label(label="Custom Upscaling Multiplier\nNOTE that factors greater than 2 are not recommended!\nFactors greater than 4 will not run!")
|
||||||
self.custom_quality_selector_shrink = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
self.custom_quality_selector_shrink = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||||
self.custom_quality_selector = Gtk.Entry()
|
self.custom_quality_selector = Gtk.Entry()
|
||||||
self.custom_quality_selector_shrink.pack_start(self.custom_quality_selector, True, False, 30)
|
self.custom_quality_selector_shrink.pack_start(self.custom_quality_selector, True, False, 30)
|
||||||
@@ -171,7 +172,24 @@ class HomeWindow(Gtk.Window):
|
|||||||
def opfilechooser_clicked(self, widget):
|
def opfilechooser_clicked(self, widget):
|
||||||
self.filechooserdialog_save = Gtk.FileChooserDialog(title="Choose output file", action=Gtk.FileChooserAction.SAVE)
|
self.filechooserdialog_save = Gtk.FileChooserDialog(title="Choose output file", action=Gtk.FileChooserAction.SAVE)
|
||||||
Gtk.FileChooser.set_do_overwrite_confirmation(self.filechooserdialog_save, True)
|
Gtk.FileChooser.set_do_overwrite_confirmation(self.filechooserdialog_save, True)
|
||||||
|
if self.os_type == "linux":
|
||||||
|
Gtk.FileChooser.set_current_folder(self.filechooserdialog_save, "/home")
|
||||||
|
elif self.os_type == "win32":
|
||||||
|
Gtk.FileChooser.set_current_folder(self.filechooserdialog_save, "%HOMEPATH%")
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
if str(self.open_file)[len(self.open_file) - 4:] == ".mp4":
|
||||||
Gtk.FileChooser.set_current_name(self.filechooserdialog_save, "video.mp4")
|
Gtk.FileChooser.set_current_name(self.filechooserdialog_save, "video.mp4")
|
||||||
|
elif str(self.open_file)[len(self.open_file) - 4:] == ".mkv":
|
||||||
|
Gtk.FileChooser.set_current_name(self.filechooserdialog_save, "video.mkv")
|
||||||
|
elif str(self.open_file)[len(self.open_file) - 4:] == ".png":
|
||||||
|
Gtk.FileChooser.set_current_name(self.filechooserdialog_save, "image.png")
|
||||||
|
elif str(self.open_file)[len(self.open_file) - 4:] == ".jpg":
|
||||||
|
Gtk.FileChooser.set_current_name(self.filechooserdialog_save, "image.jpg")
|
||||||
|
elif str(self.open_file)[len(self.open_file) - 4:] == ".jpeg":
|
||||||
|
Gtk.FileChooser.set_current_name(self.filechooserdialog_save, "image.jpeg")
|
||||||
|
else:
|
||||||
|
Gtk.FileChooser.set_current_name(self.filechooserdialog_save, "")
|
||||||
self.filechooserdialog_save.add_buttons(
|
self.filechooserdialog_save.add_buttons(
|
||||||
Gtk.STOCK_CANCEL,
|
Gtk.STOCK_CANCEL,
|
||||||
Gtk.ResponseType.CANCEL,
|
Gtk.ResponseType.CANCEL,
|
||||||
@@ -180,10 +198,9 @@ class HomeWindow(Gtk.Window):
|
|||||||
)
|
)
|
||||||
self.response = self.filechooserdialog_save.run()
|
self.response = self.filechooserdialog_save.run()
|
||||||
if self.response == Gtk.ResponseType.OK:
|
if self.response == Gtk.ResponseType.OK:
|
||||||
print("ok, selected file:", self.filechooserdialog_save.get_filename())
|
|
||||||
self.save_file = self.filechooserdialog_save.get_filename()
|
self.save_file = self.filechooserdialog_save.get_filename()
|
||||||
elif self.response == Gtk.ResponseType.CANCEL:
|
elif self.response == Gtk.ResponseType.CANCEL:
|
||||||
print("cancel")
|
pass
|
||||||
self.filechooserdialog_save.destroy()
|
self.filechooserdialog_save.destroy()
|
||||||
|
|
||||||
def start_clicked(self, widget):
|
def start_clicked(self, widget):
|
||||||
@@ -199,16 +216,19 @@ class HomeWindow(Gtk.Window):
|
|||||||
|
|
||||||
if self.respawn:
|
if self.respawn:
|
||||||
if str(self.open_file) != "" and str(self.save_file) != "":
|
if str(self.open_file) != "" and str(self.save_file) != "":
|
||||||
print("ok")
|
|
||||||
if checks.perform(self.output, self.custom_quality_selector.get_text(), self.open_file, self.save_file):
|
if checks.perform(self.output, self.custom_quality_selector.get_text(), self.open_file, self.save_file):
|
||||||
if self.output == "Custom (will respect value below)":
|
if self.output == "Custom (will respect value below)":
|
||||||
self.quality_selected = "custom"
|
self.quality_selected = "custom"
|
||||||
|
if self.custom_quality_selector.get_text()[len(self.custom_quality_selector.get_text()) - 1] == "x":
|
||||||
self.q = f"{self.custom_quality_selector.get_text()} {self.custom_quality_selector.get_text()}"
|
self.q = f"{self.custom_quality_selector.get_text()} {self.custom_quality_selector.get_text()}"
|
||||||
|
else:
|
||||||
|
self.q = f"{self.custom_quality_selector.get_text()}x {self.custom_quality_selector.get_text()}x"
|
||||||
else:
|
else:
|
||||||
self.quality_selected = "default"
|
self.quality_selected = "default"
|
||||||
self.q = str(arg.get(self.output))
|
self.q = str(arg.get(self.output))
|
||||||
self.go = True
|
self.go = True
|
||||||
if self.go:
|
if self.go:
|
||||||
|
print("\n\nStarting upscaling process!\n\n")
|
||||||
self.pr_i = ProgressIndicator(self)
|
self.pr_i = ProgressIndicator(self)
|
||||||
self.pr_i.run()
|
self.pr_i.run()
|
||||||
self.pr_i.destroy()
|
self.pr_i.destroy()
|
||||||
@@ -229,6 +249,7 @@ class HomeWindow(Gtk.Window):
|
|||||||
print("no file specified")
|
print("no file specified")
|
||||||
self.fileerror()
|
self.fileerror()
|
||||||
else:
|
else:
|
||||||
|
self.runningerror()
|
||||||
print("Already running!")
|
print("Already running!")
|
||||||
|
|
||||||
def runningerror(self):
|
def runningerror(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user