This commit is contained in:
Michel Roux 2022-12-22 00:01:21 +00:00
parent 910cc4e692
commit dbb7586496
10 changed files with 42 additions and 17 deletions

View File

@ -0,0 +1,2 @@
def run():
print("oui")

View File

@ -5,6 +5,8 @@ from bs4 import BeautifulSoup
import dateparser
from pydantic import HttpUrl, parse_obj_as
from pynyaata.cache import cache_data
from pynyaata.filters import filter_data
from pynyaata.types import Bridge, Color, RemoteFile
import requests
@ -31,6 +33,8 @@ class AnimeUltime(Bridge):
),
)
@cache_data
@filter_data
def search(self, query: str = "", page: int = 1) -> List[RemoteFile]:
response = (
requests.post(self.search_url(query, page), {"search": query})
@ -59,6 +63,7 @@ class AnimeUltime(Bridge):
torrents.append(
RemoteFile(
bridge=self.__class__.__name__,
id=tds[0].a["href"].split("/")[1].split("-")[0],
category=tds[1].get_text(),
name=tds[0].get_text(),
@ -77,6 +82,7 @@ class AnimeUltime(Bridge):
torrents.append(
RemoteFile(
bridge=self.__class__.__name__,
id=tds[0].a["href"].split("/")[-2],
category=tds[4].get_text(),
name=tds[0].get_text(),
@ -89,6 +95,7 @@ class AnimeUltime(Bridge):
elif player and title and history and tables:
torrents.append(
RemoteFile(
bridge=self.__class__.__name__,
id=player["data-serie"],
category=title.get_text(),
name=history.get_text(),

View File

@ -1,4 +1,5 @@
from datetime import datetime
from os import getenv
from typing import List
from urllib.parse import urlencode
@ -6,12 +7,15 @@ from bs4 import BeautifulSoup
from pydantic import HttpUrl, parse_obj_as
from pynyaata.cache import cache_data
from pynyaata.constants import VF_WORDS
from pynyaata.filters import filter_data
from pynyaata.types import Bridge, Color, RemoteFile
import requests
VF_WORDS = getenv("VF_WORDS", "vf,vostfr,multi,fre").split(",")
class Nyaa(Bridge):
color = Color.INFO
title = "Nyaa"
@ -34,6 +38,7 @@ class Nyaa(Bridge):
return parse_obj_as(HttpUrl, f"{self.base_url}?{params}")
@cache_data
@filter_data
def search(self, query: str = "", page: int = 1) -> List[RemoteFile]:
response = requests.get(self.search_url(query, page))
@ -54,6 +59,7 @@ class Nyaa(Bridge):
torrents.append(
RemoteFile(
bridge=self.__class__.__name__,
id=urls[1 if len(urls) > 1 else 0]["href"].split("/")[-1],
category=tds[0].a["title"],
color=Color[tr["class"][0].upper()],

View File

@ -1,15 +1,19 @@
import logging
from functools import wraps
from os import environ
from os import getenv
from typing import Optional
from pynyaata.cache.simple import SimpleCache
from pynyaata.types import Cache
from redis import RedisError
CACHE_TIMEOUT = int(environ.get("CACHE_TIMEOUT", 60 * 60))
REDIS_URL = environ.get("REDIS_URL", "")
CACHE_TIMEOUT = int(getenv("CACHE_TIMEOUT", 60 * 60))
REDIS_URL: Optional[str] = getenv("REDIS_URL")
client: Cache = SimpleCache()
if REDIS_URL:
try:
from pynyaata.cache.redis import RedisCache

View File

@ -1,18 +1,22 @@
from json import dumps, loads
from os import environ
from typing import List, Optional
from pynyaata.cache import CACHE_TIMEOUT
from pynyaata.cache import CACHE_TIMEOUT, REDIS_URL
from pynyaata.types import Cache, RemoteFile
from redis import Redis
from redis import ConnectionError, Redis
REDIS_URL = environ.get("REDIS_URL", "")
if not REDIS_URL:
raise ConnectionError(f"Invalid REDIS_URL: {REDIS_URL}")
client = Redis.from_url(REDIS_URL)
class RedisCache(Cache):
def get(self, key: str) -> Optional[List[RemoteFile]]:
return loads(str(client.get(key)))
data = client.get(key)
return loads(str(data)) if data else None
def set(self, key: str, data: List[RemoteFile]):
return client.set(key, dumps(data), CACHE_TIMEOUT)

View File

@ -1,5 +1,6 @@
from datetime import datetime, timedelta
from typing import Dict, List, Optional, Tuple
from pynyaata.cache import CACHE_TIMEOUT
from pynyaata.types import Cache, RemoteFile
@ -11,10 +12,12 @@ class SimpleCache(Cache):
def get(self, key: str) -> Optional[List[RemoteFile]]:
if key in CACHE_DATA:
data, timeout = CACHE_DATA[key]
if datetime.now() > timeout + timedelta(seconds=CACHE_TIMEOUT):
return data
else:
CACHE_DATA.pop(key)
return None
def set(self, key: str, data: List[RemoteFile]):

View File

@ -1,4 +0,0 @@
from os import environ
VF_WORDS = environ.get("VF_WORDS", "vf,vostfr,multi,french").split(",")
CLOUDPROXY_ENDPOINT = environ.get("CLOUDPROXY_ENDPOINT")

View File

@ -1,11 +1,11 @@
from functools import wraps
from os import environ
from os import getenv
from typing import List
from pynyaata.types import Color, RemoteFile
BLACKLIST_WORDS = environ.get("BLACKLIST_WORDS", "").split(",")
BLACKLIST_WORDS = getenv("BLACKLIST_WORDS", "").split(",")
def duplicate(remotes: List[RemoteFile]) -> List[RemoteFile]:

View File

@ -1,11 +1,13 @@
from io import BytesIO
from os import getenv
from urllib import parse
from pynyaata.constants import CLOUDPROXY_ENDPOINT
from requests import RequestException, Response, Session, post
CLOUDPROXY_ENDPOINT = getenv("CLOUDPROXY_ENDPOINT")
class FlareRequests(Session):
def request(self, method, url, params=None, **kwargs):
if not CLOUDPROXY_ENDPOINT:

View File

@ -21,6 +21,7 @@ class Color(str, Enum):
class RemoteFile(BaseModel):
bridge: str
id: int
category: str
color: Optional[Color]