diff --git a/src/gogoanimeapi.py b/src/gogoanimeapi.py index 116f833..f24b19b 100644 --- a/src/gogoanimeapi.py +++ b/src/gogoanimeapi.py @@ -1,6 +1,7 @@ from requests_html import HTMLSession from bs4 import BeautifulSoup import requests +import random class gogoanime(): @@ -11,6 +12,14 @@ def __init__(self, query, animeid, episode_num, genre_name, page): # Intialises self.genre_name = genre_name self.page = page +Random = random.choice(RANDOM) + +RANDOM = ( +"pokemon-xy", +"naruto", +"pokemondub", +) + def get_search_results(query): try: url1 = f"https://gogoanime.ai//search.html?keyword={query}" @@ -72,6 +81,46 @@ def get_anime_details(animeid): except requests.exceptions.ConnectionError: return {"status":"404", "reason":"Check the host's network Connection"} +def get_random_anime(): + try: + randomlink = 'https://gogoanime.ai/category/{random} + response = requests.get(randomlink) + plainText = response.text + soup = BeautifulSoup(plainText, "lxml") + source_url = soup.find("div", {"class": "anime_info_body_bg"}).img + imgg = source_url.get('src') + tit_url = soup.find("div", {"class": "anime_info_body_bg"}).h1.string + lis = soup.find_all('p', {"class": "type"}) + plot_sum = lis[1] + pl = plot_sum.get_text().split(':') + pl.remove(pl[0]) + sum = "" + plot_summary = sum.join(pl) + type_of_show = lis[0].a['title'] + ai = lis[2].find_all('a') # .find_all('title') + genres = [] + for link in ai: + genres.append(link.get('title')) + year1 = lis[3].get_text() + year2 = year1.split(" ") + year = year2[1] + status = lis[4].a.get_text() + oth_names = lis[5].get_text() + lnk = soup.find(id="episode_page") + ep_str = str(lnk.contents[-2]) + a_tag = ep_str.split("\n")[-2] + a_tag_sliced = a_tag[:-4].split(">") + last_ep_range = a_tag_sliced[-1] + y = last_ep_range.split("-") + ep_num = y[-1] + res_detail_search = {"title":f"{tit_url}", "year":f"{year}", "other_names":f"{oth_names}", "type":f"{type_of_show}", "status":f"{status}", "genre":f"{genres}", "episodes":f"{ep_num}", "image_url":f"{imgg}","plot_summary":f"{plot_summary}"} + return res_detail_search + except AttributeError: + return {"status":"400", "reason":"Invalid animeid"} + except requests.exceptions.ConnectionError: + return {"status":"404", "reason":"Check the host's network Connection"} + + def get_episodes_link(animeid, episode_num): try: animelink = f'https://gogoanime.ai/category/{animeid}'