diff --git a/pyproject.toml b/pyproject.toml index 525758f..784a94c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ygg-rss-proxy" -version = "1.3.0-alpha" +version = "v1.3.3-alpha" description = "Proxy for yggtorrent rss feeds" authors = ["LimeDrive "] readme = "README.md" diff --git a/ygg_rss_proxy/app.py b/ygg_rss_proxy/app.py index 7085ebc..a6b2e92 100644 --- a/ygg_rss_proxy/app.py +++ b/ygg_rss_proxy/app.py @@ -5,6 +5,7 @@ from ygg_rss_proxy.rss import get_rss_feed, replace_torrent_links from ygg_rss_proxy.settings import settings from ygg_rss_proxy.logging_config import logger +from ygg_rss_proxy.torrent import dwl_torrent from ygg_rss_proxy.session_manager import ( save_session, get_session, @@ -29,8 +30,6 @@ db = SQLAlchemy(app) app.config["SESSION_SQLALCHEMY"] = db -URL_TORRENTS = f"{settings.ygg_url}/rss/download" -URL_PROXY = f"{settings.rss_shema}://{settings.rss_host}:{settings.rss_port}" Session(app) @@ -68,10 +67,13 @@ def proxy_rss(): @app.route("/torrent", methods=["GET"]) def proxy_torrent(): - torrent_url = request.url.replace(f"{URL_PROXY}/torrent", URL_TORRENTS) + query_params = request.query_string.decode("utf-8") ygg_session = get_session() - response = ygg_session.get(torrent_url) + try: + response = dwl_torrent(query_params, requests_session=ygg_session) + except TimeoutError as e: + logger.error(f"Timeout Err: {e}") if response.status_code in [ 401, @@ -82,7 +84,7 @@ def proxy_torrent(): logger.debug(f"Response status : {response.status_code}") logger.info("Session may have expired, re-authenticating...") ygg_session = new_session() - response = ygg_session.get(torrent_url) + response = dwl_torrent(query_params, requests_session=ygg_session) if response.status_code == 200: save_session(ygg_session) diff --git a/ygg_rss_proxy/auth.py b/ygg_rss_proxy/auth.py index ed00f55..bc46505 100644 --- a/ygg_rss_proxy/auth.py +++ b/ygg_rss_proxy/auth.py @@ -135,13 +135,13 @@ def ygg_cloudflare_login( @retry( - stop=stop_after_attempt(3), + stop=stop_after_attempt(2), wait=wait_fixed(0.3), retry_error_callback=lambda retry_state: Exception( "Failed to connect to YGG after retries" ), ) -@timeout_decorator.timeout(90, exception_message=f"Timeout after 90 seconds") +@timeout_decorator.timeout(60, exception_message=f"Timeout after 60 seconds") def ygg_login( session=requests.Session(), ygg_playload: dict = ygg_playload ) -> requests.Session: diff --git a/ygg_rss_proxy/settings.py b/ygg_rss_proxy/settings.py index 7b41710..69f8aca 100644 --- a/ygg_rss_proxy/settings.py +++ b/ygg_rss_proxy/settings.py @@ -36,7 +36,7 @@ class Settings(BaseSettings): gunicorn_workers: int = 4 gunicorn_port: int = 8080 gunicorn_binder: str = "0.0.0.0" - gunicorn_timeout: int = 120 + gunicorn_timeout: int = 180 # LOGGING log_level: LogLevel = LogLevel.INFO diff --git a/ygg_rss_proxy/torrent.py b/ygg_rss_proxy/torrent.py new file mode 100644 index 0000000..63f4165 --- /dev/null +++ b/ygg_rss_proxy/torrent.py @@ -0,0 +1,16 @@ +from typing import Any +from lxml import etree +from ygg_rss_proxy.settings import settings +import requests +import timeout_decorator + +URL_DWL: str = f"{settings.ygg_url}/rss/download" + + +@timeout_decorator.timeout(60, exception_message=f"Timeout after 60 seconds") +def dwl_torrent( + query_params: str, requests_session: requests.Session +) -> requests.Response: + rss_url_with_params = f"{URL_DWL}?{query_params}" + response = requests_session.get(rss_url_with_params) + return response