Skip to content

Commit ab0ddbc

Browse files
committed
Fix base_url
1 parent 3791006 commit ab0ddbc

17 files changed

Lines changed: 205 additions & 128 deletions

README.it.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[![Static Badge](https://img.shields.io/badge/lang-italian-%239FA8DA)](https://github.com/MainKronos/AnimeWorld-API/blob/master/README.it.md)
1515

1616

17-
AnimeWorld-API is an unofficial library for [AnimeWorld](https://www.animeworld.so/) (Italian anime site).
17+
AnimeWorld-API is an unofficial library for [AnimeWorld](https://www.animeworld.ac/) (Italian anime site).
1818

1919
## Installazione
2020
Questa libreria richiede [Python 3.7](https://www.python.org/) o superiore.
@@ -34,13 +34,13 @@ print(res)
3434
```
3535
La funzione estituirà un dizionario contentente per chiave il nome dell'anime e per valore il link della pagina di animeworld.
3636
```python
37-
{'name': 'No Game no Life', 'link': 'https://www.animeworld.so/play/no-game-no-life.IJUH1', ...}
37+
{'name': 'No Game no Life', 'link': 'https://www.animeworld.ac/play/no-game-no-life.IJUH1E', ...}
3838
```
3939
È Possibile anche scaricare gli episodi di un anime.
4040
```python
4141
import animeworld as aw
4242

43-
anime = aw.Anime(link="https://www.animeworld.so/play/danmachi-3.Ydt8-")
43+
anime = aw.Anime(link="https://www.animeworld.ac/play/danmachi-3.Ydt8-")
4444
for episodio in anime.getEpisodes():
4545
print("Episodio Numero: ", episodio.number)
4646

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[![Static Badge](https://img.shields.io/badge/lang-italian-%239FA8DA)](https://github.com/MainKronos/AnimeWorld-API/blob/master/README.it.md)
1515

1616

17-
AnimeWorld-API is an unofficial library for [AnimeWorld](https://www.animeworld.so/) (Italian anime site).
17+
AnimeWorld-API is an unofficial library for [AnimeWorld](https://www.animeworld.ac/) (Italian anime site).
1818

1919
## Installation
2020
This library requires [Python 3.7](https://www.python.org/) or later.
@@ -34,13 +34,13 @@ print(res)
3434
```
3535
The function will return a dictionary with the anime name as the key and the link to the anime world page as the value.
3636
```python
37-
{'name': 'No Game no Life', 'link': 'https://www.animeworld.so/play/no-game-no-life.IJUH1', ...}
37+
{'name': 'No Game no Life', 'link': 'https://www.animeworld.ac/play/no-game-no-life.IJUH1E', ...}
3838
```
3939
You can also download episodes of an anime.
4040
```python
4141
import animeworld as aw
4242

43-
anime = aw.Anime(link="https://www.animeworld.so/play/danmachi-3.Ydt8-")
43+
anime = aw.Anime(link="https://www.animeworld.ac/play/danmachi-3.Ydt8-")
4444
for episode in anime.getEpisodes():
4545
print("Episode Number: ", episode.number)
4646

animeworld/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
AnimeWorld-API
33
"""
4-
from .utility import find
4+
from .utility import find, SES
55
from .anime import Anime
66
from .episodio import Episodio
77
from .servers.Server import Server

animeworld/anime.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def __init__(self, link: str):
2727
DeprecatedLibrary: Cambiamento del sito Animeworld.
2828
Error404: È una pagina 404.
2929
"""
30-
31-
self.link:str = link
30+
31+
self.link:str = httpx.URL(link).path
3232
self.html:bytes = self.__getHTML().content
3333
self.__check404()
3434

@@ -245,7 +245,7 @@ def getEpisodes(self, nums: Union[List[int], List[str]] = None) -> List[Episodio
245245
a_link = soupeddata.select_one('li.episode > a')
246246
if a_link is None: raise AnimeNotAvailable(self.getName())
247247

248-
self.link = "https://www.animeworld.so" + a_link.get('href')
248+
self.link = str(SES.build_url(a_link.get('href')))
249249

250250
provLegacy = self.__getServer() # vecchio sistema di cattura server
251251

@@ -260,18 +260,18 @@ def getEpisodes(self, nums: Union[List[int], List[str]] = None) -> List[Episodio
260260
if epID not in raw_eps:
261261
raw_eps[epID] = {
262262
'number': epNum,
263-
'link': f"https://www.animeworld.so/api/download/{epID}",
263+
'link': str(SES.build_url(f"/api/download/{epID}")),
264264
'legacy': [{
265265
"id": int(provID),
266266
"name": provLegacy[provID]["name"],
267-
"link": "https://www.animeworld.so" + data.get("href")
267+
"link": str(SES.build_url(data.get("href")))
268268
}]
269269
}
270270
else:
271271
raw_eps[epID]['legacy'].append({
272272
"id": int(provID),
273273
"name": provLegacy[provID]["name"],
274-
"link": "https://www.animeworld.so" + data.get("href")
274+
"link": str(SES.build_url(data.get("href")))
275275
})
276276

277277
return [

animeworld/servers/YouTube.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def fileLink(self) -> str:
2020
"""
2121

2222
anime_id = self.link.split("/")[-1]
23-
external_link = "https://www.animeworld.so/api/episode/serverPlayerAnimeWorld?id={}".format(anime_id)
23+
external_link = str(SES.build_url(f"/api/episode/serverPlayerAnimeWorld?id={anime_id}"))
2424

2525
sb_get = SES.get(self.link)
2626
sb_get.raise_for_status()

animeworld/utility.py

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,25 @@ class MySession(httpx.Client):
1313
"""
1414
Sessione httpx.
1515
"""
16-
def __init__(self) -> None:
17-
super().__init__(http2=True)
16+
17+
def __init__(self, *args, **kwargs) -> None:
18+
super().__init__(*args, **kwargs)
1819
self.headers.update({'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'})
1920
self.fixCookie()
2021

22+
def build_url(self, url: httpx.URL | str) -> httpx.URL:
23+
"""
24+
Unisce l'url con il base_url.
25+
"""
26+
return self._merge_url(url)
27+
2128
def fixCookie(self):
2229
"""Aggiunge il csrf_token all'headers."""
2330

2431
csrf_token = re.compile(br'<meta.*?id="csrf-token"\s*?content="(.*?)">')
2532
cookie = re.compile(br'document\.cookie\s*?=\s*?"(.+?)=(.+?)(\s*?;\s*?path=.+?)?"\s*?;')
2633
for _ in range(2): # numero di tentativi
27-
res = self.get("https://www.animeworld.so", follow_redirects=True)
34+
res = self.get("/", follow_redirects=True)
2835

2936
m = cookie.search(res.content)
3037
if m:
@@ -111,7 +118,7 @@ def find(keyword: str) -> List[Dict]:
111118
```
112119
"""
113120

114-
res = SES.post("https://www.animeworld.so/api/search/v2?", params = {"keyword": keyword}, follow_redirects=True)
121+
res = SES.post("/api/search/v2?", params = {"keyword": keyword}, follow_redirects=True)
115122

116123
data = res.json()
117124
if "error" in data: return []
@@ -126,34 +133,41 @@ def find(keyword: str) -> List[Dict]:
126133

127134
return [
128135
{
129-
"id": elem["id"],
130-
"name": elem["name"],
131-
"jtitle": elem["jtitle"],
132-
"studio": elem["studio"],
133-
"release": elem["release"],
134-
"episodes": int(elem["episodes"]) if elem["episodes"] is not None else None,
135-
"state": elem["state"],
136-
"story": elem["story"],
137-
"categories": elem["categories"],
138-
"image": elem["image"],
139-
"durationEpisodes": elem["durationEpisodes"],
140-
"link": f"https://www.animeworld.so/play/{elem['link']}.{elem['identifier']}" if elem['link'] is not None or elem['identifier'] is not None else None,
141-
"createdAt": elem["createdAt"],
142-
"language": elem["language"],
143-
"year": elem["year"],
144-
"dub": elem["dub"] != "0" if elem["dub"] is not None else None,
145-
"season": elem["season"],
146-
"totViews": elem["totViews"],
147-
"dayViews": elem["dayViews"],
148-
"weekViews": elem["weekViews"],
149-
"monthViews": elem["monthViews"],
150-
"malId": elem["malId"],
151-
"anilistId": elem["anilistId"],
152-
"mangaworldId": elem["mangaworldId"],
153-
"malVote": elem["malVote"],
154-
"trailer": elem["trailer"]
155-
}for elem in data
136+
"id": elem["id"],
137+
"name": elem["name"],
138+
"jtitle": elem["jtitle"],
139+
"studio": elem["studio"],
140+
"release": elem["release"],
141+
"episodes": int(elem["episodes"]) if elem["episodes"] is not None else None,
142+
"state": elem["state"],
143+
"story": elem["story"],
144+
"categories": elem["categories"],
145+
"image": elem["image"],
146+
"durationEpisodes": elem["durationEpisodes"],
147+
"link": str(SES.build_url(f"/play/{elem['link']}.{elem['identifier']}")) if elem['link'] is not None or elem['identifier'] is not None else None,
148+
"createdAt": elem["createdAt"],
149+
"language": elem["language"],
150+
"year": elem["year"],
151+
"dub": elem["dub"] != "0" if elem["dub"] is not None else None,
152+
"season": elem["season"],
153+
"totViews": elem["totViews"],
154+
"dayViews": elem["dayViews"],
155+
"weekViews": elem["weekViews"],
156+
"monthViews": elem["monthViews"],
157+
"malId": elem["malId"],
158+
"anilistId": elem["anilistId"],
159+
"mangaworldId": elem["mangaworldId"],
160+
"malVote": elem["malVote"],
161+
"trailer": elem["trailer"]
162+
} for elem in data
156163
]
157164

158-
SES = MySession() # sessione contenente Cookie e headers
159-
"Sessione httpx."
165+
SES = MySession(http2=True, base_url="https://www.animeworld.ac/") # sessione contenente Cookie e headers
166+
"""Sessione httpx.
167+
168+
Example:
169+
```py
170+
# Per cabiare il base_url:
171+
SES.base_url = "https://www.animeworld.ac"
172+
```
173+
"""

docs/api-reference/developer-interface.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ search:
55

66
# Developer Interface
77

8+
## Globals
9+
10+
### ::: animeworld.SES
11+
812
## Funzioni
913

1014
### ::: animeworld.find

docs/index.en.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ Now you can start searching for anime:
2121
>>> import animeworld as aw
2222
>>> res = aw.find("No game no life")
2323
>>> res
24-
{'name': 'No Game no Life', 'link': 'https://www.animeworld.so/play/no-game-no-life.IJUH1', ...}
24+
{'name': 'No Game no Life', 'link': 'https://www.animeworld.ac/play/no-game-no-life.IJUH1E', ...}
2525
```
2626

2727
And download episodes:
2828
```python
2929
>>> import animeworld as aw
30-
>>> anime = aw.Anime(link="https://www.animeworld.so/play/danmachi-3.Ydt8-")
30+
>>> # https://www.animeworld.ac/play/danmachi-3.Ydt8-
31+
>>> anime = aw.Anime(link="/play/danmachi-3.Ydt8-")
3132
>>> for episode in anime.getEpisodes():
3233
... print("Episode Number: ", episode.number)
3334
... if(episode.download()):

docs/index.it.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ Adesso puoi iniziare a cercare anime:
2020
>>> import animeworld as aw
2121
>>> res = aw.find("No game no life")
2222
>>> res
23-
{'name': 'No Game no Life', 'link': 'https://www.animeworld.so/play/no-game-no-life.IJUH1', ...}
23+
{'name': 'No Game no Life', 'link': 'https://www.animeworld.ac/play/no-game-no-life.IJUH1E', ...}
2424
```
2525

2626
E a scaricare episodi:
2727
```python
2828
>>> import animeworld as aw
29-
>>> anime = aw.Anime(link="https://www.animeworld.so/play/danmachi-3.Ydt8-")
29+
>>> # https://www.animeworld.ac/play/danmachi-3.Ydt8-
30+
>>> anime = aw.Anime(link="/play/danmachi-3.Ydt8-")
3031
>>> for episodio in anime.getEpisodes():
3132
... print("Episodio Numero: ", episodio.number)
3233
... if(episodio.download()):

docs/static/example.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ def my_hook(d):
2222

2323

2424
try:
25-
anime = aw.Anime(link="https://www.animeworld.so/play/tokyo-revengers-seiya-kessen-hen.tzgly")
25+
# Imposto il base_url per la sessione
26+
aw.SES.base_url = "https://www.animeworld.ac"
27+
28+
anime = aw.Anime(link="/play/tokyo-revengers-seiya-kessen-hen.tzgly")
2629

2730
print("Titolo:", anime.getName()) # Titolo dell'anime
2831

0 commit comments

Comments
 (0)