optimised filechooser and fixed multiple bugs
This commit is contained in:
@@ -18,24 +18,39 @@ class Checks:
|
||||
try:
|
||||
self.custom_quality = float(custom_q)
|
||||
except ValueError:
|
||||
return False
|
||||
return True
|
||||
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
|
||||
else:
|
||||
print("invalid letter in custom quality multiplier!")
|
||||
return False
|
||||
if 4 >= self.custom_quality >= 1:
|
||||
print("quality selction ok")
|
||||
return True
|
||||
else:
|
||||
print("invalid range for multiplier!")
|
||||
|
||||
def file_checks(self, i_fp, o_fp):
|
||||
self.i_file_extension = str(i_fp)[len(i_fp) - 4:]
|
||||
if self.i_file_extension == ".png" or self.i_file_extension == ".jpg":
|
||||
pass
|
||||
print("file extensions ok (image)")
|
||||
elif self.i_file_extension == "jpeg":
|
||||
if str(i_fp)[len(i_fp) - 5:] == ".jpeg":
|
||||
pass
|
||||
print("file extensions ok (image)")
|
||||
else:
|
||||
return False
|
||||
elif self.i_file_extension == ".mp4" or self.i_file_extension == ".mkv":
|
||||
pass
|
||||
print("file extensions ok (video)")
|
||||
else:
|
||||
return False
|
||||
|
||||
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
|
||||
else:
|
||||
print("files don't have same extension!")
|
||||
return False
|
||||
|
||||
@@ -16,7 +16,7 @@ import time
|
||||
|
||||
# Loading the config file to get user preferred temp path
|
||||
config = configparser.ConfigParser()
|
||||
config.read('../config/settings.ini')
|
||||
config.read('./config/settings.ini')
|
||||
|
||||
|
||||
class Handler:
|
||||
@@ -29,12 +29,14 @@ class Handler:
|
||||
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
|
||||
if self.os_type == "linux":
|
||||
self.tmppath = "/tmp/fsru/" # config["PathSettings"]["tmpPathLinux"]
|
||||
self.tmppath = config["PathSettings"]["tmpPathLinux"]
|
||||
elif self.os_type == "win32":
|
||||
self.tmppath = config["PathSettings"]["tmpPathWindows"]
|
||||
else:
|
||||
print("OS CURRENTLY UNSUPPORTED!")
|
||||
return False
|
||||
self.tmppath += "fsru/"
|
||||
print(self.tmppath)
|
||||
# checking for spaces in filepath (for use with terminal commands)
|
||||
self.filepath = ""
|
||||
for self.letter in filepath:
|
||||
@@ -83,9 +85,14 @@ class Handler:
|
||||
# Retrieving Video metadata
|
||||
self.duration = self.videometa.get("duration")
|
||||
self.frames = self.videometa.get("nb_frames")
|
||||
self.framerate = round(float(self.frames) / float(self.duration), 1)
|
||||
try:
|
||||
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
|
||||
os.remove(self.tmppath)
|
||||
try:
|
||||
os.mkdir(self.tmppath)
|
||||
except FileExistsError:
|
||||
@@ -93,9 +100,9 @@ class Handler:
|
||||
|
||||
if self.os_type == "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":
|
||||
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:
|
||||
print("OS CURRENTLY UNSUPPORTED!")
|
||||
return False
|
||||
@@ -110,13 +117,12 @@ class Handler:
|
||||
self.number = 0
|
||||
for self.file in self.filelist:
|
||||
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.pos = 1
|
||||
|
||||
# Refactoring of commands that are longer than 32K characters
|
||||
if len(self.files) > self.maxlength:
|
||||
print("shrinking command length")
|
||||
self.fileout = []
|
||||
|
||||
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:])
|
||||
else:
|
||||
self.fileout.append(self.files)
|
||||
print("filepath assembled")
|
||||
|
||||
try:
|
||||
os.mkdir(f"{self.tmppath}upscaled/")
|
||||
@@ -185,7 +190,6 @@ class Handler:
|
||||
else:
|
||||
print("OS CURRENTLY UNSUPPORTED!")
|
||||
return False
|
||||
print(self.command, "\n\n\nCOMMAND to EXECUTE\n\n\n")
|
||||
os.system(self.command)
|
||||
print("Finished upscaling this section.")
|
||||
time.sleep(3)
|
||||
@@ -209,9 +213,9 @@ class Handler:
|
||||
# reassemble Video
|
||||
print("Reassembling Video... with framerate @", self.framerate)
|
||||
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":
|
||||
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:
|
||||
print("OS CURRENTLY UNSUPPORTED!")
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user