-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
213 lines (182 loc) · 6.15 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
from programs.anime_loader import get_GPage, get_html
from programs.db import update_views, update_watch
from programs.html_gen import animeRecHtml, episodeHtml, get_eps_html, get_eps_html2, get_recent_html, get_search_html, get_selector_btns, get_genre_html, get_trending_html, slider_gen
from flask import Flask, render_template, request, redirect
from programs.anilist import Anilist
from programs.others import get_atitle, get_other_title, get_studios, get_t_from_u
from programs.gogo import GoGoApi
from programs.vidstream import extract_m3u8
GOGO = GoGoApi()
application = Flask(__name__)
@application.route('/favicon.ico')
def favicon():
return redirect('https://anime-desk.ru/static/img/favicon.ico')
@application.route('/')
def home():
html = render_template('home.html')
div1 = get_trending_html()
try:
div2 = get_recent_html(GOGO.home())
except:
div2 = ''
sliders = slider_gen()
html = html.replace(
'MOST_POPULAR',
div1
).replace(
'RECENT_RELEASE',
div2
).replace(
'SLIDERS',
sliders
)
update_views('home-anime-desk')
return html
@application.route('/embed')
def get_embed():
url = request.args.get('url')
if url:
if 'gogohd' in url:
file = extract_m3u8(url)
elif '.mp4' in url or '.mkv' in url:
file = url
else:
file = request.args.get('file')
if not file:
return redirect(url)
sub = request.args.get('sub')
title = request.args.get('title')
if sub != None:
track = """tracks: [{
"kind": "captions",
file: "sopu",
label: 'English',
"default": true
}],""".replace('sopu', sub)
else:
track = ''
return render_template('vid.html', m3u8=file, title=title).replace('TRACKS', track)
@application.route('/episode/<anime>/<episode>')
def get_episode(anime, episode):
anime = get_t_from_u(anime).lower()
episode = int(episode)
try:
total_eps, ep = GOGO.get_episodes(anime)
eps = GOGO.get_links(ep[episode-1])
ep_list = get_eps_html2(ep)
except:
search = GOGO.search(anime, True)
total_eps, ep = GOGO.get_episodes(search[0])
eps = GOGO.get_links(ep[episode-1])
ep_list = get_eps_html2(ep)
aid = ep[episode-1].split('-episode-')[0]
btn_html = get_selector_btns(
f"/episode/{anime}/", int(episode), int(total_eps))
ep_html, iframe = episodeHtml(eps, f'{anime} - Episode {episode}')
temp = render_template(
'episode.html',
title=f'{anime} - Episode {episode}',
heading=anime,
iframe=iframe
)
update_watch(aid)
return temp.replace('PROSLO', btn_html).replace('SERVER', ep_html).replace('EPISOS', ep_list)
@application.route('/anime/<anime>')
def get_anime(anime):
try:
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]
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))
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').get('nodes'))
episodes = str(data.get('episodes'))
genres = get_genre_html(data.get('genres'))
displayAnime = animeRecHtml(data.get('recommendations').get('edges'))
try:
ep_html, watch = get_eps_html(anime)
except:
ep_html, watch = '', '#'
dub = data.get('format')
season = data.get('season')
year = data.get('seasonYear')
typo = data.get('format')
status = data.get('status')
html = render_template('anime.html',
img=img,
title=title,
DUB=dub,
SEASON=season,
other=names,
studios=studios,
episodes=episodes,
year=year,
ATYPE=typo,
status=status,
animeURL=f'/anime/{anime}',
WATCHNOW=f'/episode/{watch}',
aid=anime
)
html = html.replace('GENEROS', genres)
html = html.replace('EPISOS', ep_html)
html = html.replace('DISPLAY_ANIME', displayAnime)
html = html.replace('SYNOP', synopsis)
update_views(anime)
return html
@application.route('/search', methods=['GET'])
def search_anime():
anime = request.args.get('query').lower().strip()
if anime.endswith('-dub'):
anime = anime[:-4]
if anime.endswith('-sub'):
anime = anime[:-4]
html = render_template('search.html',
aid=anime.replace('+', ' '))
data = GOGO.search(anime)
display = get_search_html(data)
html = html.replace(
'SEARCHED',
display
)
update_views('search-anime-desk')
return html
@application.route('/api/latest/<page>')
def latest(page):
try:
data = get_GPage(page)
html = get_html(data)
return {'html': html}
except:
return {'html': ''}
if __name__ == '__main__':
application.run(host='0.0.0.0')