nyaa-apiwrapper 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ from .enums import Filter, NyaaFunCategories, SukebeiCategories
2
+ from .nyaafun import NyaaFun
3
+ from .sukebei import Sukebei
4
+
5
+ __all__ = ['Filter', 'NyaaFunCategories', 'SukebeiCategories', 'NyaaFun', 'Sukebei']
@@ -0,0 +1,12 @@
1
+ from httpx import AsyncClient, AsyncHTTPTransport
2
+
3
+
4
+ def get_client(base_url: str) -> AsyncClient:
5
+ return AsyncClient(
6
+ base_url=base_url,
7
+ headers={
8
+ 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36'
9
+ },
10
+ timeout=10.0,
11
+ transport=AsyncHTTPTransport(retries=6),
12
+ )
@@ -0,0 +1,49 @@
1
+ from enum import IntEnum, StrEnum
2
+
3
+
4
+ class SukebeiCategories(StrEnum):
5
+ art = '1_0'
6
+ art_anime = '1_1'
7
+ art_doujinshi = '1_2'
8
+ art_games = '1_3'
9
+ art_manga = '1_4'
10
+ art_pictures = '1_5'
11
+ real_life = '2_0'
12
+ real_life_pictures = '2_1'
13
+ real_life_videos = '2_2'
14
+
15
+
16
+ class NyaaFunCategories(StrEnum):
17
+ anime = '1_0'
18
+ anime_amv = '1_1'
19
+ anime_english = '1_2'
20
+ anime_non_english = '1_3'
21
+ anime_raw = '1_4'
22
+ audio = '2_0'
23
+ audio_lossless = '2_1'
24
+ audio_lossy = '2_2'
25
+ literature = '3_0'
26
+ literature_english = '3_1'
27
+ literature_non_english = '3_2'
28
+ literature_raw = '3_3'
29
+ live_action = '4_0'
30
+ live_action_english = '4_1'
31
+ live_action_idol_pv = '4_2'
32
+ live_action_non_english = '4_3'
33
+ live_action_raw = '4_4'
34
+ pictures = '5_0'
35
+ pictures_graphics = '5_1'
36
+ pictures_photos = '5_2'
37
+ software = '6_0'
38
+ software_apps = '6_1'
39
+ software_games = '6_2'
40
+
41
+
42
+ class Filter(IntEnum):
43
+ NO_REMAKES = 1
44
+ TRUSTED_ONLY = 2
45
+
46
+
47
+ class NyaaSite(StrEnum):
48
+ FUN = 'https://nyaa.si/'
49
+ FAP = 'https://sukebei.nyaa.si/'
@@ -0,0 +1,81 @@
1
+ from bs4 import BeautifulSoup
2
+
3
+ from .client import get_client
4
+ from .enums import NyaaSite
5
+ from .types.nyaa import ContentData, ResponseData
6
+
7
+
8
+ class BadResponse(Exception):
9
+ def __init__(self, message: str) -> None:
10
+ super().__init__(message)
11
+
12
+
13
+ class Nyaa:
14
+ def __init__(self, site: NyaaSite) -> None:
15
+ self.client = get_client(site)
16
+
17
+ async def get_content(
18
+ self, *, filter, category, query, sort, order, page
19
+ ) -> ResponseData:
20
+ if sort == 'date':
21
+ sort = 'id'
22
+
23
+ res = await self.client.get(
24
+ '',
25
+ params={
26
+ 'f': filter,
27
+ 'c': category,
28
+ 'q': query,
29
+ 'p': page,
30
+ 's': sort,
31
+ 'o': order,
32
+ },
33
+ )
34
+
35
+ if res.status_code != 200:
36
+ raise BadResponse('Error connection to nyaa')
37
+
38
+ html = BeautifulSoup(res.text, 'html.parser')
39
+ rows = html.select('tbody tr')
40
+ data: list[ContentData] = []
41
+
42
+ for row in rows:
43
+ properties = row.find_all('td')
44
+ category_row = properties[0].find('a')
45
+ category_row = (category_row or {}).get('title', '')
46
+ comments = properties[1].find('a', attrs={'class': 'commentss'})
47
+ comments = int(comments.text) if comments else 0
48
+ name = properties[1].find('a', {'class': False})
49
+ name = name.text if name else ''
50
+ torrent = properties[2].find('i', {'class': 'fa-download'})
51
+ torrent = torrent.parent if torrent else None
52
+ torrent = torrent.get('href') if torrent else None
53
+ torrent = str(self.client.base_url)[:-1] + str(torrent) if torrent else None
54
+ magnet = properties[2].find('i', {'class': 'fa-magnet'})
55
+ magnet = magnet.parent if magnet else None
56
+ magnet = str(magnet.get('href')) if magnet else None
57
+ size = properties[3].text
58
+ date = properties[4].get('data-timestamp')
59
+ seeders = int(properties[5].text)
60
+ leechers = int(properties[6].text)
61
+ downloads = int(properties[7].text)
62
+
63
+ content: ContentData = {
64
+ 'category': str(category_row),
65
+ 'name': str(name),
66
+ 'comments': comments,
67
+ 'links': {'torrent': torrent, 'magnet': magnet},
68
+ 'size': str(size),
69
+ 'date': str(date),
70
+ 'seeders': seeders,
71
+ 'leechers': leechers,
72
+ 'downloads': downloads,
73
+ }
74
+
75
+ data.append(content)
76
+
77
+ return {'page': page, 'results': len(data), 'data': data}
78
+
79
+ async def close(self):
80
+ """Closes connection to nyaa"""
81
+ await self.client.aclose()
@@ -0,0 +1,27 @@
1
+ from .enums import Filter, NyaaFunCategories, NyaaSite
2
+ from .nyaa import Nyaa
3
+ from .types.nyaa import Order, ResponseData, Sort
4
+
5
+
6
+ class NyaaFun(Nyaa):
7
+ def __init__(self) -> None:
8
+ super().__init__(NyaaSite.FUN)
9
+
10
+ async def get_content(
11
+ self,
12
+ *,
13
+ filter: Filter | None = None,
14
+ category: NyaaFunCategories | None = None,
15
+ query: str | None = None,
16
+ page: int = 1,
17
+ sort: Sort | None = None,
18
+ order: Order = 'desc',
19
+ ) -> ResponseData:
20
+ return await super().get_content(
21
+ filter=filter,
22
+ category=category,
23
+ query=query,
24
+ sort=sort,
25
+ page=page,
26
+ order=order,
27
+ )
@@ -0,0 +1,27 @@
1
+ from .enums import Filter, NyaaSite, SukebeiCategories
2
+ from .nyaa import Nyaa
3
+ from .types.nyaa import Order, ResponseData, Sort
4
+
5
+
6
+ class Sukebei(Nyaa):
7
+ def __init__(self) -> None:
8
+ super().__init__(NyaaSite.FAP)
9
+
10
+ async def get_content(
11
+ self,
12
+ *,
13
+ filter: Filter | None = None,
14
+ category: SukebeiCategories | None = None,
15
+ query: str | None = None,
16
+ page: int = 1,
17
+ sort: Sort | None = None,
18
+ order: Order = 'desc',
19
+ ) -> ResponseData:
20
+ return await super().get_content(
21
+ filter=filter,
22
+ category=category,
23
+ query=query,
24
+ sort=sort,
25
+ page=page,
26
+ order=order,
27
+ )
@@ -0,0 +1,28 @@
1
+ from typing import Literal, TypedDict
2
+
3
+
4
+ class _Links(TypedDict):
5
+ torrent: str | None
6
+ magnet: str | None
7
+
8
+
9
+ class ContentData(TypedDict):
10
+ category: str
11
+ name: str
12
+ comments: int
13
+ size: str
14
+ date: str
15
+ seeders: int
16
+ leechers: int
17
+ downloads: int
18
+ links: _Links
19
+
20
+
21
+ class ResponseData(TypedDict):
22
+ page: int
23
+ results: int
24
+ data: list[ContentData]
25
+
26
+
27
+ type Sort = Literal['comments', 'size', 'date', 'seeders', 'leechers', 'downloads']
28
+ type Order = Literal['asc', 'desc']
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.3
2
+ Name: nyaa-apiwrapper
3
+ Version: 0.1.0
4
+ Summary: A nyaa api wrapper
5
+ Author: mikel39
6
+ Author-email: mikel39 <202028875+mikel39@users.noreply.github.com>
7
+ Requires-Dist: bs4>=0.0.2
8
+ Requires-Dist: httpx>=0.28.1
9
+ Requires-Python: >=3.14
10
+ Description-Content-Type: text/markdown
11
+
@@ -0,0 +1,10 @@
1
+ nyaa_apiwrapper/__init__.py,sha256=Q85n2fc9xfJPjy1nGcWjHo092HhL-wECjRH_YzNzAjo,208
2
+ nyaa_apiwrapper/client.py,sha256=9LeOHoqLjgeKTxHDZApfSigDlOZG1qlN8yOB6ApCUzw,385
3
+ nyaa_apiwrapper/enums.py,sha256=AEY7OpuW3I5tSQ1XuwGHPzv-DYQSYmPBJ6ChzS47pRo,1087
4
+ nyaa_apiwrapper/nyaa.py,sha256=SVUdCccbYrWrIXd66CX2ViarSpBgHoO6dMH4d3EfZRM,2770
5
+ nyaa_apiwrapper/nyaafun.py,sha256=gWqSQ4yNiLrzs8flFibRAL4lEmy6A9EvHh1E981EzWU,715
6
+ nyaa_apiwrapper/sukebei.py,sha256=FFkcJ47tR-aeapSUYQQYlDIZKRo0_srnpYYP_d-ylwk,715
7
+ nyaa_apiwrapper/types/nyaa.py,sha256=-5FXn8vzCLV9jfTZY6ItE3g7xGXI8peoXCMW7Acer8g,508
8
+ nyaa_apiwrapper-0.1.0.dist-info/WHEEL,sha256=fAguSjoiATBe7TNBkJwOjyL1Tt4wwiaQGtNtjRPNMQA,80
9
+ nyaa_apiwrapper-0.1.0.dist-info/METADATA,sha256=-7rsylFZPfqXpRtF76WoesAxKySb8ez2yMiwGOw4c7Y,290
10
+ nyaa_apiwrapper-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.9.28
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any