nyapy 0.1.2__py3-none-any.whl → 0.1.4__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.
nyapy/enums.py CHANGED
@@ -40,8 +40,8 @@ class NyaaFunCategories(StrEnum):
40
40
 
41
41
 
42
42
  class Filter(IntEnum):
43
- NO_REMAKES = 1
44
- TRUSTED_ONLY = 2
43
+ no_remakes = 1
44
+ trusted_only = 2
45
45
 
46
46
 
47
47
  class NyaaSite(StrEnum):
nyapy/nyaa.py CHANGED
@@ -3,8 +3,9 @@ import re
3
3
  from bs4 import BeautifulSoup
4
4
 
5
5
  from .client import get_client
6
- from .enums import NyaaSite
7
- from .types.nyaa import ContentData, ResponseData
6
+ from .enums import Filter as FilterEnum
7
+ from .enums import NyaaFunCategories, NyaaSite, SukebeiCategories
8
+ from .types.nyaa import ContentData, Filter, Order, ResponseData, Sort
8
9
 
9
10
 
10
11
  class BadResponse(Exception):
@@ -12,25 +13,36 @@ class BadResponse(Exception):
12
13
  super().__init__(message)
13
14
 
14
15
 
15
- class Nyaa:
16
+ class Nyaa[T: str]:
16
17
  def __init__(self, site: NyaaSite) -> None:
17
- self.client = get_client(site)
18
+ self._client = get_client(site)
19
+ self._categories_enum = (
20
+ NyaaFunCategories if NyaaSite.FUN == site else SukebeiCategories
21
+ )
18
22
 
19
23
  async def get_content(
20
- self, *, filter, category, query, sort, order, page
24
+ self,
25
+ *,
26
+ filter: Filter | None = None,
27
+ category: T | None = None,
28
+ query: str | None = None,
29
+ page: int = 1,
30
+ sort: Sort | None = None,
31
+ order: Order = 'desc',
21
32
  ) -> ResponseData:
22
- if sort == 'date':
23
- sort = 'id'
33
+ sortval = 'id' if sort == 'date' else None
34
+ catval = self._categories_enum[category] if category else None
35
+ filterval = FilterEnum[filter] if filter else None
24
36
 
25
- res = await self.client.get(
37
+ res = await self._client.get(
26
38
  '',
27
39
  params={
28
- 'f': filter,
29
- 'c': category,
40
+ 'f': filterval,
30
41
  'q': query,
31
42
  'p': page,
32
- 's': sort,
43
+ 's': sortval,
33
44
  'o': order,
45
+ 'c': catval,
34
46
  },
35
47
  )
36
48
 
@@ -54,7 +66,9 @@ class Nyaa:
54
66
  torrent = properties[2].find('i', {'class': 'fa-download'})
55
67
  torrent = torrent.parent if torrent else None
56
68
  torrent = torrent.get('href') if torrent else None
57
- torrent = str(self.client.base_url)[:-1] + str(torrent) if torrent else None
69
+ torrent = (
70
+ str(self._client.base_url)[:-1] + str(torrent) if torrent else None
71
+ )
58
72
  magnet = properties[2].find('i', {'class': 'fa-magnet'})
59
73
  magnet = magnet.parent if magnet else None
60
74
  magnet = str(magnet.get('href')) if magnet else None
@@ -83,4 +97,4 @@ class Nyaa:
83
97
 
84
98
  async def close(self):
85
99
  """Closes connection to nyaa"""
86
- await self.client.aclose()
100
+ await self._client.aclose()
nyapy/nyaafun.py CHANGED
@@ -1,27 +1,8 @@
1
- from .enums import Filter, NyaaFunCategories, NyaaSite
1
+ from .enums import NyaaSite
2
2
  from .nyaa import Nyaa
3
- from .types.nyaa import Order, ResponseData, Sort
3
+ from .types.nyaa import NyaaFunCategories
4
4
 
5
5
 
6
- class NyaaFun(Nyaa):
6
+ class NyaaFun(Nyaa[NyaaFunCategories]):
7
7
  def __init__(self) -> None:
8
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
- )
nyapy/sukebei.py CHANGED
@@ -1,27 +1,8 @@
1
- from .enums import Filter, NyaaSite, SukebeiCategories
1
+ from .enums import NyaaSite
2
2
  from .nyaa import Nyaa
3
- from .types.nyaa import Order, ResponseData, Sort
3
+ from .types.nyaa import SukebeiCategories
4
4
 
5
5
 
6
- class Sukebei(Nyaa):
6
+ class Sukebei(Nyaa[SukebeiCategories]):
7
7
  def __init__(self) -> None:
8
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
- )
nyapy/types/nyaa.py CHANGED
@@ -27,3 +27,40 @@ class ResponseData(TypedDict):
27
27
 
