From 0f68ef558ea15d42c619f9eb4df0e3bae4f0d354 Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Thu, 17 Mar 2022 01:50:19 +0100 Subject: [PATCH] exit if results list is empty (or is cleared during filtering) --- mvw-dl.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mvw-dl.py b/mvw-dl.py index 9762924..49d91e8 100644 --- a/mvw-dl.py +++ b/mvw-dl.py @@ -29,6 +29,7 @@ JSONType = t.Union[str, int, float, bool, None, t.Dict[str, t.Any], t.List[t.Any # Exit codes # 1: Config file invalid, it has no sections # 2: Config file invalid, sections must define at least CONST.CFG_MANDATORY +# 3: No search results to download class CONST(object): @@ -204,12 +205,20 @@ def get_json_response( return got_json_response +def no_downloads_needed() -> None: + log.info(f"No search results to download, exiting 3 ...") + sys.exit(3) + + def remove_result( json_obj: MVWJSONResponse, result_obj: type_def.mvw_json_response.Show) -> MVWJSONResponse: json_obj.result.results.remove(result_obj) json_obj.result.queryInfo.resultCount -= 1 - return json_obj + if json_obj.result.queryInfo.resultCount: + return json_obj + else: + no_downloads_needed() def log_result_count(result_count: int, pre_filter: bool = True) -> None: @@ -309,4 +318,9 @@ if __name__ == '__main__': log.debug(f"Deduplicating results by title where needed ...") if config.has_option(section, "title_not_regex"): json_response = dedup_json_titles(section, config, json_response) - # console.print_json(json_response.json()) + + #if json_response.result.queryInfo.resultCount: + # log.debug(f"Downloading shows ...") + #else + # + # # console.print_json(json_response.json())