diff --git a/app.py b/app.py index 79aa5149..f5a63fb4 100644 --- a/app.py +++ b/app.py @@ -7,9 +7,9 @@ app = Flask(__name__) -@app.errorhandler(404) -def error(): - return 'Something went wrong...\n\n Probably Anilist Is Down. Report To https://t.me/techshreyash' +@app.errorhandler(Exception) +def error(error=None): + return '

Something went wrong...\n\n Report To Owner

' @app.route('/') @@ -111,21 +111,38 @@ def get_anime(anime): typo = data.get('type') status = data.get('status') except: - data = GOGO.anime(x) - title = data[0] - synopsis = data[1] - names = data[2] - studios = data[3] - episodes = data[4] - genres = get_genre_html(data[5]) - img = data[6] - dub = data[7] - season = data[8] - year = data[9] - typo = data[10] - status = data[11] - displayAnime = 'Not Available' - ep_html = get_eps_html(anime, title, episodes) + try: + data = GOGO.anime(x) + title = data[0] + synopsis = data[1] + names = data[2] + studios = data[3] + episodes = data[4] + genres = get_genre_html(data[5]) + img = data[6] + dub = data[7] + season = data[8] + year = data[9] + typo = data[10] + status = data[11] + displayAnime = 'Not Available' + ep_html = get_eps_html(anime, title, episodes) + except: + data = GOGO.anime_api(x) + img = data.get('image') + title = data.get('title') + synopsis = data.get('description') + names = data.get('otherName') + studios = '?' + episodes = str(len(data.get('episodes'))) + genres = get_genre_html(data.get('genres')) + displayAnime = 'Not Available' + ep_html = get_eps_html(anime, title) + dub = data.get('subOrDub').upper() + season = data.get('type') + year = data.get('type') + typo = data.get('type') + status = data.get('status') html = render_template('anime.html', img=img, diff --git a/main.py b/main.py index 83eddf65..ce84c076 100644 --- a/main.py +++ b/main.py @@ -7,9 +7,9 @@ app = Flask(__name__) -@app.errorhandler(404) -def error(): - return 'Something went wrong...\n\n Probably Anilist Is Down. Report To https://t.me/techshreyash' +@app.errorhandler(Exception) +def error(error=None): + return '

Something went wrong...\n\n Report To Owner

' @app.route('/') @@ -111,21 +111,38 @@ def get_anime(anime): typo = data.get('type') status = data.get('status') except: - data = GOGO.anime(x) - title = data[0] - synopsis = data[1] - names = data[2] - studios = data[3] - episodes = data[4] - genres = get_genre_html(data[5]) - img = data[6] - dub = data[7] - season = data[8] - year = data[9] - typo = data[10] - status = data[11] - displayAnime = 'Not Available' - ep_html = get_eps_html(anime, title, episodes) + try: + data = GOGO.anime(x) + title = data[0] + synopsis = data[1] + names = data[2] + studios = data[3] + episodes = data[4] + genres = get_genre_html(data[5]) + img = data[6] + dub = data[7] + season = data[8] + year = data[9] + typo = data[10] + status = data[11] + displayAnime = 'Not Available' + ep_html = get_eps_html(anime, title, episodes) + except: + data = GOGO.anime_api(x) + img = data.get('image') + title = data.get('title') + synopsis = data.get('description') + names = data.get('otherName') + studios = '?' + episodes = str(len(data.get('episodes'))) + genres = get_genre_html(data.get('genres')) + displayAnime = 'Not Available' + ep_html = get_eps_html(anime, title) + dub = data.get('subOrDub').upper() + season = data.get('type') + year = data.get('type') + typo = data.get('type') + status = data.get('status') html = render_template('anime.html', img=img, diff --git a/programs/gogo.py b/programs/gogo.py index 1e0c0458..c220864a 100644 --- a/programs/gogo.py +++ b/programs/gogo.py @@ -1,5 +1,6 @@ import requests from bs4 import BeautifulSoup as bs +from programs.others import get_t_from_u from programs.vidstream import extract @@ -15,6 +16,8 @@ def __init__(self, url, img, lang, title, episode) -> None: class GoGoApi: def __init__(self) -> None: self.host = 'gogoanime.dk' + self.api = ['https://api-techshreyash.up.railway.app/', + 'https://api.consumet.org/'] def search(self, query, url_only=False): soup = bs(requests.get( @@ -40,6 +43,20 @@ def search(self, query, url_only=False): ) return results + def anime_api(self, anime): + anime = get_t_from_u(anime).strip().replace(' ', '-') + for host in self.api: + try: + url = host + 'anime/gogoanime/info/' + anime + data = requests.get(url) + if data.status_code == 200: + data = data.json() + if data: + break + except: + continue + return data + def anime(self, anime): soup = bs(requests.get( f'https://{self.host}/category/'+anime).content, 'html.parser')