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

View File

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

View File

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

View File

@ -1,18 +1,22 @@
from json import dumps, loads from json import dumps, loads
from os import environ
from typing import List, Optional 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 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) client = Redis.from_url(REDIS_URL)
class RedisCache(Cache): class RedisCache(Cache):
def get(self, key: str) -> Optional[List[RemoteFile]]: 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]): def set(self, key: str, data: List[RemoteFile]):
return client.set(key, dumps(data), CACHE_TIMEOUT) return client.set(key, dumps(data), CACHE_TIMEOUT)

View File

@ -1,5 +1,6 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import Dict, List, Optional, Tuple from typing import Dict, List, Optional, Tuple
from pynyaata.cache import CACHE_TIMEOUT from pynyaata.cache import CACHE_TIMEOUT
from pynyaata.types import Cache, RemoteFile from pynyaata.types import Cache, RemoteFile
@ -11,10 +12,12 @@ class SimpleCache(Cache):
def get(self, key: str) -> Optional[List[RemoteFile]]: def get(self, key: str) -> Optional[List[RemoteFile]]:
if key in CACHE_DATA: if key in CACHE_DATA:
data, timeout = CACHE_DATA[key] data, timeout = CACHE_DATA[key]
if datetime.now() > timeout + timedelta(seconds=CACHE_TIMEOUT): if datetime.now() > timeout + timedelta(seconds=CACHE_TIMEOUT):
return data return data
else: else:
CACHE_DATA.pop(key) CACHE_DATA.pop(key)
return None return None
def set(self, key: str, data: List[RemoteFile]): 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 functools import wraps
from os import environ from os import getenv
from typing import List from typing import List
from pynyaata.types import Color, RemoteFile 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]: def duplicate(remotes: List[RemoteFile]) -> List[RemoteFile]:

View File

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

View File

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