2022-10-26 13:06:04 +00:00
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
from datetime import datetime
|
|
|
|
from enum import Enum
|
2023-01-04 21:32:27 +00:00
|
|
|
from functools import wraps
|
2023-01-04 23:49:54 +00:00
|
|
|
from logging import exception
|
2022-10-26 13:06:04 +00:00
|
|
|
from typing import List, Optional
|
|
|
|
|
|
|
|
from pydantic import BaseModel, ByteSize, HttpUrl
|
|
|
|
|
|
|
|
|
|
|
|
class Color(str, Enum):
|
|
|
|
WHITE = "white"
|
|
|
|
BLACK = "black"
|
|
|
|
LIGHT = "light"
|
|
|
|
DARK = "dark"
|
|
|
|
PRIMARY = "primary"
|
|
|
|
LINK = "link"
|
|
|
|
INFO = "info"
|
|
|
|
SUCCESS = "success"
|
|
|
|
WARNING = "warning"
|
|
|
|
DANGER = "danger"
|
|
|
|
DEFAULT = "default"
|
|
|
|
|
|
|
|
|
|
|
|
class RemoteFile(BaseModel):
|
2022-12-22 00:01:21 +00:00
|
|
|
bridge: str
|
2022-10-26 13:06:04 +00:00
|
|
|
id: int
|
|
|
|
category: str
|
|
|
|
color: Optional[Color]
|
|
|
|
name: str
|
|
|
|
link: HttpUrl
|
|
|
|
comment: int = 0
|
2023-01-06 13:17:11 +00:00
|
|
|
comment_url: Optional[HttpUrl]
|
2022-10-26 13:06:04 +00:00
|
|
|
magnet: Optional[str]
|
|
|
|
torrent: Optional[HttpUrl]
|
|
|
|
size: Optional[ByteSize]
|
|
|
|
date: Optional[datetime]
|
|
|
|
seeds: Optional[int]
|
|
|
|
leechs: Optional[int]
|
|
|
|
downloads: Optional[int]
|
|
|
|
nb_pages: int = 1
|
|
|
|
|
|
|
|
|
|
|
|
class Bridge(BaseModel, ABC):
|
|
|
|
color: Color
|
|
|
|
title: str
|
|
|
|
favicon: HttpUrl
|
|
|
|
base_url: HttpUrl
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def search_url(self, query: str = "", page: int = 1) -> HttpUrl:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-01-04 15:57:16 +00:00
|
|
|
async def search(self, query: str = "", page: int = 1) -> List[RemoteFile]:
|
2022-10-26 13:06:04 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Cache(ABC):
|
|
|
|
@abstractmethod
|
|
|
|
def get(self, key: str) -> Optional[List[RemoteFile]]:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def set(self, key: str, data: List[RemoteFile]):
|
|
|
|
pass
|
2023-01-04 21:32:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
def log_async(f):
|
|
|
|
@wraps(f)
|
|
|
|
async def wrapper(*args, **kwargs):
|
|
|
|
try:
|
|
|
|
return await f(*args, **kwargs)
|
|
|
|
except Exception as e:
|
2023-01-04 23:49:54 +00:00
|
|
|
exception(e)
|
2023-01-04 21:32:27 +00:00
|
|
|
raise e
|
|
|
|
|
|
|
|
return wrapper
|