mirror of
https://github.com/k4yt3x/video2x.git
synced 2026-03-06 23:29:37 +08:00
all string formatting switched to f-string
This commit is contained in:
@@ -13,7 +13,7 @@ __ __ _ _ ___ __ __
|
||||
Name: Video2X Controller
|
||||
Author: K4YT3X
|
||||
Date Created: Feb 24, 2018
|
||||
Last Modified: April 11, 2019
|
||||
Last Modified: April 21, 2019
|
||||
|
||||
Licensed under the GNU General Public License Version 3 (GNU GPL v3),
|
||||
available at: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
@@ -80,7 +80,7 @@ def process_arguments():
|
||||
upscaler_options.add_argument('-d', '--driver', help='Waifu2x driver', action='store', default='waifu2x_caffe', choices=['waifu2x_caffe', 'waifu2x_converter'])
|
||||
upscaler_options.add_argument('-y', '--model_dir', help='Folder containing model JSON files', action='store')
|
||||
upscaler_options.add_argument('-t', '--threads', help='Number of threads to use for upscaling', action='store', type=int, default=5)
|
||||
upscaler_options.add_argument('-c', '--config', help='Video2X config file location', action='store', default='{}\\video2x.json'.format(os.path.dirname(os.path.abspath(sys.argv[0]))))
|
||||
upscaler_options.add_argument('-c', '--config', help='Video2X config file location', action='store', default=f'{os.path.dirname(os.path.abspath(sys.argv[0]))}\\video2x.json')
|
||||
upscaler_options.add_argument('-b', '--batch', help='Enable batch mode (select all default values to questions)', action='store_true')
|
||||
|
||||
# scaling options
|
||||
@@ -101,8 +101,8 @@ def print_logo():
|
||||
print(' \\ / | | | (_| | | __/ | (_) | / /_ / . \\')
|
||||
print(' \\/ |_| \\__,_| \\___| \\___/ |____| /_/ \\_\\')
|
||||
print('\n Video2X Video Enlarger')
|
||||
spaces = ((44 - len("Version {}".format(VERSION))) // 2) * " "
|
||||
print('{}\n{} Version {}\n{}'.format(Avalon.FM.BD, spaces, VERSION, Avalon.FM.RST))
|
||||
spaces = ((44 - len(f'Version {VERSION}')) // 2) * ' '
|
||||
print(f'{Avalon.FM.BD}\n{spaces} Version {VERSION}\n{Avalon.FM.RST}')
|
||||
|
||||
|
||||
def check_memory():
|
||||
@@ -141,17 +141,17 @@ def check_memory():
|
||||
|
||||
# if user doesn't even have enough memory to run even one thread
|
||||
if memory_available < mem_per_thread:
|
||||
Avalon.warning('You might have insufficient amount of {} memory available to run this program ({} GB)'.format(memory_type, memory_available))
|
||||
Avalon.warning(f'You might have insufficient amount of {memory_type} memory available to run this program ({memory_available} GB)')
|
||||
Avalon.warning('Proceed with caution')
|
||||
if args.threads > 1:
|
||||
if Avalon.ask('Reduce number of threads to avoid crashing?', default=True, batch=args.batch):
|
||||
args.threads = 1
|
||||
# if memory available is less than needed, warn the user
|
||||
elif memory_available < (mem_per_thread * args.threads):
|
||||
Avalon.warning('Each waifu2x-caffe thread will require up to 2.5 GB of system memory')
|
||||
Avalon.warning('You demanded {} threads to be created, but you only have {} GB {} memory available'.format(args.threads, round(memory_available, 4), memory_type))
|
||||
Avalon.warning('{} GB of {} memory is recommended for {} threads'.format(mem_per_thread * args.threads, memory_type, args.threads))
|
||||
Avalon.warning('With your current amount of {} memory available, {} threads is recommended'.format(memory_type, int(memory_available // mem_per_thread)))
|
||||
Avalon.warning(f'Each waifu2x-caffe thread will require up to {SYS_MEM_PER_THREAD} GB of system memory')
|
||||
Avalon.warning(f'You demanded {args.threads} threads to be created, but you only have {round(memory_available, 4)} GB {memory_type} memory available')
|
||||
Avalon.warning(f'{mem_per_thread * args.threads} GB of {memory_type} memory is recommended for {args.threads} threads')
|
||||
Avalon.warning(f'With your current amount of {memory_type} memory available, {int(memory_available // mem_per_thread)} threads is recommended')
|
||||
|
||||
# ask the user if he / she wants to change to the recommended
|
||||
# number of threads
|
||||
@@ -187,20 +187,20 @@ def absolutify_paths(config):
|
||||
|
||||
# check waifu2x-caffe path
|
||||
if not re.match('^[a-z]:', config['waifu2x_caffe']['waifu2x_caffe_path'], re.IGNORECASE):
|
||||
config['waifu2x_caffe']['waifu2x_caffe_path'] = '{}\\{}'.format(current_folder, config['waifu2x_caffe']['waifu2x_caffe_path'])
|
||||
config['waifu2x_caffe']['waifu2x_caffe_path'] = f'{current_folder}\\{config["waifu2x_caffe"]["waifu2x_caffe_path"]}'
|
||||
|
||||
# check waifu2x-converter-cpp path
|
||||
if not re.match('^[a-z]:', config['waifu2x_converter']['waifu2x_converter_path'], re.IGNORECASE):
|
||||
config['waifu2x_converter']['waifu2x_converter_path'] = '{}\\{}'.format(current_folder, config['waifu2x_converter']['waifu2x_converter_path'])
|
||||
config['waifu2x_converter']['waifu2x_converter_path'] = f'{current_folder}\\{config["waifu2x_converter"]["waifu2x_converter_path"]}'
|
||||
|
||||
# check ffmpeg path
|
||||
if not re.match('^[a-z]:', config['ffmpeg']['ffmpeg_path'], re.IGNORECASE):
|
||||
config['ffmpeg']['ffmpeg_path'] = '{}\\{}'.format(current_folder, config['ffmpeg']['ffmpeg_path'])
|
||||
config['ffmpeg']['ffmpeg_path'] = f'{current_folder}\\{config["ffmpeg"]["ffmpeg_path"]}'
|
||||
|
||||
# check video2x cache path
|
||||
if config['video2x']['video2x_cache_folder']:
|
||||
if not re.match('^[a-z]:', config['video2x']['video2x_cache_folder'], re.IGNORECASE):
|
||||
config['video2x']['video2x_cache_folder'] = '{}\\{}'.format(current_folder, config['video2x']['video2x_cache_folder'])
|
||||
config['video2x']['video2x_cache_folder'] = f'{current_folder}\\{config["video2x"]["video2x_cache_folder"]}'
|
||||
|
||||
return config
|
||||
|
||||
@@ -210,7 +210,7 @@ def absolutify_paths(config):
|
||||
# this is not a library
|
||||
if __name__ != '__main__':
|
||||
Avalon.error('This file cannot be imported')
|
||||
raise ImportError('{} cannot be imported'.format(__file__))
|
||||
raise ImportError(f'{__file__} cannot be imported')
|
||||
|
||||
print_logo()
|
||||
|
||||
@@ -262,16 +262,16 @@ preserve_frames = config['video2x']['preserve_frames']
|
||||
|
||||
# create temp directories if they don't exist
|
||||
if not video2x_cache_folder:
|
||||
video2x_cache_folder = '{}\\video2x'.format(tempfile.gettempdir())
|
||||
video2x_cache_folder = f'{tempfile.gettempdir()}\\video2x'
|
||||
|
||||
if video2x_cache_folder and not os.path.isdir(video2x_cache_folder):
|
||||
if not os.path.isfile(video2x_cache_folder) and not os.path.islink(video2x_cache_folder):
|
||||
Avalon.warning('Specified cache folder/directory {} does not exist'.format(video2x_cache_folder))
|
||||
Avalon.warning(f'Specified cache folder/directory {video2x_cache_folder} does not exist')
|
||||
if Avalon.ask('Create folder/directory?', default=True, batch=args.batch):
|
||||
if os.mkdir(video2x_cache_folder) is None:
|
||||
Avalon.info('{} created'.format(video2x_cache_folder))
|
||||
Avalon.info(f'{video2x_cache_folder} created')
|
||||
else:
|
||||
Avalon.error('Unable to create {}'.format(video2x_cache_folder))
|
||||
Avalon.error(f'Unable to create {video2x_cache_folder}')
|
||||
Avalon.error('Aborting...')
|
||||
exit(1)
|
||||
else:
|
||||
@@ -288,7 +288,7 @@ try:
|
||||
# if input specified is a single file
|
||||
if os.path.isfile(args.input):
|
||||
""" Upscale single video file """
|
||||
Avalon.info('Upscaling single video file: {}'.format(args.input))
|
||||
Avalon.info(f'Upscaling single video file: {args.input}')
|
||||
|
||||
# check for input output format mismatch
|
||||
if os.path.isdir(args.output):
|
||||
@@ -321,9 +321,9 @@ try:
|
||||
# if input specified is a folder
|
||||
elif os.path.isdir(args.input):
|
||||
""" Upscale videos in a folder/directory """
|
||||
Avalon.info('Upscaling videos in folder/directory: {}'.format(args.input))
|
||||
Avalon.info(f'Upscaling videos in folder/directory: {args.input}')
|
||||
for input_video in [f for f in os.listdir(args.input) if os.path.isfile(os.path.join(args.input, f))]:
|
||||
output_video = '{}\\{}'.format(args.output, input_video)
|
||||
output_video = f'{args.output}\\{input_video}'
|
||||
upscaler = Upscaler(input_video=os.path.join(args.input, input_video), output_video=output_video, method=args.method, waifu2x_settings=waifu2x_settings, ffmpeg_settings=ffmpeg_settings)
|
||||
|
||||
# set optional options
|
||||
@@ -343,13 +343,12 @@ try:
|
||||
upscaler.cleanup()
|
||||
else:
|
||||
Avalon.error('Input path is neither a file nor a folder/directory')
|
||||
raise FileNotFoundError('{} is neither file nor folder/directory'.format(args.input))
|
||||
raise FileNotFoundError(f'{args.input} is neither file nor folder/directory')
|
||||
|
||||
Avalon.info('Program completed, taking {} seconds'.format(round((time.time() - begin_time), 5)))
|
||||
Avalon.info(f'Program completed, taking {round((time.time() - begin_time), 5)} seconds')
|
||||
except Exception:
|
||||
Avalon.error('An exception has occurred')
|
||||
traceback.print_exc()
|
||||
Avalon.warning('If you experience error \"cudaSuccess out of memory\", try reducing number of threads you\'re using')
|
||||
finally:
|
||||
# remove Video2X Cache folder
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user