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 2782c493..a6a52bde 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 @@ -29,10 +30,10 @@ class TelegramNotification(RequestContent): } photo = load_image(notify.poster_path) if photo: - resp = self.post_form( - self.notification_url, data, files={"photo": photo} + resp = self.post_files( + 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 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/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 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 + +