From 0e82b0591ffb81d95844f2e77fd4f8b963058971 Mon Sep 17 00:00:00 2001 From: Taras Terletskyi <888784+tropicoo@users.noreply.github.com> Date: Wed, 4 Oct 2023 20:46:39 +0300 Subject: [PATCH] Fix #185 --- .editorconfig | 6 ++++-- app_bot/bot/core/service.py | 3 ++- app_worker/ytdl_opts/per_host/_registry.py | 9 +++++---- yt_shared/yt_shared/constants.py | 13 ++++++++++--- yt_shared/yt_shared/schemas/url.py | 2 +- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/.editorconfig b/.editorconfig index 87af0d6..815aa06 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,17 +3,19 @@ # top-most EditorConfig file root = true -# Unix-style newlines with a newline ending every file [*] end_of_line = lf insert_final_newline = true -# 4 space indentation [*.py] charset = utf-8 indent_style = space indent_size = 4 max_line_length = 88 +[*.json] +indent_style = space +indent_size = 4 + [Makefile] indent_style = space diff --git a/app_bot/bot/core/service.py b/app_bot/bot/core/service.py index d7fdc5b..412ec97 100644 --- a/app_bot/bot/core/service.py +++ b/app_bot/bot/core/service.py @@ -62,13 +62,14 @@ class UrlParser: message: Message = context['message'] user: UserSchema = context['user'] ack_message: Message = context['ack_message'] + from_user_id = message.from_user.id if message.from_user else None return [ URL( url=url, original_url=orig_url, from_chat_id=message.chat.id, from_chat_type=TelegramChatType(message.chat.type.value), - from_user_id=message.from_user.id, + from_user_id=from_user_id, message_id=message.id, ack_message_id=ack_message.id, save_to_storage=user.save_to_storage, diff --git a/app_worker/ytdl_opts/per_host/_registry.py b/app_worker/ytdl_opts/per_host/_registry.py index dc5c7b6..4257d62 100644 --- a/app_worker/ytdl_opts/per_host/_registry.py +++ b/app_worker/ytdl_opts/per_host/_registry.py @@ -5,7 +5,7 @@ from ytdl_opts.per_host._base import AbstractHostConfig class HostConfRegistry(type): REGISTRY: dict[str, type[AbstractHostConfig]] = {} - HOST_TO_CLS_MAP = {} + HOST_TO_CLS_MAP: dict[str | None, type[AbstractHostConfig]] = {} def __new__( mcs: Type['HostConfRegistry'], @@ -33,6 +33,7 @@ class HostConfRegistry(type): ) -> None: if hostnames is None: mcs.HOST_TO_CLS_MAP[None] = host_cls - else: - for host in hostnames: - mcs.HOST_TO_CLS_MAP[host] = host_cls + return + + for host in hostnames: + mcs.HOST_TO_CLS_MAP[host] = host_cls diff --git a/yt_shared/yt_shared/constants.py b/yt_shared/yt_shared/constants.py index 4f967aa..5c1153c 100644 --- a/yt_shared/yt_shared/constants.py +++ b/yt_shared/yt_shared/constants.py @@ -3,8 +3,16 @@ from asyncio import Lock ASYNC_LOCK = Lock() -INSTAGRAM_HOSTS = ('instagram.com', 'www.instagram.com') -TIKTOK_HOSTS = ('tiktok.com', 'vm.tiktok.com', 'www.tiktok.com', 'www.vm.tiktok.com') +INSTAGRAM_HOSTS = ( + 'instagram.com', + 'www.instagram.com', +) +TIKTOK_HOSTS = ( + 'tiktok.com', + 'vm.tiktok.com', + 'www.tiktok.com', + 'www.vm.tiktok.com', +) TWITTER_HOSTS = ( 'twitter.com', 'www.twitter.com', @@ -14,5 +22,4 @@ TWITTER_HOSTS = ( 'www.t.co', ) - REMOVE_QUERY_PARAMS_HOSTS = TWITTER_HOSTS + INSTAGRAM_HOSTS diff --git a/yt_shared/yt_shared/schemas/url.py b/yt_shared/yt_shared/schemas/url.py index 1fa29ed..52bd627 100644 --- a/yt_shared/yt_shared/schemas/url.py +++ b/yt_shared/yt_shared/schemas/url.py @@ -9,7 +9,7 @@ class URL(RealBaseModel): original_url: StrictStr from_chat_id: StrictInt from_chat_type: TelegramChatType - from_user_id: StrictInt + from_user_id: StrictInt | None message_id: StrictInt ack_message_id: StrictInt save_to_storage: StrictBool