From c0f25383a6ad8f015a7182aeb1041925e52f7429 Mon Sep 17 00:00:00 2001 From: Dantenerosas Date: Tue, 26 Sep 2023 00:01:09 +0300 Subject: [PATCH] up fix to sitenotimplementedexception --- src/core/master_service.py | 8 +++++++- src/core/redis_client.py | 2 ++ src/web/main.py | 24 ++++++++++++++++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/core/master_service.py b/src/core/master_service.py index 0fd0b56..aabd460 100644 --- a/src/core/master_service.py +++ b/src/core/master_service.py @@ -78,6 +78,7 @@ class MasterService: parser_mapping = { "my.mail.ru": MyMailParser(params), "www.youtube.com": BaseParser(params), + "youtu.be": BaseParser(params), "vk.com": BaseParser(params), "ok.ru": BaseParser(params), "likee.video": BaseParser(params), @@ -98,13 +99,18 @@ class MasterService: "status": "done" }) except FileAlreadyExistException as ex: + # TODO: сделать так, чтобы грузился обычный, нам не нужно записывать что-то в редис return Result(result_type=ResultTypeEnum.EXIST, value={ "link": video_params["link"], "result": ex.message, "status": "exist" }) except SiteNotImplementedException as ex: - return Result(result_type=ResultTypeEnum.EXCEPTION, value=ex.default_message) + return Result(result_type=ResultTypeEnum.EXCEPTION, value={ + "link": video_params["link"], + "result": ex.default_message, + "status": "error" + }) # TODO upload to server diff --git a/src/core/redis_client.py b/src/core/redis_client.py index fa608b3..0ca8ad3 100644 --- a/src/core/redis_client.py +++ b/src/core/redis_client.py @@ -7,6 +7,8 @@ class RedisClient: SET_NAME = "queue" TASKS_NAME = "tasks_working" TASKS_DONE_NAME = "tasks_done" + + # TODO: переписать всё вазимодействие редиса обратно на ключ-значение def __init__(self): self.connection = redis.Redis(host="localhost", port=6379, db=0) diff --git a/src/web/main.py b/src/web/main.py index 593230f..90db6c2 100644 --- a/src/web/main.py +++ b/src/web/main.py @@ -45,13 +45,29 @@ app.add_middleware( TypeError: string indices must be integers ''' +''' +queue_name -> [ + "{link...}", + "{link2...}", + "{link3..}" +] + +queue_name -> { + "link1" -> {vars}, + "link2" -> {vars}, + "link3" -> {vars}, +} +''' + + async def is_task_already_done_or_exist(redis: RedisClient, link: str): messages = await redis.get_task_done_queue() - + temp = [json.loads(msg) for msg in messages] + print(temp) tasks = [ - literal_eval(message.decode('utf-8')) for message in messages - if literal_eval(message.decode('utf-8'))["link"] == link - and literal_eval(message.decode('utf-8'))["status"] in ["done", "exist"] + msg for msg in temp + if msg["link"] == link + and msg["status"] in ["done", "exist"] ] if len(tasks) > 0: