nyapy 0.1.2__tar.gz → 0.1.4__tar.gz

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.
@@ -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>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "nyapy"
3
- version = "0.1.2"
3
+ version = "0.1.4"
4
4
  authors = [
5
5
  { name = "mikel39", email = "202028875+mikel39@users.noreply.github.com" }
6
6
  ]
@@ -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):
@@ -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()
@@ -0,0 +1,8 @@
1
+ from .enums import NyaaSite
2
+ from .nyaa import Nyaa
3
+ from .types.nyaa import NyaaFunCategories
4
+
5
+
6
+ class NyaaFun(Nyaa[NyaaFunCategories]):
7
+ def __init__(self) -> None:
8
+ super().__init__(NyaaSite.FUN)
@@ -0,0 +1,8 @@
1
+ from .enums import NyaaSite
2
+ from .nyaa import Nyaa
3
+ from .types.nyaa import SukebeiCategories
4
+
5
+
6
+ class Sukebei(Nyaa[SukebeiCategories]):
7
+ def __init__(self) -> None:
8
+ super().__init__(NyaaSite.FAP)
@@ -0,0 +1,66 @@
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
+ id: int
11
+ category: str
12
+ name: str
13
+ comments: int
14
+ size: str
15
+ date: str
16
+ seeders: int
17
+ leechers: int
18
+ downloads: int
19
+ links: _Links
20
+
21
+
22
+ class ResponseData(TypedDict):
23
+ page: int
24
+ results: int
25
+ data: list[ContentData]
26
+
27
+
28
+ type Sort = Literal['comments', 'size', 'date', 'seeders', 'leechers', 'downloads']
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,27 +0,0 @@
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
- )
@@ -1,27 +0,0 @@
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
- )
@@ -1,29 +0,0 @@
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
- id: int
11
- category: str
12
- name: str
13
- comments: int
14
- size: str
15
- date: str
16
- seeders: int
17
- leechers: int
18
- downloads: int
19
- links: _Links
20
-
21
-
22
- class ResponseData(TypedDict):
23
- page: int
24
- results: int
25
- data: list[ContentData]
26
-
27
-
28
- type Sort = Literal['comments', 'size', 'date', 'seeders', 'leechers', 'downloads']
29
- type Order = Literal['asc', 'desc']
File without changes
File without changes
File without changes