Skip to content
This repository was archived by the owner on Feb 16, 2024. It is now read-only.

Commit 4e46f67

Browse files
committed
Improvement
Trying to reduce errors as much as possible
1 parent 6c64fcb commit 4e46f67

File tree

3 files changed

+87
-36
lines changed

3 files changed

+87
-36
lines changed

app.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
app = Flask(__name__)
88

99

10-
@app.errorhandler(404)
11-
def error():
12-
return 'Something went wrong...\n\n Probably Anilist Is Down. Report To https://t.me/techshreyash'
10+
@app.errorhandler(Exception)
11+
def error(error=None):
12+
return '<h1>Something went wrong...\n\n Report To <a href="https://t.me/techshreyash">Owner</a></h1>'
1313

1414

1515
@app.route('/')
@@ -111,21 +111,38 @@ def get_anime(anime):
111111
typo = data.get('type')
112112
status = data.get('status')
113113
except:
114-
data = GOGO.anime(x)
115-
title = data[0]
116-
synopsis = data[1]
117-
names = data[2]
118-
studios = data[3]
119-
episodes = data[4]
120-
genres = get_genre_html(data[5])
121-
img = data[6]
122-
dub = data[7]
123-
season = data[8]
124-
year = data[9]
125-
typo = data[10]
126-
status = data[11]
127-
displayAnime = 'Not Available'
128-
ep_html = get_eps_html(anime, title, episodes)
114+
try:
115+
data = GOGO.anime(x)
116+
title = data[0]
117+
synopsis = data[1]
118+
names = data[2]
119+
studios = data[3]
120+
episodes = data[4]
121+
genres = get_genre_html(data[5])
122+
img = data[6]
123+
dub = data[7]
124+
season = data[8]
125+
year = data[9]
126+
typo = data[10]
127+
status = data[11]
128+
displayAnime = 'Not Available'
129+
ep_html = get_eps_html(anime, title, episodes)
130+
except:
131+
data = GOGO.anime_api(x)
132+
img = data.get('image')
133+
title = data.get('title')
134+
synopsis = data.get('description')
135+
names = data.get('otherName')
136+
studios = '?'
137+
episodes = str(len(data.get('episodes')))
138+
genres = get_genre_html(data.get('genres'))
139+
displayAnime = 'Not Available'
140+
ep_html = get_eps_html(anime, title)
141+
dub = data.get('subOrDub').upper()
142+
season = data.get('type')
143+
year = data.get('type')
144+
typo = data.get('type')
145+
status = data.get('status')
129146

130147
html = render_template('anime.html',
131148
img=img,

main.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
app = Flask(__name__)
88

99

10-
@app.errorhandler(404)
11-
def error():
12-
return 'Something went wrong...\n\n Probably Anilist Is Down. Report To https://t.me/techshreyash'
10+
@app.errorhandler(Exception)
11+
def error(error=None):
12+
return '<h1>Something went wrong...\n\n Report To <a href="https://t.me/techshreyash">Owner</a></h1>'
1313

1414

1515
@app.route('/')
@@ -111,21 +111,38 @@ def get_anime(anime):
111111
typo = data.get('type')
112112
status = data.get('status')
113113
except:
114-
data = GOGO.anime(x)
115-
title = data[0]
116-
synopsis = data[1]
117-
names = data[2]
118-
studios = data[3]
119-
episodes = data[4]
120-
genres = get_genre_html(data[5])
121-
img = data[6]
122-
dub = data[7]
123-
season = data[8]
124-
year = data[9]
125-
typo = data[10]
126-
status = data[11]
127-
displayAnime = 'Not Available'
128-
ep_html = get_eps_html(anime, title, episodes)
114+
try:
115+
data = GOGO.anime(x)
116+
title = data[0]
117+
synopsis = data[1]
118+
names = data[2]
119+
studios = data[3]
120+
episodes = data[4]
121+
genres = get_genre_html(data[5])
122+
img = data[6]
123+
dub = data[7]
124+
season = data[8]
125+
year = data[9]
126+
typo = data[10]
127+
status = data[11]
128+
displayAnime = 'Not Available'
129+
ep_html = get_eps_html(anime, title, episodes)
130+
except:
131+
data = GOGO.anime_api(x)
132+
img = data.get('image')
133+
title = data.get('title')
134+
synopsis = data.get('description')
135+
names = data.get('otherName')
136+
studios = '?'
137+
episodes = str(len(data.get('episodes')))
138+
genres = get_genre_html(data.get('genres'))
139+
displayAnime = 'Not Available'
140+
ep_html = get_eps_html(anime, title)
141+
dub = data.get('subOrDub').upper()
142+
season = data.get('type')
143+
year = data.get('type')
144+
typo = data.get('type')
145+
status = data.get('status')
129146

130147
html = render_template('anime.html',
131148
img=img,

programs/gogo.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import requests
22
from bs4 import BeautifulSoup as bs
3+
from programs.others import get_t_from_u
34
from programs.vidstream import extract
45

56

@@ -15,6 +16,8 @@ def __init__(self, url, img, lang, title, episode) -> None:
1516
class GoGoApi:
1617
def __init__(self) -> None:
1718
self.host = 'gogoanime.dk'
19+
self.api = ['https://api-techshreyash.up.railway.app/',
20+
'https://api.consumet.org/']
1821

1922
def search(self, query, url_only=False):
2023
soup = bs(requests.get(
@@ -40,6 +43,20 @@ def search(self, query, url_only=False):
4043
)
4144
return results
4245

46+
def anime_api(self, anime):
47+
anime = get_t_from_u(anime).strip().replace(' ', '-')
48+
for host in self.api:
49+
try:
50+
url = host + 'anime/gogoanime/info/' + anime
51+
data = requests.get(url)
52+
if data.status_code == 200:
53+
data = data.json()
54+
if data:
55+
break
56+
except:
57+
continue
58+
return data
59+
4360
def anime(self, anime):
4461
soup = bs(requests.get(
4562
f'https://{self.host}/category/'+anime).content, 'html.parser')

0 commit comments

Comments
 (0)