From d26d31635fc401b8d3079643c9daee760e76ac0b Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Wed, 26 Apr 2023 12:16:16 +0800 Subject: [PATCH] Add local proxy --- src/module/api.py | 11 ++++++++--- src/module/conf/__init__.py | 6 +++++- src/module/core/api_func.py | 11 +++++++---- src/module/manager/eps_complete.py | 4 ++-- src/module/network/notification.py | 2 -- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/module/api.py b/src/module/api.py index b3e73020..5a1e8f2d 100644 --- a/src/module/api.py +++ b/src/module/api.py @@ -80,9 +80,14 @@ async def update_config(config: Config): return api_func.update_config(config) -@router.get("/RSS/MyBangumi") -async def get_rss(token: str): - content = api_func.get_rss(token) +@router.get("/RSS/{full_path:path}") +async def get_rss(full_path: str, token: str = None, searchstr: str = None): + if token is not None: + full_path = full_path + "?token=" + token + if searchstr is not None: + full_path = full_path + "?searchstr=" + searchstr + content = api_func.get_rss(full_path) + print(full_path) return Response(content, media_type="application/xml") diff --git a/src/module/conf/__init__.py b/src/module/conf/__init__.py index c716bbd8..1afbfad9 100644 --- a/src/module/conf/__init__.py +++ b/src/module/conf/__init__.py @@ -1,6 +1,8 @@ from .log import setup_logger, LOG_PATH from .config import settings, VERSION +import re + TMDB_API = "32b19d6a05b512190a056fa4e747cbbc" DATA_PATH = "data/data.json" @@ -8,4 +10,6 @@ DATA_PATH = "data/data.json" class RSSLink(str): def __new__(cls): - return f"https://{settings.rss_parser.custom_url}/RSS/MyBangumi?token={settings.rss_parser.token}" \ No newline at end of file + if "://" not in settings.rss_parser.custom_url: + return f"https://{settings.rss_parser.custom_url}/RSS/MyBangumi?token={settings.rss_parser.token}" + return f"{settings.rss_parser.custom_url}/RSS/MyBangumi?token={settings.rss_parser.token}" diff --git a/src/module/core/api_func.py b/src/module/core/api_func.py index 2a4e7589..1ac3cc06 100644 --- a/src/module/core/api_func.py +++ b/src/module/core/api_func.py @@ -85,14 +85,17 @@ class APIProcess: return json_config.load(CONFIG_PATH) @staticmethod - def get_rss(token: str): - url = f"https://mikanani.me/RSS/MyBangumi?token={token}" + def get_rss(full_path: str): + url = f"https://mikanani.me/RSS/{full_path}" + custom_url = settings.rss_parser.custom_url + if "://" not in custom_url: + custom_url = f"https://{custom_url}" with RequestContent() as request: content = request.get_html(url) - return re.sub(r"mikanani.me", settings.rss_parser.custom_url, content) + return re.sub(r"https://mikanani.me", custom_url, content) @staticmethod def get_torrent(full_path): - url = f"https://mikanani.me/Downloads/{full_path}" + url = f"https://mikanani.me/Download/{full_path}" with RequestContent() as request: return request.get_content(url) diff --git a/src/module/manager/eps_complete.py b/src/module/manager/eps_complete.py index 4ede11a1..3e9105e4 100644 --- a/src/module/manager/eps_complete.py +++ b/src/module/manager/eps_complete.py @@ -9,7 +9,7 @@ from module.core.download_client import DownloadClient logger = logging.getLogger(__name__) SEARCH_KEY = ["group", "title_raw", "season_raw", "subtitle", "source", "dpi"] -CUSTOM_URL = "mikanani.me" if settings.rss_parser.custom_url == "" else settings.rss_parser.custom_url +CUSTOM_URL = "https://mikanani.me" if settings.rss_parser.custom_url == "" else settings.rss_parser.custom_url class FullSeasonGet: @@ -26,7 +26,7 @@ class FullSeasonGet: def get_season_torrents(self, data: dict): keyword = self.init_eps_complete_search_str(data) with RequestContent() as req: - torrents = req.get_torrents(f"https://{CUSTOM_URL}/RSS/Search?searchstr={keyword}") + torrents = req.get_torrents(f"{CUSTOM_URL}/RSS/Search?searchstr={keyword}") return torrents @staticmethod diff --git a/src/module/network/notification.py b/src/module/network/notification.py index edb7103a..10e6c5b6 100644 --- a/src/module/network/notification.py +++ b/src/module/network/notification.py @@ -9,8 +9,6 @@ logger = logging.getLogger(__name__) class PostNotification: def __init__(self): - self.token = settings.notification_token - self.notification_url = lambda message: f"https://api.pushbullet.com/v2/{self.token}/{message}" self.client = self.getClient() @staticmethod