Skip to content

Commit

Permalink
Aggiornamento prestazioni
Browse files Browse the repository at this point in the history
Ottimizzata la parte della ricerca dei link degli episodi.
  • Loading branch information
MainKronos committed Apr 27, 2022
1 parent 4c7cb29 commit 62a14a2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 37 deletions.
59 changes: 26 additions & 33 deletions animeworld/anime.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,46 +169,39 @@ def getEpisodes(self) -> List[Episodio]: # Ritorna una lista di Episodi
]
```
"""
soupeddata = BeautifulSoup(self.html, "html.parser")
soupeddata = BeautifulSoup(self.html.decode('utf-8', 'ignore'), "html.parser")

a_link = soupeddata.select_one('li.episode > a')
if a_link is None: raise AnimeNotAvailable(self.getName())

self.link = "https://www.animeworld.tv" + a_link.get('href')

soupeddata = BeautifulSoup(self.__getHTML().content, "html.parser")

raw = {} # dati in formato semi-grezzo
eps = [] # Lista di Episodio()


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

raw = {}
for liElem in soupeddata.find_all("li", {"class": "episode"}):
aElem = liElem.find('a')
raw[aElem.get('data-episode-num')] = {
"episodeId": aElem.get('data-episode-id')
}

raw_eps = {}
for provID in provLegacy:
provLegacy[provID]["soup"] = soupeddata.find("div", {"class": "server", "data-name": str(provID)})

for epNum in raw:
epID = raw[epNum]["episodeId"]
legacy_links = []

for provID in provLegacy:
soup_link = provLegacy[provID]["soup"].find('a', {'data-episode-num': epNum})

if soup_link:
legacy_links.append({
"id": int(provID),
"name": provLegacy[provID]["name"],
"link": "https://www.animeworld.tv" + soup_link.get("href")
})


eps.append(Episodio(epNum, f"https://www.animeworld.tv/api/download/{epID}", legacy_links))

return eps
prov_soup = soupeddata.select_one(f"div[class*='server'][data-name='{provID}']")

for data in prov_soup.select('li.episode > a'):
epNum = data.get('data-episode-num')
epID = data.get('data-episode-id')

if epID not in raw_eps:
raw_eps[epID] = {
'number': epNum,
'link': f"https://www.animeworld.tv/api/download/{epID}",
'legacy': [{
"id": int(provID),
"name": provLegacy[provID]["name"],
"link": "https://www.animeworld.tv" + data.get("href")
}]
}
else:
raw_eps[epID]['legacy'].append({
"id": int(provID),
"name": provLegacy[provID]["name"],
"link": "https://www.animeworld.tv" + data.get("href")
})

return [Episodio(x['number'], x['link'], x['legacy']) for x in list(raw_eps.values())]
6 changes: 3 additions & 3 deletions documentation/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def my_hook(d):
Stampa una ProgressBar con tutte le informazioni di download.
"""
if d['status'] == 'downloading':
out = "{filename}:\n[{bar}][{percentage:^6.1%}]\n{total_bytes}/{downloaded_bytes} in {elapsed:%H:%M:%S} (ETA: {eta:%H:%M:%S})\x1B[3A"
out = "{filename}:\n[{bar}][{percentage:^6.1%}]\n{downloaded_bytes}/{total_bytes} in {elapsed:%H:%M:%S} (ETA: {eta:%H:%M:%S})\x1B[3A"

width = 70 # grandezza progressbar

Expand All @@ -22,7 +22,7 @@ def my_hook(d):


try:
anime = aw.Anime(link="https://www.animeworld.tv/play/jaku-chara-tomozaki-kun.RDPHq")
anime = aw.Anime(link="https://www.animeworld.tv/play/one-piece-subita.sORn4")

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

Expand All @@ -49,7 +49,7 @@ def my_hook(d):
for k in x.links:
print(f"\t{k.name} - {k.link}")

if x.number == '1':
if x.number == '1005':
x.download(hook=my_hook)
break
except (aw.DeprecatedLibrary, aw.Error404) as error:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="animeworld",
version="1.4.15",
version="1.4.16",
author="MainKronos",
description="AnimeWorld UNOFFICIAL API",
long_description=long_description,
Expand Down

0 comments on commit 62a14a2

Please sign in to comment.