Create animeworld.py
Browse files- animeworld.py +104 -0
animeworld.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
from bs4 import BeautifulSoup
|
| 3 |
+
import datetime
|
| 4 |
+
import json
|
| 5 |
+
from info import get_info_kitsu
|
| 6 |
+
def get_mp4(anime_url,ismovie,episode):
|
| 7 |
+
response = requests.get(anime_url)
|
| 8 |
+
soup = BeautifulSoup(response.text,'lxml')
|
| 9 |
+
a_tag = soup.find('a', {'id': 'alternativeDownloadLink', 'class': 'm-1 btn btn-sm btn-primary'})
|
| 10 |
+
url = a_tag['href']
|
| 11 |
+
if ismovie == 1:
|
| 12 |
+
response = requests.head(url)
|
| 13 |
+
if response.status_code == 404:
|
| 14 |
+
url = None
|
| 15 |
+
return url
|
| 16 |
+
elif ismovie == 0:
|
| 17 |
+
parts = url.split("_Ep_")
|
| 18 |
+
base = parts[0]
|
| 19 |
+
episode_part = parts[1]
|
| 20 |
+
episode_number, rest = episode_part.split("_", 1)
|
| 21 |
+
num_digits = len(episode_number)
|
| 22 |
+
episode = int(episode)
|
| 23 |
+
new_episode_number = str(episode).zfill(num_digits)
|
| 24 |
+
url = f"{base}_Ep_{new_episode_number}_{rest}"
|
| 25 |
+
response = requests.head(url)
|
| 26 |
+
if response.status_code == 404:
|
| 27 |
+
url = None
|
| 28 |
+
return url
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def search(showname,date,ismovie,episode):
|
| 38 |
+
cookies = {
|
| 39 |
+
'sessionId': 's%3AtGSRfYcsIoaeV0nqFJgN69Zxixb_-uJU.fcNz%2FsJBiiP8v8TwthMN9%2FmynWFciI5gezZuz8CltyQ',
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
headers = {
|
| 43 |
+
'authority': 'www.animeworld.so',
|
| 44 |
+
'accept': 'application/json, text/javascript, */*; q=0.01',
|
| 45 |
+
'accept-language': 'it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7',
|
| 46 |
+
# 'content-length': '0',
|
| 47 |
+
# 'cookie': 'sessionId=s%3AtGSRfYcsIoaeV0nqFJgN69Zxixb_-uJU.fcNz%2FsJBiiP8v8TwthMN9%2FmynWFciI5gezZuz8CltyQ',
|
| 48 |
+
'csrf-token': 'oKFK43s4-BzfqPX27RlAORUd-iyiAfXyfDAo',
|
| 49 |
+
'origin': 'https://www.animeworld.so',
|
| 50 |
+
'referer': 'https://www.animeworld.so/',
|
| 51 |
+
'sec-ch-ua': '"Not-A.Brand";v="99", "Chromium";v="124"',
|
| 52 |
+
'sec-ch-ua-mobile': '?0',
|
| 53 |
+
'sec-ch-ua-platform': '"Android"',
|
| 54 |
+
'sec-fetch-dest': 'empty',
|
| 55 |
+
'sec-fetch-mode': 'cors',
|
| 56 |
+
'sec-fetch-site': 'same-origin',
|
| 57 |
+
'user-agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36',
|
| 58 |
+
'x-requested-with': 'XMLHttpRequest',
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
params = {
|
| 62 |
+
'keyword': showname,
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
response = requests.post('https://www.animeworld.so/api/search/v2', params=params, cookies=cookies, headers=headers)
|
| 66 |
+
months = {
|
| 67 |
+
"Gennaio": "January", "Febbraio": "February", "Marzo": "March",
|
| 68 |
+
"Aprile": "April", "Maggio": "May", "Giugno": "June",
|
| 69 |
+
"Luglio": "July", "Agosto": "August", "Settembre": "September",
|
| 70 |
+
"Ottobre": "October", "Novembre": "November", "Dicembre": "December"
|
| 71 |
+
}
|
| 72 |
+
data = json.loads(response.text)
|
| 73 |
+
final_urls = []
|
| 74 |
+
i = 0
|
| 75 |
+
for anime in data["animes"]:
|
| 76 |
+
release_date = anime["release"]
|
| 77 |
+
i+=1
|
| 78 |
+
for ita, eng in months.items():
|
| 79 |
+
release_date = release_date.replace(ita, eng)
|
| 80 |
+
release_date = datetime.datetime.strptime(release_date, "%d %B %Y")
|
| 81 |
+
release_date = release_date.strftime("%Y-%m-%d")
|
| 82 |
+
if release_date == date:
|
| 83 |
+
identifier = anime["identifier"]
|
| 84 |
+
link = anime["link"]
|
| 85 |
+
anime_url = f'https://animeworld.so/play/{link}.{identifier}'
|
| 86 |
+
final_url = get_mp4(anime_url,ismovie,episode)
|
| 87 |
+
final_urls.append(final_url)
|
| 88 |
+
if i == 2:
|
| 89 |
+
return final_urls
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def animeworld(id):
|
| 93 |
+
try:
|
| 94 |
+
kitsu_id = id.split(":")[1]
|
| 95 |
+
episode = id.split(":")[2]
|
| 96 |
+
ismovie = 1 if len(id.split(":")) == 2 else 0
|
| 97 |
+
showname,date = get_info_kitsu(kitsu_id)
|
| 98 |
+
final_urls = search(showname,date,ismovie,episode)
|
| 99 |
+
print(final_urls)
|
| 100 |
+
return final_urls
|
| 101 |
+
except:
|
| 102 |
+
print("Animeworld failed")
|
| 103 |
+
return None
|
| 104 |
+
animeworld("kitsi:12:10")
|