mirror of
https://github.com/k4yt3x/video2x.git
synced 2025-01-04 04:39:10 +00:00
using contextlib instead of try-catch
This commit is contained in:
parent
6521e071ce
commit
e10315f89e
@ -4,7 +4,7 @@
|
|||||||
Name: Video2X Upscaler
|
Name: Video2X Upscaler
|
||||||
Author: K4YT3X
|
Author: K4YT3X
|
||||||
Date Created: December 10, 2018
|
Date Created: December 10, 2018
|
||||||
Last Modified: August 15, 2019
|
Last Modified: August 21, 2019
|
||||||
|
|
||||||
Dev: SAT3LL
|
Dev: SAT3LL
|
||||||
|
|
||||||
@ -25,6 +25,7 @@ from waifu2x_ncnn_vulkan import Waifu2xNcnnVulkan
|
|||||||
|
|
||||||
# built-in imports
|
# built-in imports
|
||||||
from fractions import Fraction
|
from fractions import Fraction
|
||||||
|
import contextlib
|
||||||
import copy
|
import copy
|
||||||
import pathlib
|
import pathlib
|
||||||
import re
|
import re
|
||||||
@ -125,7 +126,7 @@ class Upscaler:
|
|||||||
previous_cycle_frames = 0
|
previous_cycle_frames = 0
|
||||||
while not self.progress_bar_exit_signal:
|
while not self.progress_bar_exit_signal:
|
||||||
|
|
||||||
try:
|
with contextlib.suppress(FileNotFoundError):
|
||||||
self.total_frames_upscaled = len([f for f in self.upscaled_frames.iterdir() if str(f)[-4:] == f'.{self.image_format}'])
|
self.total_frames_upscaled = len([f for f in self.upscaled_frames.iterdir() if str(f)[-4:] == f'.{self.image_format}'])
|
||||||
delta = self.total_frames_upscaled - previous_cycle_frames
|
delta = self.total_frames_upscaled - previous_cycle_frames
|
||||||
previous_cycle_frames = self.total_frames_upscaled
|
previous_cycle_frames = self.total_frames_upscaled
|
||||||
@ -136,8 +137,6 @@ class Upscaler:
|
|||||||
|
|
||||||
# adds the delta into the progress bar
|
# adds the delta into the progress bar
|
||||||
progress_bar.update(delta)
|
progress_bar.update(delta)
|
||||||
except FileNotFoundError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ Installation Details:
|
|||||||
|
|
||||||
# built-in imports
|
# built-in imports
|
||||||
import argparse
|
import argparse
|
||||||
|
import contextlib
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
@ -274,10 +275,8 @@ def download(url, save_path, chunk_size=4096):
|
|||||||
file_name = None
|
file_name = None
|
||||||
if 'content-disposition' in stream.headers:
|
if 'content-disposition' in stream.headers:
|
||||||
disposition = stream.headers['content-disposition']
|
disposition = stream.headers['content-disposition']
|
||||||
try:
|
with contextlib.suppress(IndexError):
|
||||||
file_name = re.findall("filename=(.+)", disposition)[0].strip('"')
|
file_name = re.findall("filename=(.+)", disposition)[0].strip('"')
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if file_name is None:
|
if file_name is None:
|
||||||
# output_file = f'{save_path}\\{stream.url.split("/")[-1]}'
|
# output_file = f'{save_path}\\{stream.url.split("/")[-1]}'
|
||||||
|
Loading…
Reference in New Issue
Block a user