mirror of
https://github.com/flibusta-apps/batch_downloader.git
synced 2025-12-06 14:25:36 +01:00
Add downloading translator books
This commit is contained in:
@@ -148,7 +148,7 @@ async def create_archive(task_id: uuid.UUID, redis: Redis = TaskiqDepends(get_re
|
||||
item = await LibraryClient.get_sequence(task.object_id)
|
||||
assert item
|
||||
name = item.name
|
||||
case ObjectType.AUTHOR:
|
||||
case ObjectType.AUTHOR | ObjectType.TRANSLATOR:
|
||||
item = await LibraryClient.get_author(task.object_id)
|
||||
assert item
|
||||
names = [item.first_name, item.last_name, item.middle_name]
|
||||
|
||||
@@ -17,6 +17,11 @@ class AuthorBook(BaseModel):
|
||||
available_types: list[str]
|
||||
|
||||
|
||||
class TranslatorBook(BaseModel):
|
||||
id: int
|
||||
available_types: list[str]
|
||||
|
||||
|
||||
Item = TypeVar("Item", bound=BaseModel)
|
||||
|
||||
|
||||
@@ -81,6 +86,26 @@ class LibraryClient:
|
||||
|
||||
return Page[AuthorBook].parse_raw(response.text)
|
||||
|
||||
@staticmethod
|
||||
async def get_translator_books(
|
||||
translator_id: int, allowed_langs: list[str], page: int = 1
|
||||
) -> Page[TranslatorBook] | None:
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.get(
|
||||
f"{env_config.LIBRARY_URL}/api/v1/translators/{translator_id}/books",
|
||||
params={
|
||||
"page": page,
|
||||
"allowed_langs": allowed_langs,
|
||||
"is_deleted": "false",
|
||||
},
|
||||
headers={"Authorization": env_config.LIBRARY_API_KEY},
|
||||
)
|
||||
|
||||
if response.status_code != 200:
|
||||
return None
|
||||
|
||||
return Page[TranslatorBook].parse_raw(response.text)
|
||||
|
||||
@staticmethod
|
||||
async def get_sequence(sequence_id: int) -> Sequence | None:
|
||||
async with httpx.AsyncClient() as client:
|
||||
|
||||
@@ -27,6 +27,8 @@ class TaskCreator:
|
||||
books_getter = LibraryClient.get_sequence_books
|
||||
case ObjectType.AUTHOR:
|
||||
books_getter = LibraryClient.get_author_books
|
||||
case ObjectType.TRANSLATOR:
|
||||
books_getter = LibraryClient.get_translator_books
|
||||
|
||||
while current_page <= pages_count:
|
||||
book_page = await books_getter(object_id, allowed_langs, page=current_page)
|
||||
|
||||
@@ -14,6 +14,7 @@ class TaskStatusEnum(enum.StrEnum):
|
||||
class ObjectType(enum.StrEnum):
|
||||
SEQUENCE = "sequence"
|
||||
AUTHOR = "author"
|
||||
TRANSLATOR = "translator"
|
||||
|
||||
|
||||
class Task(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user