28
28
  type Sort = Literal['comments', 'size', 'date', 'seeders', 'leechers', 'downloads']
29
29
  type Order = Literal['asc', 'desc']
30
+ type Filter = Literal['no_remakes', 'trusted_only']
31
+ type SukebeiCategories = Literal[
32
+ 'art',
33
+ 'art_anime',
34
+ 'art_doujinshi',
35
+ 'art_games',
36
+ 'art_manga',
37
+ 'art_pictures',
38
+ 'real_life',
39
+ 'real_life_pictures',
40
+ 'real_life_videos',
41
+ ]
42
+ type NyaaFunCategories = Literal[
43
+ 'anime',
44
+ 'anime_amv',
45
+ 'anime_english',
46
+ 'anime_non_english',
47
+ 'anime_raw',
48
+ 'audio',
49
+ 'audio_lossless',
50
+ 'audio_lossy',
51
+ 'literature',
52
+ 'literature_english',
53
+ 'literature_non_english',
54
+ 'literature_raw',
55
+ 'live_action',
56
+ 'live_action_english',
57
+ 'live_action_idol_pv',
58
+ 'live_action_non_english',
59
+ 'live_action_raw',
60
+ 'pictures',
61
+ 'pictures_graphics',
62
+ 'pictures_photos',
63
+ 'software',
64
+ 'software_apps',
65
+ 'software_games',
66
+ ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: nyapy
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: A nyaa scrapper
5
5
  Author: mikel39
6
6
  Author-email: mikel39 <202028875+mikel39@users.noreply.github.com>
@@ -0,0 +1,10 @@
1
+ nyapy/__init__.py,sha256=Q85n2fc9xfJPjy1nGcWjHo092HhL-wECjRH_YzNzAjo,208
2
+ nyapy/client.py,sha256=9LeOHoqLjgeKTxHDZApfSigDlOZG1qlN8yOB6ApCUzw,385
3
+ nyapy/enums.py,sha256=Nw7iCWTvohcDqjIE16L-HDuXW5NSq3jZHFvwyQ9MdV4,1087
4
+ nyapy/nyaa.py,sha256=UFySVClr55NGfdolcLisUWATJ6XraQKRnhxkJ1IWTSE,3482
5
+ nyapy/nyaafun.py,sha256=rM-qWjox_9FCoitypRlo2apr14mdL7Ktd_8Tro2SzIQ,206
6
+ nyapy/sukebei.py,sha256=1wp5OS_ky0-OxSUEDO20jRbb492FIZPbiVRCSqrCUiM,206
7
+ nyapy/types/nyaa.py,sha256=jhCrNJ0OEN737yOd0CKY8gmPHtlcR1t-shmUZiGUNhw,1307
8
+ nyapy-0.1.4.dist-info/WHEEL,sha256=fAguSjoiATBe7TNBkJwOjyL1Tt4wwiaQGtNtjRPNMQA,80
9
+ nyapy-0.1.4.dist-info/METADATA,sha256=PtoYa8nkrcm33DIrvcEwrPZf03lbNYYanxq4jR8xnZM,338
10
+ nyapy-0.1.4.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- nyapy/__init__.py,sha256=Q85n2fc9xfJPjy1nGcWjHo092HhL-wECjRH_YzNzAjo,208
2
- nyapy/client.py,sha256=9LeOHoqLjgeKTxHDZApfSigDlOZG1qlN8yOB6ApCUzw,385
3
- nyapy/enums.py,sha256=AEY7OpuW3I5tSQ1XuwGHPzv-DYQSYmPBJ6ChzS47pRo,1087
4
- nyapy/nyaa.py,sha256=wfI2RtriFPspjP2veLVcsZJ3L6qkNx6cakkRJydKWeo,2924
5
- nyapy/nyaafun.py,sha256=gWqSQ4yNiLrzs8flFibRAL4lEmy6A9EvHh1E981EzWU,715
6
- nyapy/sukebei.py,sha256=FFkcJ47tR-aeapSUYQQYlDIZKRo0_srnpYYP_d-ylwk,715
7
- nyapy/types/nyaa.py,sha256=zpnQdPRVL-GKoRQ25-YzxzGvSoFbSWESW8wQnKs3Hzw,520
8
- nyapy-0.1.2.dist-info/WHEEL,sha256=fAguSjoiATBe7TNBkJwOjyL1Tt4wwiaQGtNtjRPNMQA,80
9
- nyapy-0.1.2.dist-info/METADATA,sha256=nTGNAiid1H0kaI7cQF3uyb1PRIEVU4J5IJU8GJs3He8,338
10
- nyapy-0.1.2.dist-info/RECORD,,
File without changes