Skip to content

Commit

Permalink
Ricerca anime
Browse files Browse the repository at this point in the history
Aggiunta la ricerca degli anime sfruttando le api interne a AnimeWorld
  • Loading branch information
MainKronos committed Jan 27, 2022
1 parent 9b0c951 commit 0f6c7ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
38 changes: 26 additions & 12 deletions animeworld/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@

## Function ##########################################

def find(animeName): # Deprecata
ret = {}

search = "https://www.animeworld.tv/search?keyword={}".format(animeName.replace(" ", "%20"))
sb_get = requests.get(search, headers = HDR)
soupeddata = BeautifulSoup(sb_get.content, "html.parser")

page_result = soupeddata.find("div", { "class" : "film-list" }).find_all("a", { "class" : "name" })
for x in page_result:
ret[x.get_text()] = f"https://www.animeworld.tv{x.get('href')}"

return ret

def HealthCheck(fun): # Controlla se la libreria è deprecata
def wrapper(*args, **kwargs):
Expand All @@ -38,6 +26,32 @@ def wrapper(*args, **kwargs):
raise DeprecatedLibrary(funName, errLine)
return wrapper

@HealthCheck
def find(keyword):
res = requests.get("https://www.animeworld.tv", headers = HDR)
cookies.update(res.cookies.get_dict())
soupeddata = BeautifulSoup(res.content, "html.parser")
myHDR = {"csrf-token": soupeddata.find('meta', {'id': 'csrf-token'}).get('content')}


res = requests.post("https://www.animeworld.tv/api/search/v2?", params = {"keyword": keyword} ,headers=myHDR, cookies=cookies)

data = res.json()["animes"]
data.sort(key=lambda a: a["dub"])

# with open("index.html", 'w') as f:
# json.dump(data, f, indent='\t')


if len(data) == 0:
return None
else:
return {
"name": data[0]["name"],
"link": f"https://www.animeworld.tv/play/{data[0]['link']}.{data[0]['identifier']}"
}


########################################################

## Class ###############################################
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", # Replace with your own username
version="1.4.5",
version="1.4.6",
author="MainKronos",
author_email="[email protected]",
description="AnimeWorld UNOFFICIAL API",
Expand Down

0 comments on commit 0f6c7ed

Please sign in to comment.