Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.3.3-alpha #22

Merged
merged 6 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
readme = "README.md"
Expand Down
12 changes: 7 additions & 5 deletions ygg_rss_proxy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ygg_rss_proxy/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion ygg_rss_proxy/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions ygg_rss_proxy/torrent.py
Original file line number Diff line number Diff line change
@@ -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
Loading