yummyanime 0.0.1__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.
Potentially problematic release.
This version of yummyanime might be problematic. Click here for more details.
- yummyanime-0.0.1/LICENSE +7 -0
- yummyanime-0.0.1/PKG-INFO +45 -0
- yummyanime-0.0.1/README.md +28 -0
- yummyanime-0.0.1/pyproject.toml +24 -0
- yummyanime-0.0.1/requirements.txt +4 -0
- yummyanime-0.0.1/setup.cfg +4 -0
- yummyanime-0.0.1/src/yummyanime/__init__.py +5 -0
- yummyanime-0.0.1/src/yummyanime/api.py +167 -0
- yummyanime-0.0.1/src/yummyanime/enums.py +7 -0
- yummyanime-0.0.1/src/yummyanime/exceptions.py +44 -0
- yummyanime-0.0.1/src/yummyanime/parsers/__init__.py +9 -0
- yummyanime-0.0.1/src/yummyanime/parsers/abstract_parser.py +90 -0
- yummyanime-0.0.1/src/yummyanime/parsers/kodik/__init__.py +1 -0
- yummyanime-0.0.1/src/yummyanime/parsers/kodik/downloader.py +111 -0
- yummyanime-0.0.1/src/yummyanime/parsers/utils.py +6 -0
- yummyanime-0.0.1/src/yummyanime/routes/__init__.py +1 -0
- yummyanime-0.0.1/src/yummyanime/routes/_abs.py +16 -0
- yummyanime-0.0.1/src/yummyanime/routes/anime.py +66 -0
- yummyanime-0.0.1/src/yummyanime/routes/trailers.py +12 -0
- yummyanime-0.0.1/src/yummyanime/structs/__init__.py +4 -0
- yummyanime-0.0.1/src/yummyanime/structs/_base.py +97 -0
- yummyanime-0.0.1/src/yummyanime/structs/_enums.py +27 -0
- yummyanime-0.0.1/src/yummyanime/structs/anime.py +266 -0
- yummyanime-0.0.1/src/yummyanime/structs/trailers.py +16 -0
- yummyanime-0.0.1/src/yummyanime/structs/video.py +38 -0
- yummyanime-0.0.1/src/yummyanime.egg-info/PKG-INFO +45 -0
- yummyanime-0.0.1/src/yummyanime.egg-info/SOURCES.txt +28 -0
- yummyanime-0.0.1/src/yummyanime.egg-info/dependency_links.txt +1 -0
- yummyanime-0.0.1/src/yummyanime.egg-info/requires.txt +4 -0
- yummyanime-0.0.1/src/yummyanime.egg-info/top_level.txt +1 -0
yummyanime-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2024 I.M.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: yummyanime
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Yummy Anime API wrapper
|
|
5
|
+
Author-email: "IM.Corp" <root@yummyani.me>
|
|
6
|
+
Project-URL: Homepage, https://yummyani.me/
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: aiohttp~=3.9.5
|
|
14
|
+
Requires-Dist: json5~=0.9.25
|
|
15
|
+
Requires-Dist: beautifulsoup4~=4.12.3
|
|
16
|
+
Requires-Dist: gdown~=5.1.0
|
|
17
|
+
|
|
18
|
+
# YummyAnime API python
|
|
19
|
+
|
|
20
|
+
This is a wrapper around [yummyanime API](https://yummyani.me/api), written in Python async.
|
|
21
|
+
|
|
22
|
+
# Installation
|
|
23
|
+
```bash
|
|
24
|
+
pip install yummyanime
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
# Getting started
|
|
28
|
+
Before using the API, create DEV application [here](https://yummyani.me/dev/applications).
|
|
29
|
+
|
|
30
|
+
After that, start using it right away:
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
|
|
34
|
+
from yummyanime import YummyApi, Format
|
|
35
|
+
|
|
36
|
+
api = YummyApi("your_client_id from https://yummyani.me/dev/applications", Format.JSON)
|
|
37
|
+
|
|
38
|
+
async def main(url: str):
|
|
39
|
+
anime = await api.anime.get(url, need_videos=True)
|
|
40
|
+
print("Friren's anime title: ", anime.response.title)
|
|
41
|
+
video_kodik = next(i for i in anime.response.videos if "kodik." in i.iframe_url)
|
|
42
|
+
qualities = await video_kodik.qualities()
|
|
43
|
+
print("Link to 720p: ", qualities.p720)
|
|
44
|
+
print(main('provozhayushchaya-posledniy-put-friren'))
|
|
45
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# YummyAnime API python
|
|
2
|
+
|
|
3
|
+
This is a wrapper around [yummyanime API](https://yummyani.me/api), written in Python async.
|
|
4
|
+
|
|
5
|
+
# Installation
|
|
6
|
+
```bash
|
|
7
|
+
pip install yummyanime
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
# Getting started
|
|
11
|
+
Before using the API, create DEV application [here](https://yummyani.me/dev/applications).
|
|
12
|
+
|
|
13
|
+
After that, start using it right away:
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
|
|
17
|
+
from yummyanime import YummyApi, Format
|
|
18
|
+
|
|
19
|
+
api = YummyApi("your_client_id from https://yummyani.me/dev/applications", Format.JSON)
|
|
20
|
+
|
|
21
|
+
async def main(url: str):
|
|
22
|
+
anime = await api.anime.get(url, need_videos=True)
|
|
23
|
+
print("Friren's anime title: ", anime.response.title)
|
|
24
|
+
video_kodik = next(i for i in anime.response.videos if "kodik." in i.iframe_url)
|
|
25
|
+
qualities = await video_kodik.qualities()
|
|
26
|
+
print("Link to 720p: ", qualities.p720)
|
|
27
|
+
print(main('provozhayushchaya-posledniy-put-friren'))
|
|
28
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
[project]
|
|
5
|
+
name = "yummyanime"
|
|
6
|
+
version = "0.0.1"
|
|
7
|
+
authors = [
|
|
8
|
+
{ name="IM.Corp", email="root@yummyani.me" },
|
|
9
|
+
]
|
|
10
|
+
dynamic = ["dependencies"]
|
|
11
|
+
description = "Yummy Anime API wrapper"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.9"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://yummyani.me/"
|
|
22
|
+
|
|
23
|
+
[tool.setuptools.dynamic]
|
|
24
|
+
dependencies = {file = ["requirements.txt"]}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from typing import Any, Callable
|
|
3
|
+
|
|
4
|
+
import aiohttp
|
|
5
|
+
import json5
|
|
6
|
+
|
|
7
|
+
from .enums import Format
|
|
8
|
+
from .exceptions import YummyAPIError, YummyError, YummyRateLimitError, YummyNotFoundError, YummyResponseParseFailed
|
|
9
|
+
from .routes import Anime
|
|
10
|
+
from .structs import YummyAnswer, Timing, AbsDict
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class YummyApi:
|
|
14
|
+
"""
|
|
15
|
+
The YummyApi class is used to interact with the Yummy API.
|
|
16
|
+
It provides methods for making HTTP requests to the API's endpoints.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
x_application_token: str,
|
|
22
|
+
format: Format = Format.JSON,
|
|
23
|
+
api_gateway='https://api.yani.tv',
|
|
24
|
+
accept: str = 'image/avif,image/webp',
|
|
25
|
+
custom_headers: dict = None,
|
|
26
|
+
user_token: str | None = None
|
|
27
|
+
):
|
|
28
|
+
"""
|
|
29
|
+
Initializes a new instance of the YummyApi class.
|
|
30
|
+
|
|
31
|
+
:param x_application_token: Public application Access token. Get from [here](https://yummyani.me/dev/applications).
|
|
32
|
+
:param format: The format of the response (default is JSON).
|
|
33
|
+
:param api_gateway: The base URL of the API (default is 'https://api.yani.tv').
|
|
34
|
+
:param accept: The accepted response image types (default is 'image/avif,image/webp').
|
|
35
|
+
:param custom_headers: Any custom headers to include in the request (default is None).
|
|
36
|
+
:param user_token: The user's token (default is None).
|
|
37
|
+
"""
|
|
38
|
+
self._format = format
|
|
39
|
+
self._x_application = x_application_token
|
|
40
|
+
self.api_gateway = api_gateway
|
|
41
|
+
self._accept = accept
|
|
42
|
+
self._custom_headers = custom_headers or {}
|
|
43
|
+
self.anime = Anime(self)
|
|
44
|
+
self.token = user_token
|
|
45
|
+
|
|
46
|
+
async def method(self, path: str, method: str, data: dict | None = None, retry_count: int = 3,
|
|
47
|
+
type: Any = None) -> Any:
|
|
48
|
+
"""
|
|
49
|
+
Makes an HTTP request to the specified path.
|
|
50
|
+
|
|
51
|
+
:param retry_count: retry count in case of 429 error
|
|
52
|
+
:param path: The path of the endpoint.
|
|
53
|
+
:param method: The HTTP method to use.
|
|
54
|
+
:param data: The data to send with the request (default is None).
|
|
55
|
+
:return: The response from the server.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
def retry(retry_count_new: int):
|
|
59
|
+
return self.method(path, method, data, retry_count=retry_count_new, type=type)
|
|
60
|
+
|
|
61
|
+
method = method.upper()
|
|
62
|
+
async with aiohttp.ClientSession(headers=self._headers) as session:
|
|
63
|
+
if method == 'HEAD':
|
|
64
|
+
async with session.head(f'{self.api_gateway}{path}', params=data) as resp:
|
|
65
|
+
return await self._parse_response(resp, retry, retry_count)
|
|
66
|
+
if method == 'GET':
|
|
67
|
+
async with session.get(f'{self.api_gateway}{path}', params=data) as resp:
|
|
68
|
+
return await self._parse_response(resp, retry, retry_count, type)
|
|
69
|
+
elif method == 'PUT':
|
|
70
|
+
async with session.put(f'{self.api_gateway}{path}', json=data) as resp:
|
|
71
|
+
return await self._parse_response(resp, retry, retry_count, type)
|
|
72
|
+
elif method == 'POST':
|
|
73
|
+
async with session.post(f'{self.api_gateway}{path}', json=data) as resp:
|
|
74
|
+
return await self._parse_response(resp, retry, retry_count, type)
|
|
75
|
+
elif method == 'DELETE':
|
|
76
|
+
async with session.delete(f'{self.api_gateway}{path}', json=data) as resp:
|
|
77
|
+
return await self._parse_response(resp, retry, retry_count, type)
|
|
78
|
+
elif method == 'PATCH':
|
|
79
|
+
async with session.patch(f'{self.api_gateway}{path}', json=data) as resp:
|
|
80
|
+
return await self._parse_response(resp, retry, retry_count, type)
|
|
81
|
+
else:
|
|
82
|
+
raise ValueError(f'Invalid method: {method}')
|
|
83
|
+
|
|
84
|
+
@property
|
|
85
|
+
def _headers(self):
|
|
86
|
+
"""
|
|
87
|
+
Returns the headers to be used in the HTTP request.
|
|
88
|
+
|
|
89
|
+
:return: A dictionary containing the headers.
|
|
90
|
+
"""
|
|
91
|
+
return {
|
|
92
|
+
'X-Application': self._x_application,
|
|
93
|
+
'Content-Type': 'application/json',
|
|
94
|
+
'Accept': self._accept,
|
|
95
|
+
'Vary': self._format.value,
|
|
96
|
+
**(self._custom_headers or {}),
|
|
97
|
+
**({'Authorization': f'Bearer {self.token}'} if self.token else {})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async def _parse_response(self, resp: aiohttp.ClientResponse, retry: Callable[[int], Any] = None,
|
|
101
|
+
_retry_count=3, type: Any = None) -> YummyAnswer:
|
|
102
|
+
"""
|
|
103
|
+
Parses the response from the server.
|
|
104
|
+
|
|
105
|
+
:param resp: The response from the server.
|
|
106
|
+
:return: The parsed response.
|
|
107
|
+
"""
|
|
108
|
+
if resp.status == 429: # Rate limit API handler - retry 3 times
|
|
109
|
+
_retry_count -= 1
|
|
110
|
+
if _retry_count >= 0:
|
|
111
|
+
await asyncio.sleep(5)
|
|
112
|
+
return await retry(_retry_count - 1)
|
|
113
|
+
raise YummyRateLimitError("Rate limit exceeded")
|
|
114
|
+
if resp.method == 'HEAD':
|
|
115
|
+
return YummyAnswer(resp.status == 200, self._parse_server_timing(resp.headers.get('Server-Timing', '')))
|
|
116
|
+
elif resp.status == 404:
|
|
117
|
+
raise YummyNotFoundError("Not found")
|
|
118
|
+
try:
|
|
119
|
+
if self._format == Format.XML:
|
|
120
|
+
raise YummyError("Xml response is not yet supported!")
|
|
121
|
+
elif self._format == Format.JSON5:
|
|
122
|
+
ans = json5.loads(await resp.text())
|
|
123
|
+
else:
|
|
124
|
+
ans = await resp.json()
|
|
125
|
+
except Exception as e:
|
|
126
|
+
raise YummyResponseParseFailed(e)
|
|
127
|
+
|
|
128
|
+
if 'error' in ans:
|
|
129
|
+
error = ans['error']
|
|
130
|
+
raise YummyAPIError(
|
|
131
|
+
error.get('message', ''), error.get('status_code', 0), error.get('title', 'Error'),
|
|
132
|
+
error.get('name', 'Undefined Error'), error.get('suberror_code', None)
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
timings = self._parse_server_timing(resp.headers.get('Server-Timing', ''))
|
|
136
|
+
response = self._parse_type(ans.get('response'), type)
|
|
137
|
+
return YummyAnswer(response, timings)
|
|
138
|
+
|
|
139
|
+
@staticmethod
|
|
140
|
+
def _parse_server_timing(server_timing_header: str) -> list[Timing]:
|
|
141
|
+
"""
|
|
142
|
+
Parses the Server-Timing header.
|
|
143
|
+
|
|
144
|
+
:param server_timing_header: The Server-Timing header.
|
|
145
|
+
:return: A dictionary containing the parsed Server-Timing header.
|
|
146
|
+
"""
|
|
147
|
+
answers = []
|
|
148
|
+
for component in server_timing_header.split(','):
|
|
149
|
+
# Split the component into its name and duration
|
|
150
|
+
data = component.split(';')
|
|
151
|
+
name = data[0]
|
|
152
|
+
duration = next((i.replace('dur=', '') for i in data if i.startswith('dur=')), "0")
|
|
153
|
+
description = next((i.replace('desc="', '').replace('"', '') for i in data if i.startswith('desc=')), "")
|
|
154
|
+
answers.append(Timing(name, float(duration), description))
|
|
155
|
+
|
|
156
|
+
return answers
|
|
157
|
+
|
|
158
|
+
@staticmethod
|
|
159
|
+
def _parse_type(ans: dict | list, type: Any):
|
|
160
|
+
if not type:
|
|
161
|
+
if isinstance(ans, list):
|
|
162
|
+
return [YummyApi._parse_type(i, None) for i in ans]
|
|
163
|
+
return AbsDict(ans)
|
|
164
|
+
if isinstance(ans, list):
|
|
165
|
+
if not type.__args__: raise ValueError(f"Type {type} is not a list")
|
|
166
|
+
return [YummyApi._parse_type(i, type.__args__[0]) for i in ans]
|
|
167
|
+
return type(ans)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
class YummyError(Exception):
|
|
2
|
+
def __init__(self, message):
|
|
3
|
+
super().__init__()
|
|
4
|
+
self.message = message
|
|
5
|
+
|
|
6
|
+
def __repr__(self):
|
|
7
|
+
return f'YummyError(message="{self.message}")'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class YummyAPIError(YummyError):
|
|
11
|
+
def __init__(self, message, status_code, title='Error', name='Undefined Error', suberror_code=None):
|
|
12
|
+
super().__init__(message)
|
|
13
|
+
self.status_code = status_code
|
|
14
|
+
self.title = title
|
|
15
|
+
self.name = name
|
|
16
|
+
self.suberror_code = suberror_code
|
|
17
|
+
|
|
18
|
+
def __repr__(self):
|
|
19
|
+
return f'YummyAPIError(message="{self.message}", status_code={self.status_code}, title="{self.title}", name="{self.name}", suberror_code={self.suberror_code})'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class YummyRateLimitError(YummyAPIError):
|
|
23
|
+
def __init__(self, msg: str):
|
|
24
|
+
super().__init__(msg, 429, 'Rate limit exceeded', 'Rate limit exceeded')
|
|
25
|
+
|
|
26
|
+
def __repr__(self):
|
|
27
|
+
return f'YummyRateLimitError(message="{self.message}")'
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class YummyNotFoundError(YummyAPIError):
|
|
31
|
+
def __init__(self, msg: str):
|
|
32
|
+
super().__init__(msg, 404, 'Not found', 'Not found')
|
|
33
|
+
|
|
34
|
+
def __repr__(self):
|
|
35
|
+
return f'YummyNotFoundError(message="{self.message}")'
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class YummyResponseParseFailed(YummyError):
|
|
39
|
+
def __init__(self, exception: Exception):
|
|
40
|
+
self.sub_error = exception
|
|
41
|
+
super().__init__(f'Failed to parse the response: {exception}')
|
|
42
|
+
|
|
43
|
+
def __repr__(self):
|
|
44
|
+
return f'YummyResponseParseFailed(message="{self.message}", sub_error={self.sub_error!r})'
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import aiohttp
|
|
2
|
+
|
|
3
|
+
from .kodik import KodikVideoParser
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def get_parser(iframe_url: str, session: aiohttp.ClientSession, url_from: str):
|
|
7
|
+
if "kodik" in iframe_url:
|
|
8
|
+
return KodikVideoParser(iframe_url, session, url_from)
|
|
9
|
+
raise NotImplemented(f"Parser not implemented: {iframe_url}")
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
from urllib.parse import urlparse, urljoin
|
|
3
|
+
|
|
4
|
+
import aiohttp
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Quality:
|
|
8
|
+
def __init__(self, url: str, ref: str) -> None:
|
|
9
|
+
self.url = url
|
|
10
|
+
self.ref = ref
|
|
11
|
+
|
|
12
|
+
def __str__(self):
|
|
13
|
+
return self.url
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Qualities:
|
|
17
|
+
def __init__(self):
|
|
18
|
+
self.p360 = self.p720 = self.p480 = self.p1080 = None
|
|
19
|
+
|
|
20
|
+
p360: Quality | None
|
|
21
|
+
p480: Quality | None
|
|
22
|
+
p720: Quality | None
|
|
23
|
+
p1080: Quality | None
|
|
24
|
+
p240: Quality | None
|
|
25
|
+
|
|
26
|
+
def set(self, key: str, q: Quality):
|
|
27
|
+
match key:
|
|
28
|
+
case '240':
|
|
29
|
+
self.p240 = q
|
|
30
|
+
return
|
|
31
|
+
case "360":
|
|
32
|
+
self.p360 = q
|
|
33
|
+
return
|
|
34
|
+
case "480":
|
|
35
|
+
self.p480 = q
|
|
36
|
+
return
|
|
37
|
+
case "720":
|
|
38
|
+
self.p720 = q
|
|
39
|
+
return
|
|
40
|
+
case "1080":
|
|
41
|
+
self.p1080 = q
|
|
42
|
+
return
|
|
43
|
+
raise KeyError(f"Key {key} not found in qualities")
|
|
44
|
+
|
|
45
|
+
def __str__(self):
|
|
46
|
+
return f'Qualities (360="{self.p360}", 480="{self.p480}", 720="{self.p720}", 1080="{self.p1080}")'
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class ParseAnswer:
|
|
50
|
+
def __init__(self, quality: Qualities, subtitle: str) -> None:
|
|
51
|
+
self.qualities = quality
|
|
52
|
+
self.subtitles = subtitle
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class AbstractParser(ABC):
|
|
56
|
+
def __init__(self, frame_url: str, session: aiohttp.ClientSession, url_from: str):
|
|
57
|
+
self.request = session
|
|
58
|
+
self.frame_url = frame_url
|
|
59
|
+
self.url_from = url_from
|
|
60
|
+
|
|
61
|
+
async def parse(self) -> ParseAnswer:
|
|
62
|
+
raise NotImplementedError("Abstract Parser must be implement")
|
|
63
|
+
|
|
64
|
+
@staticmethod
|
|
65
|
+
def get_good_src(src: str, parent: str):
|
|
66
|
+
if src.startswith("//"):
|
|
67
|
+
src = "https:" + src
|
|
68
|
+
elif src.startswith("/"):
|
|
69
|
+
parent_url = urlparse(parent)
|
|
70
|
+
src = urljoin(f"{parent_url.scheme or 'https'}://{parent_url.netloc}", src)
|
|
71
|
+
elif not src.startswith("http"):
|
|
72
|
+
parent_url = urlparse(parent)
|
|
73
|
+
final_src = f"https://{parent_url.netloc}{parent_url.path}"
|
|
74
|
+
if not final_src.endswith("/"):
|
|
75
|
+
final_src = final_src[:final_src.rfind("/") + 1]
|
|
76
|
+
src = urljoin(final_src, src)
|
|
77
|
+
return src
|
|
78
|
+
|
|
79
|
+
async def load_frame_from_url(self, url: str, ref: str = None):
|
|
80
|
+
if ref is None: ref = self.url_from
|
|
81
|
+
url = self.get_good_src(url, '')
|
|
82
|
+
async with self.request.get(url, headers={
|
|
83
|
+
'Referer': ref,
|
|
84
|
+
'Upgrade-Insecure-Requests': '1',
|
|
85
|
+
'Sec-Fetch-Site': 'cross-site',
|
|
86
|
+
'Sec-Fetch-Dest': 'iframe',
|
|
87
|
+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8'
|
|
88
|
+
}) as response:
|
|
89
|
+
ans = await response.text('utf-8')
|
|
90
|
+
return ans
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .downloader import KodikVideoParser
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import re
|
|
3
|
+
from typing import Dict
|
|
4
|
+
|
|
5
|
+
import aiohttp
|
|
6
|
+
from bs4 import BeautifulSoup
|
|
7
|
+
|
|
8
|
+
from ..abstract_parser import AbstractParser, Quality, Qualities
|
|
9
|
+
from ..utils import InvalidHtmlFormatException
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class KodikVideoParser(AbstractParser):
|
|
13
|
+
def __init__(self, frame_url: str, session: aiohttp.ClientSession, url_from: str):
|
|
14
|
+
super().__init__(frame_url, session, url_from)
|
|
15
|
+
self.video_get_vars: Dict[str, str] = {}
|
|
16
|
+
self.video_get_json_params: Dict[str, str] = {}
|
|
17
|
+
self.json_url: str = None
|
|
18
|
+
|
|
19
|
+
async def parse(self) -> Qualities:
|
|
20
|
+
await self.load_params_from_html()
|
|
21
|
+
await self.set_def_json_params()
|
|
22
|
+
ans = await self.get_info_from_json()
|
|
23
|
+
return ans
|
|
24
|
+
|
|
25
|
+
async def get_info_from_json(self):
|
|
26
|
+
json_data = await self.request.post(
|
|
27
|
+
self.json_url, data=self.video_get_json_params,
|
|
28
|
+
headers={
|
|
29
|
+
'Referer': self.frame_url,
|
|
30
|
+
'Origin': 'https://kodik.biz',
|
|
31
|
+
'TE': 'trailers',
|
|
32
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
33
|
+
'Sec-Fetch-Dest': 'empty',
|
|
34
|
+
'Sec-Fetch-Mode': 'cors',
|
|
35
|
+
'Sec-Fetch-Site': 'same-origin',
|
|
36
|
+
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
|
37
|
+
}
|
|
38
|
+
)
|
|
39
|
+
json_data = await json_data.json(content_type=None)
|
|
40
|
+
links = json_data["links"]
|
|
41
|
+
ans = Qualities()
|
|
42
|
+
for key, array in links.items():
|
|
43
|
+
m3u8_url = self.get_good_src(self.decode_url(array[0]["src"]), self.frame_url)
|
|
44
|
+
q = Quality(m3u8_url, self.frame_url)
|
|
45
|
+
ans.set(key, q)
|
|
46
|
+
return ans
|
|
47
|
+
|
|
48
|
+
async def set_def_json_params(self):
|
|
49
|
+
self.video_get_json_params["bad_user"] = "false"
|
|
50
|
+
self.video_get_json_params.update(self.video_get_vars)
|
|
51
|
+
self.json_url = self.get_good_src(self.POST_SRC, self.frame_url)
|
|
52
|
+
self.video_get_json_params['d'] = 'yummyani.me'
|
|
53
|
+
|
|
54
|
+
async def load_params_from_html(self):
|
|
55
|
+
html = await self.load_frame_from_url(self.frame_url)
|
|
56
|
+
self.url_from = self.frame_url
|
|
57
|
+
soup = BeautifulSoup(html, 'html.parser')
|
|
58
|
+
for el in soup.find_all('script'):
|
|
59
|
+
text = (el.string or '').strip()
|
|
60
|
+
if text:
|
|
61
|
+
m = re.findall(self.find_params_pattern, text)
|
|
62
|
+
for (key, value) in m:
|
|
63
|
+
self.video_get_vars[key] = value
|
|
64
|
+
|
|
65
|
+
m = re.search(r"videoInfo\.hash ?= ?['\"](.+?)['\"]", text)
|
|
66
|
+
if m:
|
|
67
|
+
value = m.group(1)
|
|
68
|
+
self.video_get_vars["hash"] = value
|
|
69
|
+
|
|
70
|
+
if not self.video_get_vars:
|
|
71
|
+
raise InvalidHtmlFormatException("Html is invalid - no params in html")
|
|
72
|
+
|
|
73
|
+
async def load_frame_url_from_first_frame(self):
|
|
74
|
+
url = self.frame_url
|
|
75
|
+
data = await self.load_frame_from_url(url)
|
|
76
|
+
match = re.search(self.find_url_pattern, data)
|
|
77
|
+
if not match:
|
|
78
|
+
raise InvalidHtmlFormatException("Html is invalid - no src in html")
|
|
79
|
+
self.url_from = self.frame_url
|
|
80
|
+
self.frame_url = match.group(1)
|
|
81
|
+
if self.frame_url is None:
|
|
82
|
+
raise InvalidHtmlFormatException("HTML is invalid - frame url is null")
|
|
83
|
+
if self.frame_url.startswith("//"):
|
|
84
|
+
self.frame_url = "https:" + self.frame_url
|
|
85
|
+
elif self.frame_url.startswith("/"):
|
|
86
|
+
for i in url.split("/"):
|
|
87
|
+
if i and i != "http:" and i != "https:":
|
|
88
|
+
self.frame_url = "https://" + i + self.frame_url
|
|
89
|
+
break
|
|
90
|
+
|
|
91
|
+
@staticmethod
|
|
92
|
+
def decode_url(src):
|
|
93
|
+
try:
|
|
94
|
+
ans = re.sub(
|
|
95
|
+
r'[a-zA-Z]',
|
|
96
|
+
KodikVideoParser.LAMBDA,
|
|
97
|
+
src
|
|
98
|
+
)
|
|
99
|
+
data = base64.b64decode(ans)
|
|
100
|
+
return data.decode('ISO-8859-1')
|
|
101
|
+
except Exception:
|
|
102
|
+
return src
|
|
103
|
+
|
|
104
|
+
LAMBDA = lambda e: chr(
|
|
105
|
+
(ord(e.group()) - 13) if (
|
|
106
|
+
(e.group() <= 'Z' and ord(e.group()) + 13 > ord('Z')) or ord(e.group()) + 13 > ord('z'))
|
|
107
|
+
else ord(e.group()) + 13
|
|
108
|
+
)
|
|
109
|
+
POST_SRC = "/ftor"
|
|
110
|
+
find_url_pattern = re.compile(r"\.src ?= ?\\?[\"|'](.+?)\\?[\"|']")
|
|
111
|
+
find_params_pattern = re.compile(r"([a-zA-Z0-9_]+?)\s?=\s?[\"|']([^'\"]+?)[\"|']")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .anime import Anime
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from ..structs import YummyAnswer
|
|
4
|
+
|
|
5
|
+
if typing.TYPE_CHECKING:
|
|
6
|
+
from ..api import YummyApi
|
|
7
|
+
|
|
8
|
+
T = typing.TypeVar('T')
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class IApiMethods:
|
|
12
|
+
def __init__(self, api: 'YummyApi'):
|
|
13
|
+
self.api = api
|
|
14
|
+
|
|
15
|
+
async def method(self, path: str, method: str, data: dict | None = None, type: typing.Type[T] = None) -> YummyAnswer[T]:
|
|
16
|
+
return await self.api.method(path, method, data, type=type)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from ._abs import *
|
|
2
|
+
from ..structs import IOneAnimeJson, YummyAnswer, ITrailerJson, AnimeRateResponse, IAnimeRateResponse, UserListResponse
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class AnimeList(IApiMethods):
|
|
6
|
+
async def set_it(self, anime_id: int, list: int, date: int = None):
|
|
7
|
+
data = {'date': date} if date else {}
|
|
8
|
+
return await self.method(f'/anime/{anime_id}/list', 'PUT', {**{'list': list}, **data})
|
|
9
|
+
|
|
10
|
+
async def set_favorite(self, anime_id: int, date: int = None):
|
|
11
|
+
return await self.method(f'/anime/{anime_id}/list/fav', 'PUT', {'date': date} if date else {})
|
|
12
|
+
|
|
13
|
+
async def remove_favorite(self, anime_id: int):
|
|
14
|
+
return await self.method(f'/anime/{anime_id}/list/fav', 'DELETE')
|
|
15
|
+
|
|
16
|
+
async def remove_it(self, anime_id: int):
|
|
17
|
+
return await self.method(f'/anime/{anime_id}/list', 'DELETE')
|
|
18
|
+
|
|
19
|
+
async def get_users_lists(self, anime_id: int):
|
|
20
|
+
return await self.method(f'/anime/{anime_id}/lists', 'GET', type=list[UserListResponse])
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class AnimeRate(IApiMethods):
|
|
24
|
+
async def set_rate(self, anime_id: int, rate: int):
|
|
25
|
+
return await self.method(f'/anime/{anime_id}/rate', 'PUT', {'rate': rate}, type=AnimeRateResponse)
|
|
26
|
+
|
|
27
|
+
async def remove_rate(self, anime_id: int):
|
|
28
|
+
return await self.method(f'/anime/{anime_id}/rate', 'DELETE', type=AnimeRateResponse)
|
|
29
|
+
|
|
30
|
+
async def get_anime_rates(self, anime_id: int):
|
|
31
|
+
return await self.method(f'/anime/{anime_id}/rates', 'GET', type=list[IAnimeRateResponse])
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Trailers(IApiMethods):
|
|
35
|
+
async def get(self, anime_id: int):
|
|
36
|
+
return await self.method(f'/anime/{anime_id}/trailers', 'GET', type=list[ITrailerJson])
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class Anime(IApiMethods):
|
|
40
|
+
def __init__(self, api: 'YummyApi'):
|
|
41
|
+
super().__init__(api)
|
|
42
|
+
self.list = AnimeList(self.api)
|
|
43
|
+
self.rate = AnimeRate(self.api)
|
|
44
|
+
self.trailers = Trailers(self.api)
|
|
45
|
+
|
|
46
|
+
async def get(self, id: str | int, need_videos: bool = False) -> YummyAnswer[IOneAnimeJson | None]:
|
|
47
|
+
return await self.method(
|
|
48
|
+
f'/anime/{id}', 'GET', {} if not need_videos else {'need_videos': 1},
|
|
49
|
+
type=IOneAnimeJson
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
async def search(self, query: str, limit: int = 5, offset: int = 0) -> YummyAnswer[list[IOneAnimeJson]]:
|
|
53
|
+
return await self.method('/search', 'GET', {'q': query, 'limit': limit, 'offset': offset},
|
|
54
|
+
type=list[IOneAnimeJson])
|
|
55
|
+
|
|
56
|
+
async def get_recommendations(self, anime_id: int) -> YummyAnswer[list[IOneAnimeJson]]:
|
|
57
|
+
return await self.method(f'/anime/{anime_id}/recommendations', 'GET', type=list[IOneAnimeJson])
|
|
58
|
+
|
|
59
|
+
async def do_not_recommend(self, anime_id: int):
|
|
60
|
+
return await self.method(f'/anime/{anime_id}/recommend', 'DELETE', type=bool)
|
|
61
|
+
|
|
62
|
+
async def recommend(self, anime_id: int):
|
|
63
|
+
return await self.method(f'/anime/{anime_id}/recommend', 'PUT', type=bool)
|
|
64
|
+
|
|
65
|
+
async def filter(self, filters: dict):
|
|
66
|
+
return await self.method('/anime', 'GET', filters, type=list[IOneAnimeJson])
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import typing
|
|
3
|
+
import warnings
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AbsDict:
|
|
7
|
+
__annotations__ = {}
|
|
8
|
+
|
|
9
|
+
def __init__(self, __data: dict={}, **kwargs):
|
|
10
|
+
data = {**__data, **kwargs}
|
|
11
|
+
self._parse_annotations(data)
|
|
12
|
+
|
|
13
|
+
@classmethod
|
|
14
|
+
def get_annotations(cls):
|
|
15
|
+
d = {}
|
|
16
|
+
for c in cls.mro():
|
|
17
|
+
try:
|
|
18
|
+
d.update(**c.__annotations__)
|
|
19
|
+
except AttributeError:
|
|
20
|
+
# object, at least, has no __annotations__ attribute.
|
|
21
|
+
pass
|
|
22
|
+
return d
|
|
23
|
+
|
|
24
|
+
def _parse_annotations(self, data: dict):
|
|
25
|
+
annotations = self.get_annotations()
|
|
26
|
+
for i in data:
|
|
27
|
+
setattr(self, self.format_name(i), self._format(annotations, i, data[i]))
|
|
28
|
+
|
|
29
|
+
def _format(self, annotations: dict, name: str, element: typing.Any):
|
|
30
|
+
if element is None: return None
|
|
31
|
+
if name in annotations:
|
|
32
|
+
if isinstance(element, list) and annotations[name] is not list and annotations[name].__args__:
|
|
33
|
+
annotations_new = {'z': annotations[name].__args__[0]}
|
|
34
|
+
name = 'z'
|
|
35
|
+
return [self._format(annotations_new, name, i) for i in element]
|
|
36
|
+
return annotations[name](element)
|
|
37
|
+
if isinstance(element, (str, int, float)):
|
|
38
|
+
return element
|
|
39
|
+
elif isinstance(element, dict):
|
|
40
|
+
warnings.warn(f"Unknown type for {name} in {self.__class__.__name__}")
|
|
41
|
+
return AbsDict(element)
|
|
42
|
+
warnings.warn(f"Unknown type for {name} in {self.__class__.__name__}")
|
|
43
|
+
return element
|
|
44
|
+
|
|
45
|
+
@staticmethod
|
|
46
|
+
def format_name(i):
|
|
47
|
+
if i == 'class':
|
|
48
|
+
return '_class'
|
|
49
|
+
return i
|
|
50
|
+
def __repr__(self):
|
|
51
|
+
def format_it(value=None):
|
|
52
|
+
if isinstance(value, AbsDict):
|
|
53
|
+
return value.__repr__()
|
|
54
|
+
if isinstance(value, list):
|
|
55
|
+
if not value: return f'[]'
|
|
56
|
+
return f'[{", ".join([format_it(q) for q in value])}]'
|
|
57
|
+
return repr(value)
|
|
58
|
+
|
|
59
|
+
return f'''{self.__class__.__name__}({', '.join([f'{j}={format_it(getattr(self, j))}' for j in self.__dict__])})'''
|
|
60
|
+
|
|
61
|
+
def __str__(self, i=0):
|
|
62
|
+
|
|
63
|
+
def format_it(i, value=None):
|
|
64
|
+
tabs = ('\t' * (i + 2))
|
|
65
|
+
sep = ',\n' + tabs
|
|
66
|
+
if isinstance(value, AbsDict):
|
|
67
|
+
return value.__str__(i + 1)
|
|
68
|
+
if isinstance(value, list):
|
|
69
|
+
if not value: return f'[]'
|
|
70
|
+
return f'[\n{tabs}{sep.join([format_it(i + 1, q) for q in value])}\n{tabs[:-1]}]'
|
|
71
|
+
return repr(value)
|
|
72
|
+
tabs = ('\t' * (i + 1))
|
|
73
|
+
sep = ',\n' + tabs
|
|
74
|
+
|
|
75
|
+
return f'''{self.__class__.__name__}(
|
|
76
|
+
{tabs}{sep.join([f'{j}={format_it(i, getattr(self, j))}' for j in self.__dict__])}
|
|
77
|
+
{tabs[:-1]})'''
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class Timing:
|
|
81
|
+
def __init__(self, name: str, duration_ms: float, description: str = ''):
|
|
82
|
+
self.name = name
|
|
83
|
+
self.duration = duration_ms / 1000
|
|
84
|
+
self.description = description
|
|
85
|
+
|
|
86
|
+
def __repr__(self):
|
|
87
|
+
return f'<Timing {self.name} {self.duration}s, desc="{self.description}">'
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
T = typing.TypeVar("T")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class YummyAnswer(typing.Generic[T]):
|
|
94
|
+
def __init__(self, data: T, timings: list[Timing] = None):
|
|
95
|
+
self.response = data
|
|
96
|
+
self.timings = timings or []
|
|
97
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
from ..structs import AbsDict
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class IAnimeType(AbsDict):
|
|
7
|
+
value: int
|
|
8
|
+
name: str
|
|
9
|
+
shortname: str
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AnimeStatus(Enum):
|
|
13
|
+
RELEASED = 'released'
|
|
14
|
+
ONGOING = 'ongoing'
|
|
15
|
+
ANNOUNCEMENT = 'announcement'
|
|
16
|
+
UNKNOWN = 'Unknown'
|
|
17
|
+
|
|
18
|
+
def __repr__(self):
|
|
19
|
+
return f'AnimeStatus({self.value!r})'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class WorldartType(Enum):
|
|
23
|
+
ANIMATION = 'animation'
|
|
24
|
+
CINEMA = 'cinema'
|
|
25
|
+
|
|
26
|
+
def __repr__(self):
|
|
27
|
+
return f'WorldartType({self.value!r})'
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
from ._base import AbsDict
|
|
2
|
+
from ._enums import AnimeStatus, IAnimeType, WorldartType
|
|
3
|
+
from .video import IAnimeVideo
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class IPosterJson(AbsDict):
|
|
7
|
+
def __init__(self, data: dict = {}, **kwargs):
|
|
8
|
+
for i in data.copy():
|
|
9
|
+
if data[i].startswith('//'): data[i] = 'https:' + data[i]
|
|
10
|
+
for i in kwargs:
|
|
11
|
+
if kwargs[i].startswith('//'): kwargs[i] = 'https:' + data[i]
|
|
12
|
+
super().__init__(data, **kwargs)
|
|
13
|
+
|
|
14
|
+
"""
|
|
15
|
+
Small: 33x47
|
|
16
|
+
"""
|
|
17
|
+
small: str
|
|
18
|
+
"""
|
|
19
|
+
Medium: 184x260px
|
|
20
|
+
"""
|
|
21
|
+
medium: str
|
|
22
|
+
"""
|
|
23
|
+
Big: 250x350px
|
|
24
|
+
"""
|
|
25
|
+
big: str
|
|
26
|
+
"""
|
|
27
|
+
Fullsize: maximum dimensions
|
|
28
|
+
"""
|
|
29
|
+
fullsize: str
|
|
30
|
+
"""
|
|
31
|
+
Huge: 400x560
|
|
32
|
+
"""
|
|
33
|
+
huge: str
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def sizes(self):
|
|
37
|
+
return {
|
|
38
|
+
(33, 47): self.small,
|
|
39
|
+
(184, 260): self.medium,
|
|
40
|
+
(250, 350): self.big,
|
|
41
|
+
(400, 560): self.huge,
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
def for_size(self, width: int, height: int):
|
|
45
|
+
for i in self.sizes:
|
|
46
|
+
if i[0] >= width - 5 and i[1] >= height - 5:
|
|
47
|
+
return self.sizes[i]
|
|
48
|
+
return self.fullsize
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class AnimeRating(AbsDict):
|
|
52
|
+
counters: int
|
|
53
|
+
average: float
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class IAnimeRateResponse(AbsDict):
|
|
57
|
+
rating: int
|
|
58
|
+
count: int
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class UserListResponse(AbsDict):
|
|
62
|
+
list_id: int
|
|
63
|
+
count: int
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class AnimeRemoteIds(AbsDict):
|
|
67
|
+
"""
|
|
68
|
+
A class to represent the remote IDs of an anime from various sources.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
worldart_id: int # The ID of the anime on World Art.
|
|
72
|
+
worldart_type: WorldartType = None # The type of the anime on World Art. It's an instance of the `WorldartType` enum.
|
|
73
|
+
shikimori_id: int # The ID of the anime on Shikimori.
|
|
74
|
+
sr_id: int = None # The ID of the anime on SovetRomantica.
|
|
75
|
+
kp_id: int = None # The ID of the anime on Kinopoisk.
|
|
76
|
+
myanimelist_id: int = None # The ID of the anime on MyAnimeList.
|
|
77
|
+
anilibria_alias: str = None # The alias of the anime on Anilibria.
|
|
78
|
+
anidub_id: int = None # The ID of the anime on AniDub.
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def worldart_url(self):
|
|
82
|
+
"""
|
|
83
|
+
Generates the URL for the anime on World Art based on the `worldart_id` and `worldart_type`.
|
|
84
|
+
If the `worldart_id` or `worldart_type` is not available, it returns `None`.
|
|
85
|
+
"""
|
|
86
|
+
if self.worldart_id and self.worldart_type:
|
|
87
|
+
return f'https://world-art.ru/{self.worldart_type}/{self.worldart_type}.php?id={self.worldart_id}'
|
|
88
|
+
return None
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def shikimori_url(self):
|
|
92
|
+
"""
|
|
93
|
+
Generates the URL for the anime on Shikimori based on the `shikimori_id`.
|
|
94
|
+
If the `shikimori_id` is not available, it returns `None`.
|
|
95
|
+
"""
|
|
96
|
+
if self.shikimori_id:
|
|
97
|
+
return f'https://shikimori.one/animes/{self.shikimori_id}'
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
def sr_url(self):
|
|
102
|
+
"""
|
|
103
|
+
Generates the URL for the anime on SovetRomantica based on the `sr_id`.
|
|
104
|
+
If the `sr_id` is not available, it returns `None`.
|
|
105
|
+
"""
|
|
106
|
+
if self.sr_id:
|
|
107
|
+
return f'https://sovetromantica.com/anime/{self.sr_id}'
|
|
108
|
+
return None
|
|
109
|
+
|
|
110
|
+
@property
|
|
111
|
+
def anilibria_url(self):
|
|
112
|
+
"""
|
|
113
|
+
Generates the URL for the anime on Anilibria based on the `anilibria_alias`.
|
|
114
|
+
If the `anilibria_alias` is not available, it returns `None`.
|
|
115
|
+
"""
|
|
116
|
+
if self.anilibria_alias:
|
|
117
|
+
return f'https://yummyanime.anilib.top/release/{self.anilibria_alias}.html'
|
|
118
|
+
return None
|
|
119
|
+
|
|
120
|
+
@property
|
|
121
|
+
def kinopoisk_url(self):
|
|
122
|
+
"""
|
|
123
|
+
Generates the URL for the anime on Kinopoisk based on the `kp_id`.
|
|
124
|
+
If the `kp_id` is not available, it returns `None`.
|
|
125
|
+
"""
|
|
126
|
+
if self.kp_id:
|
|
127
|
+
return f'https://www.kinopoisk.ru/film/{self.kp_id}'
|
|
128
|
+
return None
|
|
129
|
+
|
|
130
|
+
@property
|
|
131
|
+
def myanimelist_url(self):
|
|
132
|
+
"""
|
|
133
|
+
Generates the URL for the anime on MyAnimeList based on the `myanimelist_id`.
|
|
134
|
+
If the `myanimelist_id` is not available, it returns `None`.
|
|
135
|
+
"""
|
|
136
|
+
if self.myanimelist_id:
|
|
137
|
+
return f'https://myanimelist.net/anime/{self.myanimelist_id}'
|
|
138
|
+
return None
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class AnimeMinAge(AbsDict):
|
|
142
|
+
value: int
|
|
143
|
+
title: str = None
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class AnimeEpisodes(AbsDict):
|
|
147
|
+
aired: int
|
|
148
|
+
count: int
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class IListFav(AbsDict):
|
|
152
|
+
title: str
|
|
153
|
+
href: str
|
|
154
|
+
_class: str
|
|
155
|
+
id: str
|
|
156
|
+
icon: str
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class UserList(AbsDict):
|
|
160
|
+
is_fav: bool
|
|
161
|
+
list: IListFav = None
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
class IUserAnimeInfo(AbsDict):
|
|
165
|
+
rating: int
|
|
166
|
+
list: UserList
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
class IAnimeStatus(AbsDict):
|
|
170
|
+
value: int
|
|
171
|
+
alias: AnimeStatus
|
|
172
|
+
title: str
|
|
173
|
+
class_: str
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
class IAnimeJson(AbsDict):
|
|
177
|
+
anime_id: int
|
|
178
|
+
anime_url: str
|
|
179
|
+
poster: IPosterJson
|
|
180
|
+
title: str
|
|
181
|
+
description: str
|
|
182
|
+
|
|
183
|
+
def __eq__(self, other):
|
|
184
|
+
if isinstance(other, IAnimeJson):
|
|
185
|
+
return other.anime_id == self.anime_id
|
|
186
|
+
return False
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
class IOneAnimeSmallJson(IAnimeJson):
|
|
190
|
+
year: int
|
|
191
|
+
anime_status: IAnimeStatus
|
|
192
|
+
season: int
|
|
193
|
+
min_age: AnimeMinAge
|
|
194
|
+
user: IUserAnimeInfo
|
|
195
|
+
type: IAnimeType
|
|
196
|
+
views: int
|
|
197
|
+
rating: AnimeRating = None
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
class IAnimeVideoPreview(IAnimeJson):
|
|
201
|
+
time: int
|
|
202
|
+
type: IAnimeType
|
|
203
|
+
year: int
|
|
204
|
+
anime_status: IAnimeStatus
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
class ILikAble(AbsDict):
|
|
208
|
+
title: str
|
|
209
|
+
url: str
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
class IAnimeGenre(ILikAble):
|
|
213
|
+
id: int
|
|
214
|
+
alias: str
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
class IAnimeStudio(ILikAble):
|
|
218
|
+
id: int
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
class IAnimeCreator(ILikAble):
|
|
222
|
+
id: int
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
class IUserAnimeInfoList(IAnimeJson):
|
|
226
|
+
list: IListFav
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
class IViewingOrderData(AbsDict):
|
|
230
|
+
text: str
|
|
231
|
+
id: int
|
|
232
|
+
index: int
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
class IAnimeViewingOrder(IAnimeJson):
|
|
236
|
+
|
|
237
|
+
data: IViewingOrderData
|
|
238
|
+
anime_status: IAnimeStatus
|
|
239
|
+
type: IAnimeType
|
|
240
|
+
year: int
|
|
241
|
+
user: IUserAnimeInfoList
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
class IOneAnimeJson(IOneAnimeSmallJson):
|
|
245
|
+
original: str
|
|
246
|
+
other_titles: list
|
|
247
|
+
rating: AnimeRating
|
|
248
|
+
worldart_rating: float
|
|
249
|
+
shikimori_rating: float
|
|
250
|
+
kp_rating: float
|
|
251
|
+
myanimelist_rating: float
|
|
252
|
+
anidub_rating: float
|
|
253
|
+
remote_ids: AnimeRemoteIds
|
|
254
|
+
creators: list[IAnimeCreator]
|
|
255
|
+
studios: list[IAnimeStudio]
|
|
256
|
+
videos: list[IAnimeVideo] = None
|
|
257
|
+
genres: list[IAnimeGenre]
|
|
258
|
+
viewing_order: list[IAnimeViewingOrder]
|
|
259
|
+
translates: list
|
|
260
|
+
blocked_in: list
|
|
261
|
+
episodes: AnimeEpisodes
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
class AnimeRateResponse(AbsDict):
|
|
265
|
+
rating: float
|
|
266
|
+
votes: int
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from ..structs import AbsDict
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ITrailerJson(AbsDict):
|
|
5
|
+
def __init__(self, data: dict, **kwargs):
|
|
6
|
+
if data.get('iframe_url', '').startswith('//'):
|
|
7
|
+
data['iframe_url'] = 'https:' + data['iframe_url']
|
|
8
|
+
if kwargs.get('iframe_url', '').startswith('//'):
|
|
9
|
+
kwargs['iframe_url'] = 'https:' + kwargs['iframe_url']
|
|
10
|
+
|
|
11
|
+
trailer_id: int
|
|
12
|
+
anime_id: int
|
|
13
|
+
iframe_url: str
|
|
14
|
+
dubbing: str
|
|
15
|
+
player: str
|
|
16
|
+
number: str
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
import aiohttp
|
|
4
|
+
|
|
5
|
+
from ..parsers import get_parser
|
|
6
|
+
from ..structs import AbsDict
|
|
7
|
+
from ..parsers.abstract_parser import Qualities
|
|
8
|
+
|
|
9
|
+
if typing.TYPE_CHECKING:
|
|
10
|
+
from .anime import IAnimeJson
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class VideoData(AbsDict):
|
|
14
|
+
player: str
|
|
15
|
+
dubbing: str
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class IAnimeVideo(AbsDict):
|
|
19
|
+
def __init__(self, __data: dict = {}, **kwargs):
|
|
20
|
+
super().__init__(__data, **kwargs)
|
|
21
|
+
self.__qualities = None
|
|
22
|
+
|
|
23
|
+
video_id: int
|
|
24
|
+
data: VideoData
|
|
25
|
+
number: str
|
|
26
|
+
date: int
|
|
27
|
+
iframe_url: str
|
|
28
|
+
index: int
|
|
29
|
+
|
|
30
|
+
async def qualities(self, anime: 'IAnimeJson') -> Qualities:
|
|
31
|
+
if not hasattr(self, '__qualities'):
|
|
32
|
+
async with aiohttp.ClientSession(headers={
|
|
33
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
|
|
34
|
+
}) as session:
|
|
35
|
+
parser = get_parser(self.iframe_url, session,
|
|
36
|
+
f'https://yummyani.me/catalog/item/{anime.anime_url}')
|
|
37
|
+
self.__qualities: Qualities = await parser.parse()
|
|
38
|
+
return self.__qualities
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: yummyanime
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Yummy Anime API wrapper
|
|
5
|
+
Author-email: "IM.Corp" <root@yummyani.me>
|
|
6
|
+
Project-URL: Homepage, https://yummyani.me/
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: aiohttp~=3.9.5
|
|
14
|
+
Requires-Dist: json5~=0.9.25
|
|
15
|
+
Requires-Dist: beautifulsoup4~=4.12.3
|
|
16
|
+
Requires-Dist: gdown~=5.1.0
|
|
17
|
+
|
|
18
|
+
# YummyAnime API python
|
|
19
|
+
|
|
20
|
+
This is a wrapper around [yummyanime API](https://yummyani.me/api), written in Python async.
|
|
21
|
+
|
|
22
|
+
# Installation
|
|
23
|
+
```bash
|
|
24
|
+
pip install yummyanime
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
# Getting started
|
|
28
|
+
Before using the API, create DEV application [here](https://yummyani.me/dev/applications).
|
|
29
|
+
|
|
30
|
+
After that, start using it right away:
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
|
|
34
|
+
from yummyanime import YummyApi, Format
|
|
35
|
+
|
|
36
|
+
api = YummyApi("your_client_id from https://yummyani.me/dev/applications", Format.JSON)
|
|
37
|
+
|
|
38
|
+
async def main(url: str):
|
|
39
|
+
anime = await api.anime.get(url, need_videos=True)
|
|
40
|
+
print("Friren's anime title: ", anime.response.title)
|
|
41
|
+
video_kodik = next(i for i in anime.response.videos if "kodik." in i.iframe_url)
|
|
42
|
+
qualities = await video_kodik.qualities()
|
|
43
|
+
print("Link to 720p: ", qualities.p720)
|
|
44
|
+
print(main('provozhayushchaya-posledniy-put-friren'))
|
|
45
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
requirements.txt
|
|
5
|
+
src/yummyanime/__init__.py
|
|
6
|
+
src/yummyanime/api.py
|
|
7
|
+
src/yummyanime/enums.py
|
|
8
|
+
src/yummyanime/exceptions.py
|
|
9
|
+
src/yummyanime.egg-info/PKG-INFO
|
|
10
|
+
src/yummyanime.egg-info/SOURCES.txt
|
|
11
|
+
src/yummyanime.egg-info/dependency_links.txt
|
|
12
|
+
src/yummyanime.egg-info/requires.txt
|
|
13
|
+
src/yummyanime.egg-info/top_level.txt
|
|
14
|
+
src/yummyanime/parsers/__init__.py
|
|
15
|
+
src/yummyanime/parsers/abstract_parser.py
|
|
16
|
+
src/yummyanime/parsers/utils.py
|
|
17
|
+
src/yummyanime/parsers/kodik/__init__.py
|
|
18
|
+
src/yummyanime/parsers/kodik/downloader.py
|
|
19
|
+
src/yummyanime/routes/__init__.py
|
|
20
|
+
src/yummyanime/routes/_abs.py
|
|
21
|
+
src/yummyanime/routes/anime.py
|
|
22
|
+
src/yummyanime/routes/trailers.py
|
|
23
|
+
src/yummyanime/structs/__init__.py
|
|
24
|
+
src/yummyanime/structs/_base.py
|
|
25
|
+
src/yummyanime/structs/_enums.py
|
|
26
|
+
src/yummyanime/structs/anime.py
|
|
27
|
+
src/yummyanime/structs/trailers.py
|
|
28
|
+
src/yummyanime/structs/video.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
yummyanime
|