From 8dd6a53e772b897c164e27eca4e470573b30422a Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Thu, 5 Oct 2023 11:17:17 +0800 Subject: [PATCH 1/3] fix: notification error. --- backend/src/module/checker/checker.py | 1 - backend/src/module/network/request_contents.py | 2 +- backend/src/module/notification/plugin/telegram.py | 2 +- backend/src/module/utils/cache_image.py | 7 +++++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/src/module/checker/checker.py b/backend/src/module/checker/checker.py index e827102a..d78ad3cd 100644 --- a/backend/src/module/checker/checker.py +++ b/backend/src/module/checker/checker.py @@ -78,7 +78,6 @@ class Checker: @staticmethod def check_img_cache() -> bool: img_path = Path("data/posters") - # If poster folder is not empty, return True if img_path.exists(): return True else: diff --git a/backend/src/module/network/request_contents.py b/backend/src/module/network/request_contents.py index 2eff2276..05abca02 100644 --- a/backend/src/module/network/request_contents.py +++ b/backend/src/module/network/request_contents.py @@ -55,7 +55,7 @@ class RequestContent(RequestURL): def post_data(self, _url, data: dict) -> dict: return self.post_url(_url, data) - def post_form(self, _url, data: dict, files: dict) -> dict: + def post_files(self, _url, data: dict, files: dict) -> dict: return self.post_form(_url, data, files) def get_html(self, _url): diff --git a/backend/src/module/notification/plugin/telegram.py b/backend/src/module/notification/plugin/telegram.py index dbd0c962..6f22056b 100644 --- a/backend/src/module/notification/plugin/telegram.py +++ b/backend/src/module/notification/plugin/telegram.py @@ -29,7 +29,7 @@ class TelegramNotification(RequestContent): } photo = load_image(notify.poster_path) if photo: - resp = self.post_form( + resp = self.post_files( self.notification_url, data, files={"photo": photo} ) else: diff --git a/backend/src/module/utils/cache_image.py b/backend/src/module/utils/cache_image.py index 2ff8e553..54c98d98 100644 --- a/backend/src/module/utils/cache_image.py +++ b/backend/src/module/utils/cache_image.py @@ -10,5 +10,8 @@ def save_image(img, suffix): def load_image(img_path): - with open(f"data/{img_path}", "rb") as f: - return f.read() + if img_path: + with open(f"data/{img_path}", "rb") as f: + return f.read() + else: + return None From b63a08a5b3f95ba0b7b39007c592e4276cf0f0f7 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Thu, 5 Oct 2023 15:02:35 +0800 Subject: [PATCH 2/3] fix: parser error. --- backend/src/module/parser/analyser/raw_parser.py | 9 +++++---- backend/src/test/test_raw_parser.py | 9 +++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/backend/src/module/parser/analyser/raw_parser.py b/backend/src/module/parser/analyser/raw_parser.py index 5de06089..3f28197b 100644 --- a/backend/src/module/parser/analyser/raw_parser.py +++ b/backend/src/module/parser/analyser/raw_parser.py @@ -94,10 +94,11 @@ def name_process(name: str): split = re.split("-", name) if len(split) == 1: split_space = split[0].split(" ") - for idx, item in enumerate(split_space): - if re.search(r"^[\u4e00-\u9fa5]{2,}", item) is not None: - split_space.remove(item) - split = [item.strip(), " ".join(split_space).strip()] + for idx in [0, -1]: + if re.search(r"^[\u4e00-\u9fa5]{2,}", split_space[idx]) is not None: + chs = split_space[idx] + split_space.remove(chs) + split = [chs, " ".join(split_space)] break for item in split: if re.search(r"[\u0800-\u4e00]{2,}", item) and not name_jp: diff --git a/backend/src/test/test_raw_parser.py b/backend/src/test/test_raw_parser.py index e157affb..574f38a5 100644 --- a/backend/src/test/test_raw_parser.py +++ b/backend/src/test/test_raw_parser.py @@ -79,4 +79,13 @@ def test_raw_parser(): assert info.episode == 13 assert info.season == 1 + content = "[ANi] 16bit 的感动 ANOTHER LAYER - 01 [1080P][Baha][WEB-DL][AAC AVC][CHT][MP4]" + info = raw_parser(content) + assert info.group == "ANi" + assert info.title_zh == "16bit 的感动 ANOTHER LAYER" + assert info.resolution == "1080P" + assert info.episode == 1 + assert info.season == 1 + + From 664a121092aec146283b2b1309aa601f79635a96 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Thu, 5 Oct 2023 15:03:50 +0800 Subject: [PATCH 3/3] fix: telegram photo error. --- backend/src/module/notification/plugin/telegram.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/src/module/notification/plugin/telegram.py b/backend/src/module/notification/plugin/telegram.py index 6f22056b..ac35623d 100644 --- a/backend/src/module/notification/plugin/telegram.py +++ b/backend/src/module/notification/plugin/telegram.py @@ -10,7 +10,8 @@ logger = logging.getLogger(__name__) class TelegramNotification(RequestContent): def __init__(self, token, chat_id): super().__init__() - self.notification_url = f"https://api.telegram.org/bot{token}/sendPhoto" + self.photo_url = f"https://api.telegram.org/bot{token}/sendPhoto" + self.message_url = f"https://api.telegram.org/bot{token}/sendMessage" self.chat_id = chat_id @staticmethod @@ -30,9 +31,9 @@ class TelegramNotification(RequestContent): photo = load_image(notify.poster_path) if photo: resp = self.post_files( - self.notification_url, data, files={"photo": photo} + self.photo_url, data, files={"photo": photo} ) else: - resp = self.post_data(self.notification_url, data) + resp = self.post_data(self.message_url, data) logger.debug(f"Telegram notification: {resp.status_code}") return resp.status_code == 200