Skip to content
Merged
35 changes: 35 additions & 0 deletions common/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,40 @@ def __post_init__(self):
self.date = dt.datetime.fromtimestamp(self.date).strftime(globals.settings.datestamp_format)


@dataclasses.dataclass(slots=True)
class DdlFile:
thread_id: int
id: str
title: str
filename: str
size: int
date: str
size_display: str = None

def __post_init__(self):
if not self.id:
return
from modules import (
globals,
utils,
)
self.size_display = utils.sizeof_fmt(int(self.size))
self.date = dt.datetime.strptime(self.date, r"%Y-%m-%d").strftime(globals.settings.datestamp_format)


@dataclasses.dataclass(slots=True)
class FileDownload:
url: str
cookies: dict = True
path: pathlib.Path = None
progress: int = 0
total: int = 0
cancel: bool = False
stopped: bool = False
error: str = None
traceback: str = None


@dataclasses.dataclass(slots=True)
class SortSpec:
index: int
Expand Down Expand Up @@ -668,6 +702,7 @@ class Settings:
default_tab_is_new : bool
display_mode : DisplayMode
display_tab : Tab.get
downloads_dir : dict[Os, str]
ext_background_add : bool
ext_highlight_tags : bool
ext_icon_glow : bool
Expand Down
8 changes: 4 additions & 4 deletions indexer/f95zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import aiohttp
import aiolimiter

XENFORO_RATELIMIT = aiolimiter.AsyncLimiter(max_rate=1, time_period=0.5)
RATELIMIT = aiolimiter.AsyncLimiter(max_rate=1, time_period=0.5)
TIMEOUT = aiohttp.ClientTimeout(total=30)
LOGIN_ERROR_MESSAGES = (
b'<a href="/login/" data-xf-click="overlay">Log in or register now.</a>',
Expand Down Expand Up @@ -46,8 +46,8 @@ class IndexerError:
ERROR_SESSION_LOGGED_OUT = IndexerError(
"SESSION_LOGGED_OUT", dt.timedelta(hours=2).total_seconds()
)
ERROR_XENFORO_RATELIMIT = IndexerError(
"XENFORO_RATELIMIT", dt.timedelta(minutes=15).total_seconds()
ERROR_FORUM_RATELIMIT = IndexerError(
"FORUM_RATELIMIT", dt.timedelta(minutes=15).total_seconds()
)
ERROR_F95ZONE_UNAVAILABLE = IndexerError(
"F95ZONE_UNAVAILABLE", dt.timedelta(minutes=15).total_seconds()
Expand Down Expand Up @@ -100,7 +100,7 @@ def check_error(res: bytes) -> IndexerError | None:

if any((msg in res) for msg in RATELIMIT_ERROR_MESSAGES):
logger.error("Hit F95zone ratelimit")
return ERROR_XENFORO_RATELIMIT
return ERROR_FORUM_RATELIMIT

if any((msg in res) for msg in TEMP_ERROR_MESSAGES):
logger.warning("F95zone temporarily unreachable")
Expand Down
2 changes: 1 addition & 1 deletion indexer/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async def thread(id: int) -> dict[str, str] | None:
thread_url = f95zone.THREAD_URL.format(thread=id)
retries = 10
while retries:
async with f95zone.XENFORO_RATELIMIT:
async with f95zone.RATELIMIT:
async with f95zone.session.get(
thread_url,
cookies=f95zone.cookies,
Expand Down
Loading