diff --git a/app.py b/app.py index 43df1245..0b2a7a33 100644 --- a/app.py +++ b/app.py @@ -10,20 +10,13 @@ @app.route('/') def home(): - update_views('home-animedex') html = render_template('home.html') - try: - div1 = get_trending_html() - except: - div1 = '' + div1 = get_trending_html() try: div2 = get_recent_html(GOGO.home()) except: div2 = '' - try: - sliders = slider_gen() - except: - sliders = '' + sliders = slider_gen() html = html.replace( 'MOST_POPULAR', @@ -35,6 +28,7 @@ def home(): 'SLIDERS', sliders ) + update_views('home-animedex') return html @@ -65,19 +59,20 @@ def get_embed(): @app.route('/episode//') def get_episode(anime, episode): + anime = get_t_from_u(anime) anime = anime.lower() + print(anime) + if anime.endswith('dub'): anime = anime[:-4] if anime.endswith('sub'): anime = anime[:-4] - - anime = get_t_from_u(anime) search = GOGO.search(anime, True) + s = GOGO.anime_api(search[0])['episodes'] + total_eps = len(s) + eps = GOGO.get_links(search[0], episode, s) + aid = search[0] - total_eps = GoGoApi().get_episodes(search[0]) - update_watch(search[0].strip()) - - eps = GOGO.get_links(search[0], episode) btn_html = get_selector_btns( f"/episode/{anime}/", int(episode), int(total_eps)) ep_html, iframe = episodeHtml(eps, f'{anime} - Episode {episode}') @@ -89,67 +84,63 @@ def get_episode(anime, episode): iframe=iframe ) + update_watch(aid) return temp.replace('PROSLO', btn_html).replace('SERVER', ep_html) @app.route('/anime/') def get_anime(anime): - x = anime - anime = anime.lower() - if anime.endswith('dub'): - anime = anime[:-4] - if anime.endswith('sub'): - anime = anime[:-4] - try: - data = Anilist.anime(get_t_from_u(anime)) - img = data.get('image') + data = GOGO.anime(anime) + 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] + try: + x = anime.lower() + if x.endswith('dub'): + x = x[:-4] + if x.endswith('sub'): + x = x[:-4] + x = get_t_from_u(x).replace('-', ' ') + displayAnime = animeRecHtml(Anilist().get_recommendation(x)) + except Exception as e: + print(e, displayAnime) + displayAnime = 'Not Available' + ep_html, watch = get_eps_html(anime, anime) + except: + anime = anime.lower() + if anime.endswith('dub'): + anime = anime[:-4] + if anime.endswith('sub'): + anime = anime[:-4] + anime = get_t_from_u(anime).replace('-', ' ') + data = Anilist().anime(anime) + + img = data.get('coverImage').get('medium').replace('small', 'medium') + if not img: + img = data.get('bannerImage') title = get_atitle(data.get('title')) synopsis = data.get('description') names = get_other_title(data.get('title')) - studios = get_studios(data.get('studios')) - episodes = str(data.get('totalEpisodes')) + studios = get_studios(data.get('studios').get('nodes')) + episodes = str(data.get('episodes')) genres = get_genre_html(data.get('genres')) - displayAnime = animeRecHtml(data.get('recommendations')) - ep_html = get_eps_html(anime, title) - dub = data.get('type') + displayAnime = animeRecHtml(data.get('recommendations').get('edges')) + ep_html, watch = get_eps_html(anime) + dub = data.get('format') season = data.get('season') - year = data.get('releaseDate') - typo = data.get('type') + year = data.get('seasonYear') + typo = data.get('format') status = data.get('status') - except: - 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, @@ -162,8 +153,8 @@ def get_anime(anime): year=year, ATYPE=typo, status=status, - animeURL=f'/anime/{x}', - WATCHNOW=f'/episode/{x}/1', + animeURL=f'/anime/{anime}', + WATCHNOW=f'/episode/{watch}', aid=anime ) @@ -171,6 +162,7 @@ def get_anime(anime): html = html.replace('EPISOS', ep_html) html = html.replace('DISPLAY_ANIME', displayAnime) html = html.replace('SYNOP', synopsis) + update_views(anime) return html @@ -193,4 +185,5 @@ def search_anime(): 'SEARCHED', display ) - return html \ No newline at end of file + update_views('search-animedex') + return html diff --git a/main.py b/main.py index f6f3bcf6..8121e9b6 100644 --- a/main.py +++ b/main.py @@ -10,20 +10,13 @@ @app.route('/') def home(): - update_views('home-animedex') html = render_template('home.html') - try: - div1 = get_trending_html() - except: - div1 = '' + div1 = get_trending_html() try: div2 = get_recent_html(GOGO.home()) except: div2 = '' - try: - sliders = slider_gen() - except: - sliders = '' + sliders = slider_gen() html = html.replace( 'MOST_POPULAR', @@ -35,6 +28,7 @@ def home(): 'SLIDERS', sliders ) + update_views('home-animedex') return html @@ -65,19 +59,20 @@ def get_embed(): @app.route('/episode//') def get_episode(anime, episode): + anime = get_t_from_u(anime) anime = anime.lower() + print(anime) + if anime.endswith('dub'): anime = anime[:-4] if anime.endswith('sub'): anime = anime[:-4] - - anime = get_t_from_u(anime) search = GOGO.search(anime, True) + s = GOGO.anime_api(search[0])['episodes'] + total_eps = len(s) + eps = GOGO.get_links(search[0], episode, s) + aid = search[0] - total_eps = GoGoApi().get_episodes(search[0]) - update_watch(search[0].strip()) - - eps = GOGO.get_links(search[0], episode) btn_html = get_selector_btns( f"/episode/{anime}/", int(episode), int(total_eps)) ep_html, iframe = episodeHtml(eps, f'{anime} - Episode {episode}') @@ -89,67 +84,63 @@ def get_episode(anime, episode): iframe=iframe ) + update_watch(aid) return temp.replace('PROSLO', btn_html).replace('SERVER', ep_html) @app.route('/anime/') def get_anime(anime): - x = anime - anime = anime.lower() - if anime.endswith('dub'): - anime = anime[:-4] - if anime.endswith('sub'): - anime = anime[:-4] - try: - data = Anilist.anime(get_t_from_u(anime)) - img = data.get('image') + data = GOGO.anime(anime) + 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] + try: + x = anime.lower() + if x.endswith('dub'): + x = x[:-4] + if x.endswith('sub'): + x = x[:-4] + x = get_t_from_u(x).replace('-', ' ') + displayAnime = animeRecHtml(Anilist().get_recommendation(x)) + except Exception as e: + print(e, displayAnime) + displayAnime = 'Not Available' + ep_html, watch = get_eps_html(anime, anime) + except: + anime = anime.lower() + if anime.endswith('dub'): + anime = anime[:-4] + if anime.endswith('sub'): + anime = anime[:-4] + anime = get_t_from_u(anime).replace('-', ' ') + data = Anilist().anime(anime) + + img = data.get('coverImage').get('medium').replace('small', 'medium') + if not img: + img = data.get('bannerImage') title = get_atitle(data.get('title')) synopsis = data.get('description') names = get_other_title(data.get('title')) - studios = get_studios(data.get('studios')) - episodes = str(data.get('totalEpisodes')) + studios = get_studios(data.get('studios').get('nodes')) + episodes = str(data.get('episodes')) genres = get_genre_html(data.get('genres')) - displayAnime = animeRecHtml(data.get('recommendations')) - ep_html = get_eps_html(anime, title) - dub = data.get('type') + displayAnime = animeRecHtml(data.get('recommendations').get('edges')) + ep_html, watch = get_eps_html(anime) + dub = data.get('format') season = data.get('season') - year = data.get('releaseDate') - typo = data.get('type') + year = data.get('seasonYear') + typo = data.get('format') status = data.get('status') - except: - 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, @@ -162,8 +153,8 @@ def get_anime(anime): year=year, ATYPE=typo, status=status, - animeURL=f'/anime/{x}', - WATCHNOW=f'/episode/{x}/1', + animeURL=f'/anime/{anime}', + WATCHNOW=f'/episode/{watch}', aid=anime ) @@ -171,6 +162,7 @@ def get_anime(anime): html = html.replace('EPISOS', ep_html) html = html.replace('DISPLAY_ANIME', displayAnime) html = html.replace('SYNOP', synopsis) + update_views(anime) return html @@ -193,8 +185,9 @@ def search_anime(): 'SEARCHED', display ) + update_views('search-animedex') return html if __name__ == '__main__': - app.run('0.0.0.0') + app.run('0.0.0.0', debug=True) diff --git a/programs/anilist.py b/programs/anilist.py index 5d73854a..2fa0ff6d 100644 --- a/programs/anilist.py +++ b/programs/anilist.py @@ -1,67 +1,181 @@ +from datetime import datetime import requests -hosts = ['https://api-techshreyash.up.railway.app/', - 'https://api.consumet.org/'] + +def get_season(future: bool = False): + k = datetime.now() + m = k.month + if future: + m = m+3 + y = k.year + if m > 12: + y = y+1 + if m in [1, 2, 3] or m > 12: + return 'WINTER', y + if m in [4, 5, 6]: + return 'SPRING', y + if m in [7, 8, 9]: + return 'SUMMER', y + if m in [10, 11, 12]: + return 'FALL', y class Anilist: - def trending(): - for host in hosts: - try: - data = requests.get(host + 'meta/anilist/trending') - except: - continue - if data.status_code == 200: - data = data.json() - results = data.get('results') - if results: - break - return results + def __init__(self) -> None: + + self.BROWSE_QUERY = """ +query ($s: MediaSeason, $y: Int, $sort: [MediaSort]) { + Page { + media (season: $s, seasonYear: $y, sort: $sort) { + title { + romaji + english + native + } + format + genres + episodes + bannerImage + coverImage{ + medium + } + type + status + description + } + } +} +""" + self.ANIME_QUERY = """ +query ($id: Int, $idMal: Int, $search: String) { + Media(id: $id, idMal: $idMal, search: $search, type: ANIME) { + id + idMal + title { + romaji + english + native + } + format + status + episodes + seasonYear + season + description + studios(sort: FAVOURITES_DESC, isMain: true) { + nodes { + name + } + } + bannerImage + coverImage { + medium + } + genres + averageScore + recommendations { + edges { + node { + id + mediaRecommendation { + id + title { + romaji + english + native + } + status + episodes + coverImage { + medium + } + bannerImage + format + meanScore + } + } + } + } + } +} +""" + self.RECOMMENDATIONS = """ + query ($id: Int, $idMal: Int, $search: String) { + Media(id: $id, idMal: $idMal, search: $search, type: ANIME) { + recommendations { + edges { + node { + id + mediaRecommendation { + id + title { + romaji + english + native + } + status + episodes + coverImage { + medium + } + bannerImage + format + meanScore + } + } + } + } + } +} + + """ - def popular(): - for host in hosts: - try: - data = requests.get(host + 'meta/anilist/popular') - except: - continue - if data.status_code == 200: - data = data.json() - results = data.get('results') - if results: - break - return results + def trending(self): + s, y = get_season() + vars = {"s": s, "y": y, "sort": 'TRENDING_DESC'} + data = requests.post( + 'https://graphql.anilist.co', + json={ + 'query': self.BROWSE_QUERY, + 'variables': vars + } + ).json() + return data.get('data').get('Page').get('media') - def anime(anime): - for host in hosts: - data = requests.get(host + 'meta/anilist/' + anime) - if data.status_code == 200: - data = data.json() - results = data.get('results') - if results: - break - if not results: - return + def popular(self): + s, y = get_season() + vars = {"s": s, "y": y, "sort": 'POPULARITY_DESC'} + data = requests.post( + 'https://graphql.anilist.co', + json={ + 'query': self.BROWSE_QUERY, + 'variables': vars + } + ).json() + return data.get('data').get('Page').get('media') - id = results[0]['id'] + def anime(self, anime): + s, y = get_season() + vars = {'search': anime} + data = requests.post( + 'https://graphql.anilist.co', + json={ + 'query': self.ANIME_QUERY, + 'variables': vars + } + ).json() + return data.get('data').get('Media') - for host in hosts: - try: - data = requests.get(host + 'meta/anilist/info/' + str(id)) - except: - continue - if data.status_code == 200: - data = data.json() - id = data.get('id') - if id: - break - return data + def get_recommendation(self, anime): + s, y = get_season() + vars = {'search': anime} + data = requests.post( + 'https://graphql.anilist.co', + json={ + 'query': self.ANIME_QUERY, + 'variables': vars + } + ).json() + return data.get('data').get('Media') - def search(query): - for host in hosts: - data = requests.get(host + 'meta/anilist/' + query) - if data.status_code == 200: - data = data.json() - results = data.get('results') - if results: - break - return results +# print(Anilist().anime('horimiya').get('recommendations')) diff --git a/programs/gogo.py b/programs/gogo.py index 84d90fbc..36dee17e 100644 --- a/programs/gogo.py +++ b/programs/gogo.py @@ -30,6 +30,7 @@ def search(self, query, url_only=False): for i in animes: url = i.find('a').get('href').replace('/category/', '') results.append(url) + print(results) return results else: results = [] @@ -122,17 +123,25 @@ def home(self): return results def get_episodes(self, anime): - soup = bs(requests.get( - f'https://{self.host}/category/{anime}').content, 'html.parser') + anime_id = bs(requests.get( + f'https://{self.host}/category/{anime}').content, 'html.parser').find('input', 'movie_id').get('value') - ep = soup.find('a', 'active').get('ep_end') - return int(ep.strip()) + html = bs(requests.get( + f'https://ajax.gogo-load.com/ajax/load-list-episode?ep_start=0&ep_end=100000&id={anime_id}').content, 'html.parser') - def get_links(self, anime, episode): - data = {} + li = html.find_all('li') + eps = [] + for i in li: + a = i.find('a').get('href').strip()[1:] + eps.append(a) + eps.reverse() + return len(li), eps + def get_links(self, anime, episode, eps): + data = {} + x = eps[int(episode)-1].get('id') soup = bs(requests.get( - f'https://{self.host}/{anime}-episode-{episode}').content, 'html.parser') + f'https://{self.host}/{x}').content, 'html.parser') div = soup.find('div', 'anime_muti_link') a = div.find_all('a') embeds = [] @@ -150,37 +159,29 @@ def get_links(self, anime, episode): if 'mp4upload' not in url: embeds.append(url) - if 'dub' in anime: data['DUB'] = embeds else: data['SUB'] = embeds anime += '-dub' - soup = bs(requests.get( - f'https://{self.host}/{anime}-episode-{episode}').content, 'html.parser') - + f'https://{self.host}/{x}').content, 'html.parser') error = soup.find('h1', 'entry-title') if error: return data - div = soup.find('div', 'anime_muti_link') a = div.find_all('a') embeds = [] - for i in a: url = i.get('data-video') if not url.startswith('https'): url = 'https:'+url - if 'gogohd' in url: url = extract(url) - if 'mixdrop.co' in url: url = url.replace('mixdrop.co', 'mixdrop.ch') - if 'mp4upload' not in url: embeds.append(url) - data['DUB'] = embeds return data + return data diff --git a/programs/html_gen.py b/programs/html_gen.py index 23df26b7..ed02a430 100644 --- a/programs/html_gen.py +++ b/programs/html_gen.py @@ -15,19 +15,19 @@ def get_genre_html(li): return html -def get_eps_html(anime, title, data=None): - try: - if not data: - aid = GoGoApi().search(anime, True)[0].strip() - update_views(aid) - data = GoGoApi().get_episodes(aid) - x = """{}""" - html = '' - for i in range(1, data+1): - html += x.format(f'/episode/{aid}/{str(i)}', str(i)) - return html - except: - return 'None' +def get_eps_html(anime, aid=None): + if not aid: + aid = GoGoApi().search(anime, True)[0].strip() + total, data = GoGoApi().get_episodes(aid) + x = """{}""" + html = '' + pos = 1 + for i in data: + i = i.replace('-episode-', '/') + html += x.format(f'/episode/{i}', str(pos)) + pos += 1 + update_views(aid) + return html, data[0].replace('-episode-', '/') ANIME_POS = """ @@ -73,34 +73,46 @@ def animeRecHtml(data): html = '' for i in data: + i = i.get('node').get('mediaRecommendation') + img = i.get('coverImage') + if img: + img = img.get('medium').replace('small', 'medium') + else: + img = i.get('bannerImage') title = get_atitle(i.get('title')) url = get_urls(title) x = ANIME_POS.format( url, - str(i.get('rating')).strip()+' / 100', + str(i.get('meanScore')).strip()+' / 100', 'Ep '+str(i.get('episodes')).strip(), - i.get('image').replace('large', 'medium'), + img, title, - i.get('type'), + i.get('format'), i.get('status') ) - html += x + if x not in html: + html += x return html def get_trending_html(): - data = Anilist.popular() + data = Anilist().popular() html = '' for i in data: + img = i.get('coverImage') + if img: + img = img.get('medium').replace('small', 'medium') + else: + img = i.get('bannerImage') title = get_atitle(i.get('title')) url = get_urls(title) x = ANIME_POS.format( url, get_genre(i.get('genres')), - 'Ep '+str(i.get('totalEpisodes')).strip(), - i.get('image').replace('large', 'medium'), + 'Ep '+str(i.get('episodes')).strip(), + img, title, i.get('type'), i.get('status') @@ -217,12 +229,17 @@ def get_selector_btns(url, current, episodes: list): def slider_gen(): - data = Anilist.trending() + data = Anilist().trending() random.shuffle(data) html = '' pos = 1 for i in data: + img = i.get('bannerImage') + if not img: + print(img) + img = i.get('coverImage').get('medium').replace( + 'small', 'large').replace('medium', 'large') title = get_atitle(i.get('title')) url = get_urls(title) temp = SLIDER_HTML.format( @@ -236,7 +253,7 @@ def slider_gen(): '/anime/', '/episode/')+'/1', url, url, - i.get('cover') + img ) html += temp pos += 1 diff --git a/programs/others.py b/programs/others.py index d14cdeb6..bca41108 100644 --- a/programs/others.py +++ b/programs/others.py @@ -107,7 +107,7 @@ def get_other_title(title): def get_studios(stud): tit = '' for i in stud: - tit += i + ', ' + tit += i.get('name') + ', ' return tit[:-2] diff --git a/programs/vidstream.py b/programs/vidstream.py index c37fae9a..94cfbfe6 100644 --- a/programs/vidstream.py +++ b/programs/vidstream.py @@ -5,22 +5,11 @@ import yarl import requests - -base_url = "https://animixplay.to" s = b'37911490979715163134003223491201' s_2 = b'54674138327930866480207815084989' iv = b'3134003223491201' -def extract_episode_info(anime_id): - r = requests.get( - f"{base_url}{anime_id}" - ) - soup = bs(r.text, "html.parser") - data = json.loads(soup.select("#epslistplace")[0].text) - return data - - def get_crypto(url): ''' function to get crypto data