From c8ddb67b336c8de7803dd8892fb782497141be09 Mon Sep 17 00:00:00 2001 From: Kyrch Date: Wed, 2 Aug 2023 10:56:00 -0300 Subject: [PATCH] bypassing cancellations --- beta_batch_encoder/_interface.py | 36 +++++++++++++++++++++++---- beta_batch_encoder/_seek_collector.py | 6 ++--- setup.py | 2 +- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/beta_batch_encoder/_interface.py b/beta_batch_encoder/_interface.py index ec9beb6..16f81a5 100644 --- a/beta_batch_encoder/_interface.py +++ b/beta_batch_encoder/_interface.py @@ -1,6 +1,7 @@ import inquirer import logging import re +import sys class Interface: # Time Duration Specification: https://ffmpeg.org/ffmpeg-utils.html#time-duration-syntax @@ -16,15 +17,21 @@ class Interface: question = [inquirer.Text('text', message=message, validate=validate)] answer = inquirer.prompt(question) + if answer is None: + return 'NoName' + logging.debug(f'[Interface.prompt_text] answer["text"]: \'{answer["text"]}\'') return answer['text'] # Prompt the user for time questions - def prompt_time(message): - question = [inquirer.Text('time', message=message, validate=Interface.validate_time)] + def prompt_time(message, validate=validate_time): + question = [inquirer.Text('time', message=message, validate=validate)] answer = inquirer.prompt(question) + if answer is None: + return '' + logging.debug(f'[Interface.prompt_time] answer["time"]: \'{answer["time"]}\'') return answer['time'] @@ -35,6 +42,9 @@ class Interface: question = [inquirer.List('mode', message='Mode (Enter)', choices=modes)] answer = inquirer.prompt(question) + if answer is None: + sys.exit() + logging.debug(f'[Interface.choose_mode] answer["mode"]: \'{answer["mode"]}\'') return answer['mode'] @@ -44,6 +54,13 @@ class Interface: question = [inquirer.Checkbox('source_files', message='Source Files (Space to select)', choices=source_files)] answer = inquirer.prompt(question) + if answer is None: + sys.exit() + + if len(answer['source_files']) == 0: + logging.error('Select at least one file') + sys.exit() + logging.debug(f'[Interface.choose_source_files] answer["source_files"]: \'{answer["source_files"]}\'') return answer['source_files'] @@ -69,7 +86,10 @@ class Interface: question = [inquirer.List('audio_filters', message='Audio Filters (Enter)', choices=list(audio_filters.keys()))] answer = inquirer.prompt(question) - if answer['audio_filters'] == 'Fade In': + if answer is None: + audio_filters['Exit'] = True + + elif answer['audio_filters'] == 'Fade In': audio_filters['Fade In'] = Interface.prompt_time('Exponential Value').strip() or '0' elif answer['audio_filters'] == 'Fade Out': @@ -113,7 +133,7 @@ class Interface: # Prompt the user for our list of video filters def video_filters(encoding_config): video_filters_options = { - 'No Filters': 'no-vf', + 'No Filters': None, 'scale=-1:720': '720p', 'scale=-1:720,hqdn3d=0:0:3:3,gradfun,unsharp': 'filtered-720p', 'hqdn3d=0:0:3:3,gradfun,unsharp': 'filtered', @@ -124,12 +144,15 @@ class Interface: } if encoding_config.include_unfiltered: - encoding_config.video_filters.append(('no-vf', 'No Filters')) + encoding_config.video_filters.append((None, 'No Filters')) question = [inquirer.Checkbox('video_filters', message='Select Video Filters (Space to select)', choices=video_filters_options.keys(), default=[tp[1] for tp in encoding_config.video_filters])] answer = inquirer.prompt(question) + if answer is None: + return encoding_config + tp_list = [(name, filter_string) for filter_string, name in video_filters_options.items() if filter_string in answer['video_filters']] if 'Custom' in answer['video_filters']: @@ -159,6 +182,9 @@ class Interface: answer = inquirer.prompt(questions) + if answer is None: + return encoding_config + encoding_config.create_preview = answer['create_preview'] encoding_config.limit_size_enable = answer['limit_size_enable'] encoding_config.crfs = answer['crfs'].split(',') diff --git a/beta_batch_encoder/_seek_collector.py b/beta_batch_encoder/_seek_collector.py index c9411a7..86df786 100644 --- a/beta_batch_encoder/_seek_collector.py +++ b/beta_batch_encoder/_seek_collector.py @@ -27,8 +27,8 @@ class SeekCollector: and SeekCollector.start_positions in [len(x.split(',')), 0] validate_output_name = lambda _, x: \ - len(x.strip()) == 0 \ - or all(SeekCollector.filename_pattern.match(y) and not y.strip() in SeekCollector.all_output_names for y in x.split(',')) \ + len(x.strip()) > 0 \ + and all(SeekCollector.filename_pattern.match(y) and not y.strip() in SeekCollector.all_output_names for y in x.split(',')) \ and SeekCollector.start_positions == len(x.split(',')) def __init__(self, source_file): @@ -43,7 +43,7 @@ class SeekCollector: # For ending positions, a blank input value is the end position of the source file @staticmethod def prompt_time(prompt_text): - positions = Interface.prompt_text(prompt_text, validate=SeekCollector.validate_seek).split(',') + positions = Interface.prompt_time(prompt_text, validate=SeekCollector.validate_seek).split(',') if prompt_text == 'Start time(s)': SeekCollector.start_positions = len(positions) diff --git a/setup.py b/setup.py index 8a2ccc8..db4ef36 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open('README.md') as f: setup( name='animethemes-beta-batch-encoder', - version='1.4', + version='1.4.1', author='AnimeThemes', author_email='admin@animethemes.moe', url='https://github.com/AnimeThemes/animethemes-batch-encoder',