From 6d948fe377d7b43c6c240f7dbe7a696340743188 Mon Sep 17 00:00:00 2001 From: UrloMythus Date: Sun, 25 Aug 2024 21:03:05 +0200 Subject: [PATCH] Fixed Animeworld --- README.md | 2 +- animeworld.py | 66 ++++++++++++++++++++++++++++----------------------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index db78d00..e3e811d 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ To host this project with Hugging Face, go to the [linked](https://huggingface.c 8. Do not forget to add /manifest.json - 9. To update the remote server, you can either upload files manually, or you can connect the [repository locally](https://huggingface.co/docs/hub/en/repositories-getting-started) and use your file manager to do so. If you know how a Dockerfile works you could even clone the repository every time, although you will need to modify the config.json (by disabling both load_dotenv and FILMPERTUTTI). Plus remember that the README.MD of Hugging Face MUST NOT be changed or the app won't run. + 9. The Addon will update everytime you restart the service but you will need to change the config.json manually each time if there are any changes. If you just want to syncronize with the public instance then there is a button in the settings to do so. diff --git a/animeworld.py b/animeworld.py index 2fca4d2..be03224 100644 --- a/animeworld.py +++ b/animeworld.py @@ -3,30 +3,21 @@ from bs4 import BeautifulSoup import datetime import json from info import get_info_kitsu +import config +AW_DOMAIN = config.AW_DOMAIN def get_mp4(anime_url,ismovie,episode): response = requests.get(anime_url) soup = BeautifulSoup(response.text,'lxml') + episode_page = soup.find('a', {'data-episode-num':episode }) + episode_page = f'https://animeworld.{AW_DOMAIN}{episode_page["href"]}' + response = requests.get(episode_page) + soup = BeautifulSoup(response.text,'lxml') a_tag = soup.find('a', {'id': 'alternativeDownloadLink', 'class': 'm-1 btn btn-sm btn-primary'}) url = a_tag['href'] - if ismovie == 1: - response = requests.head(url) - if response.status_code == 404: + response = requests.head(url) + if response.status_code == 404: url = None - return url - elif ismovie == 0: - parts = url.split("_Ep_") - base = parts[0] - episode_part = parts[1] - episode_number, rest = episode_part.split("_", 1) - num_digits = len(episode_number) - episode = int(episode) - new_episode_number = str(episode).zfill(num_digits) - url = f"{base}_Ep_{new_episode_number}_{rest}" - response = requests.head(url) - if response.status_code == 404: - url = None - return url - + return url @@ -40,14 +31,14 @@ def search(showname,date,ismovie,episode): } headers = { - 'authority': 'www.animeworld.so', + 'authority': f'www.animeworld.{AW_DOMAIN}', 'accept': 'application/json, text/javascript, */*; q=0.01', 'accept-language': 'it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7', # 'content-length': '0', # 'cookie': 'sessionId=s%3AtGSRfYcsIoaeV0nqFJgN69Zxixb_-uJU.fcNz%2FsJBiiP8v8TwthMN9%2FmynWFciI5gezZuz8CltyQ', 'csrf-token': 'oKFK43s4-BzfqPX27RlAORUd-iyiAfXyfDAo', - 'origin': 'https://www.animeworld.so', - 'referer': 'https://www.animeworld.so/', + 'origin': f'https://www.animeworld.{AW_DOMAIN}', + 'referer': f'https://www.animeworld.{AW_DOMAIN}/', 'sec-ch-ua': '"Not-A.Brand";v="99", "Chromium";v="124"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Android"', @@ -62,7 +53,7 @@ def search(showname,date,ismovie,episode): 'keyword': showname, } - response = requests.post('https://www.animeworld.so/api/search/v2', params=params, cookies=cookies, headers=headers) + response = requests.post(f'https://www.animeworld.{AW_DOMAIN}/api/search/v2', params=params, cookies=cookies, headers=headers) months = { "Gennaio": "January", "Febbraio": "February", "Marzo": "March", "Aprile": "April", "Maggio": "May", "Giugno": "June", @@ -71,10 +62,8 @@ def search(showname,date,ismovie,episode): } data = json.loads(response.text) final_urls = [] - i = 0 for anime in data["animes"]: release_date = anime["release"] - i+=1 for ita, eng in months.items(): release_date = release_date.replace(ita, eng) release_date = datetime.datetime.strptime(release_date, "%d %B %Y") @@ -82,13 +71,30 @@ def search(showname,date,ismovie,episode): if release_date == date: identifier = anime["identifier"] link = anime["link"] - anime_url = f'https://animeworld.so/play/{link}.{identifier}' + anime_url = f'https://animeworld.{AW_DOMAIN}/play/{link}.{identifier}' final_url = get_mp4(anime_url,ismovie,episode) final_urls.append(final_url) - if i == 2: - return final_urls - - + break + showname = showname + " (ITA)" + params = { + 'keyword': showname, + } + response = requests.post(f'https://www.animeworld.{AW_DOMAIN}/api/search/v2', params=params, cookies=cookies, headers=headers) + data = json.loads(response.text) + for anime in data["animes"]: + release_date = anime["release"] + for ita, eng in months.items(): + release_date = release_date.replace(ita, eng) + release_date = datetime.datetime.strptime(release_date, "%d %B %Y") + release_date = release_date.strftime("%Y-%m-%d") + if release_date == date: + identifier = anime["identifier"] + link = anime["link"] + anime_url = f'https://animeworld.{AW_DOMAIN}/play/{link}.{identifier}' + final_url = get_mp4(anime_url,ismovie,episode) + final_urls.append(final_url) + break + return final_urls def animeworld(id): try: kitsu_id = id.split(":")[1] @@ -100,4 +106,4 @@ def animeworld(id): return final_urls except: print("Animeworld failed") - return None \ No newline at end of file + return None