pynyaasi.client.client

BaseClient

class pynyaasi.client.client.BaseClient(session: Optional[requests.Session] = None)[source]

A base class for clients that interact with websites like nyaa.si.

Attributes:
  • __endpoint__: The base URL for the website.

  • __filter_class__: The class that defines filtering options.

  • __default_filter__: The default filtering option.

  • __category_class__: The class that defines item categories.

  • __default_category__: The default item category.

Methods:
  • iter_items_by_page: Iterates through items on the website by page.

  • iter_items: Iterates through items on the website with paging support.

  • get_resource: Retrieves detailed information about a resource.

__init__(session: Optional[requests.Session] = None)[source]

Initialize the BaseClient.

Parameters:

session – An optional requests.Session object.

get_resource(id_: int)[source]

Retrieves detailed information about a resource.

Parameters:

id (int) – The ID of the resource.

Returns:

A ResourceItem object with resource details.

Return type:

ResourceItem

iter_items(query: str = '', filter=Ellipsis, category=Ellipsis, sort_by=None, order=<Order.DESC: 'desc'>, from_page: int = 1)[source]

Iterates through items on the website with paging support.

Parameters:
  • query (str) – The search query.

  • filter – The filter for items.

  • category – The category for items.

  • sort_by – The sorting option.

  • order (Order) – The sorting order (ascending or descending).

  • from_page (1) – The page number to start from.

Returns:

An iterator of ListItem objects.

Return type:

Iterator[ListItem]

iter_items_by_page(query: str = '', filter=Ellipsis, category=Ellipsis, sort_by=None, order=<Order.DESC: 'desc'>, page: int = 1) → Iterator[pynyaasi.client.client.ListItem][source]

Iterates through items on the website by page.

Parameters:
  • query (str) – The search query.

  • filter – The filter for items.

  • category – The category for items.

  • sort_by – The sorting option.

  • order (Order) – The sorting order (ascending or descending).

  • page (1) – The page number to start from.

Returns:

An iterator of ListItem objects.

Return type:

Iterator[ListItem]

ListItem

class pynyaasi.client.client.ListItem(id: int, category: Any, comments: int, title: str, url: str, torrent_download_url: str, magnet_url: str, size_raw: str, timestamp: int, seeders: int, leechers: int, downloads: int, is_trusted: bool, is_remake: bool, is_batch: bool)[source]
property datetime

Get the datetime of the item’s timestamp.

Returns:

The datetime of the item.

Return type:

datetime.datetime

property size

Get the size of the item as a SizeProxy object.

Returns:

The size of the item.

Return type:

SizeProxy

property time

Get the timestamp of the item in ISO format.

Returns:

The timestamp of the item in ISO format.

Return type:

str

ResourceItem

class pynyaasi.client.client.ResourceItem(id: int, category: Any, title: str, information: str, torrent_download_url: Union[str, NoneType], magnet_url: Union[str, NoneType], size_raw: str, timestamp: int, seeders: int, leechers: int, downloads: int, is_trusted: bool, is_remake: bool, is_batch: bool, info_hash: str, submitter: str, submitter_url: Union[str, NoneType], description_md: str, directory_tree: Union[pynyaasi.client.directory.DirectoryTreeNode, NoneType])[source]
property datetime

Get the datetime of the item’s timestamp.

Returns:

The datetime of the item.

Return type:

datetime.datetime

property size

Get the size of the item as a SizeProxy object.

Returns:

The size of the item.

Return type:

SizeProxy

property time

Get the timestamp of the item in ISO format.

Returns:

The timestamp of the item in ISO format.

Return type:

str