-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gogoanime.py
286 lines (256 loc) · 14 KB
/
gogoanime.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import discord
from discord import app_commands
from discord.ext import commands
from httpclient import HttpClient
from bs4 import BeautifulSoup as BS
import re
from urllib import parse as p
from util_discord import command_check, description_helper, check_if_not_owner
from util_database import myclient
mycol = myclient["utils"]["cant_do_json_shit_dynamically_on_docker"]
client, client_dood = HttpClient(), HttpClient()
title, url, aid, mv_tv, poster = 0, 1, 2, 3, 4
desc, ep, animetype, released, genre = 2, 3, 5, 6, 7
pagelimit = 12
gogoanime = "https://anitaku.pe"
provider="https://gdjkhp.github.io/img/logo.png"
async def get_domain():
global gogoanime
cursor = mycol.find()
data = await cursor.to_list(None)
gogoanime = data[0]["gogo"]
async def set_domain(ctx: commands.Context, arg: str):
await mycol.update_one({}, {"$set": {"gogo": arg}})
await get_domain()
await ctx.reply(gogoanime)
async def Gogoanime(ctx: commands.Context, arg: str):
if await command_check(ctx, "anime", "media"): return await ctx.reply("command disabled", ephemeral=True)
await get_domain()
if arg: msg = await ctx.reply(f"Searching `{arg}`\nPlease wait…")
else: msg = await ctx.reply("Imagine something that doesn't exist. Must be sad. You are sad. You don't belong here.\nLet's all love lain.")
try: result = await resultsAnime(searchAnime(arg if arg else "serial experiments lain"))
except: return await msg.edit(content="Error! Domain changed most likely.")
try: await msg.edit(content=None, embed=buildSearch(arg, result, 0), view = MyView4(ctx, arg, result, 0))
except Exception as e: return await msg.edit(content=f"**No results found**")
def buildAnime(details: list) -> discord.Embed:
embed = discord.Embed(title=details[title], description=details[desc], color=0x00ff00)
embed.set_thumbnail(url=provider)
valid_url = p.quote(details[poster], safe=":/")
embed.set_image(url = valid_url)
embed.add_field(name="Type", value=details[animetype])
embed.add_field(name="Episodes", value=details[ep])
embed.add_field(name="Released", value=details[released])
embed.add_field(name="Genre", value=details[genre])
embed.set_footer(text="Note: Use Adblockers :)")
return embed
def buildSearch(arg: str, result: list, index: int) -> discord.Embed:
embed = discord.Embed(title=f"Search results: `{arg}`", description=f"{len(result)} found", color=0x00ff00)
embed.set_thumbnail(url=provider)
i = index
while i < len(result):
if (i < index+pagelimit): embed.add_field(name=f"[{i + 1}] `{result[i][title]}`", value=f"{result[i][url]}")
i += 1
return embed
def searchAnime(q: str):
return q.replace(" ", "-")
async def resultsAnime(data: str) -> list:
results = []
page = 1
while True:
req = await client.get(f"{gogoanime}/search.html?keyword={data}&page={page}")
soup = BS(req, "lxml")
items = soup.find("ul", {"class": "items"}).findAll("li")
if len(items) == 0: break
img = [items[i].find("img")["src"] for i in range(len(items))]
urls = [items[i].find("a")["href"] for i in range(len(items))]
title = [items[i].find("a")["title"] for i in range(len(items))]
ids = [items[i].find("a")["title"] for i in range(len(items))]
mov_or_tv = ["TV" for i in range(len(items))]
results.extend([list(sublist) for sublist in zip(title, urls, ids, mov_or_tv, img)])
page += 1
return results
async def doodstream(url):
domain = re.findall("""([^"']*)\/e""", url)[0]
res = await client.get(url)
req = res.text
pass_md = re.findall(r"/pass_md5/[^']*", req)[0]
token = pass_md.split("/")[-1]
client_dood.set_headers(
{
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0",
"Referer": f"{url}",
"Accept-Language": "en-GB,en;q=0.5",
}
)
res = await client_dood.get(f"{domain}{pass_md}")
drylink = res.text
streamlink = f"{drylink}zUEJeL3mUN?token={token}"
print(streamlink)
return streamlink
def get_max_page(length):
if length % pagelimit != 0: return length - (length % pagelimit)
return length - pagelimit
# search
class MyView4(discord.ui.View):
def __init__(self, ctx: commands.Context, arg: str, result: list, index: int):
super().__init__(timeout=None)
last_index = min(index + pagelimit, len(result))
self.add_item(SelectChoice(ctx, index, result))
if index - pagelimit > -1:
self.add_item(nextPage(ctx, arg, result, 0, "⏪"))
self.add_item(nextPage(ctx, arg, result, index - pagelimit, "◀️"))
else:
self.add_item(DisabledButton("⏪", 1))
self.add_item(DisabledButton("◀️", 1))
if not last_index == len(result):
self.add_item(nextPage(ctx, arg, result, last_index, "▶️"))
max_page = get_max_page(len(result))
self.add_item(nextPage(ctx, arg, result, max_page, "⏩"))
else:
self.add_item(DisabledButton("▶️", 1))
self.add_item(DisabledButton("⏩", 1))
self.add_item(CancelButton(ctx, 1))
class SelectChoice(discord.ui.Select):
def __init__(self, ctx: commands.Context, index: int, result: list):
super().__init__(placeholder=f"{min(index + pagelimit, len(result))}/{len(result)} found")
i, self.result, self.ctx = index, result, ctx
while i < len(result):
if (i < index+pagelimit): self.add_option(label=f"[{i + 1}] {result[i][title]}", value=i, description=f"{result[i][url]}")
if (i == index+pagelimit): break
i += 1
async def callback(self, interaction: discord.Interaction):
if interaction.user != self.ctx.author:
return await interaction.response.send_message(f"Only <@{self.ctx.author.id}> can interact with this message.",
ephemeral=True)
await interaction.response.edit_message(view=None)
req = await client.get(f"{gogoanime}{self.result[int(self.values[0])][url]}")
soup = BS(req, "lxml")
episodes: int = soup.find("ul", {"id": "episode_page"}).find_all("a")[-1]["ep_end"]
types = soup.find_all("p", {"class": "type"})
desc: str = types[1].get_text().replace("Plot Summary:", "")
animetype: str = types[0].get_text().split(": ")[1]
genre: str = types[2].get_text().split(": ")[1]
released: str = types[3].get_text().split(": ")[1]
details = [self.result[int(self.values[0])][title], self.result[int(self.values[0])][url], desc, episodes,
self.result[int(self.values[0])][poster], animetype, released, genre]
embed = buildAnime(details)
await interaction.edit_original_response(content=None, embed = embed, view = MyView5(self.ctx, details, 0))
# legacy code
class ButtonSelect4(discord.ui.Button):
def __init__(self, ctx: commands.Context, index: int, result: list, row: int):
super().__init__(label=index, style=discord.ButtonStyle.primary, row=row)
self.result, self.ctx = result, ctx
async def callback(self, interaction: discord.Interaction):
if interaction.user != self.ctx.author:
return await interaction.response.send_message(f"Only <@{self.ctx.author.id}> can interact with this message.",
ephemeral=True)
await interaction.response.edit_message(view=None)
req = await client.get(f"{gogoanime}{self.result[url]}")
soup = BS(req, "lxml")
episodes: int = soup.find("ul", {"id": "episode_page"}).find_all("a")[-1]["ep_end"]
types = soup.find_all("p", {"class": "type"})
desc: str = types[1].get_text().replace("Plot Summary:", "")
animetype: str = types[0].get_text().split(": ")[1]
genre: str = types[2].get_text().split(": ")[1]
released: str = types[3].get_text().split(": ")[1]
details = [self.result[title], self.result[url], desc, episodes, self.result[poster], animetype, released, genre]
embed = buildAnime(details)
await interaction.edit_original_response(embed = embed, view = MyView5(self.ctx, details, 0))
class nextPage(discord.ui.Button):
def __init__(self, ctx: commands.Context, arg: str, result: list, index: int, l: str):
super().__init__(emoji=l, style=discord.ButtonStyle.success)
self.result, self.index, self.arg, self.ctx = result, index, arg, ctx
async def callback(self, interaction: discord.Interaction):
if interaction.user != self.ctx.author:
return await interaction.response.send_message(f"Only <@{self.ctx.author.id}> can interact with this message.",
ephemeral=True)
await interaction.response.edit_message(view = MyView4(self.ctx, self.arg, self.result, self.index))
# episode
class MyView5(discord.ui.View):
def __init__(self, ctx: commands.Context, details: list, index: int):
super().__init__(timeout=None)
i = index
column, row, last_index = 0, -1, int(details[ep])
while i < int(details[ep]):
if column % 4 == 0: row += 1
if (i < index+pagelimit): self.add_item(ButtonSelect5(ctx, i + 1, details[url], row))
if (i == index+pagelimit): last_index = i
i += 1
column += 1
if index - pagelimit > -1:
self.add_item(nextPageEP(ctx, details, 0, 3, "⏪"))
self.add_item(nextPageEP(ctx, details, index - pagelimit, 3, "◀️"))
else:
self.add_item(DisabledButton("⏪", 3))
self.add_item(DisabledButton("◀️", 3))
if not last_index == int(details[ep]):
self.add_item(nextPageEP(ctx, details, last_index, 3, "▶️"))
max_page = get_max_page(int(details[ep]))
self.add_item(nextPageEP(ctx, details, max_page, 3, "⏩"))
else:
self.add_item(DisabledButton("▶️", 3))
self.add_item(DisabledButton("⏩", 3))
self.add_item(CancelButton(ctx, 3))
class ButtonSelect5(discord.ui.Button):
def __init__(self, ctx: commands.Context, index: int, sUrl: str, row: int):
super().__init__(label=index, style=discord.ButtonStyle.primary, row=row)
self.index = index
self.sUrl = sUrl
self.ctx = ctx
async def callback(self, interaction: discord.Interaction):
if interaction.user != self.ctx.author:
return await interaction.response.send_message(f"Only <@{self.ctx.author.id}> can interact with this message.",
ephemeral=True)
await interaction.response.defer()
url = self.sUrl.split("/")[-1]
request = await client.get(f"{gogoanime}/{url}-episode-{self.index}")
soup = BS(request, "lxml")
video = soup.find("li", {"class": "doodstream"}).find("a")["data-video"]
await interaction.followup.send(f"{url}-episode-{self.index}", view=WatchView([video]), ephemeral=True)
# url0 = await doodstream(
# soup.find("li", {"class": "doodstream"}).find("a")["data-video"]
# )
# await interaction.followup.send(f"{url}-episode-{self.index}: {url0}")
class nextPageEP(discord.ui.Button):
def __init__(self, ctx: commands.Context, details: list, index: int, row: int, l: str):
super().__init__(emoji=l, style=discord.ButtonStyle.success, row=row)
self.details, self.index, self.ctx = details, index, ctx
async def callback(self, interaction: discord.Interaction):
if interaction.user != self.ctx.author:
return await interaction.response.send_message(f"Only <@{self.ctx.author.id}> can interact with this message.",
ephemeral=True)
await interaction.response.edit_message(view = MyView5(self.ctx, self.details, self.index))
class CancelButton(discord.ui.Button):
def __init__(self, ctx: commands.Context, r: int):
super().__init__(emoji="❌", style=discord.ButtonStyle.success, row=r)
self.ctx = ctx
async def callback(self, interaction: discord.Interaction):
if interaction.user != self.ctx.author:
return await interaction.response.send_message(f"Only <@{self.ctx.author.id}> can interact with this message.",
ephemeral=True)
await interaction.response.defer()
await interaction.delete_original_response()
class WatchView(discord.ui.View):
def __init__(self, links: list):
super().__init__(timeout=None)
for x in links[:25]:
self.add_item(discord.ui.Button(style=discord.ButtonStyle.link, url=x, emoji="🎞️",
label=f"Watch Full HD Movies & TV Shows"))
class DisabledButton(discord.ui.Button):
def __init__(self, e: str, r: int):
super().__init__(emoji=e, style=discord.ButtonStyle.success, disabled=True, row=r)
class CogGogo(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command()
async def rgogo(self, ctx: commands.Context, arg=None):
if check_if_not_owner(ctx): return
await set_domain(ctx, arg)
@commands.hybrid_command(description=f"{description_helper['emojis']['anime']} gogoanime")
@app_commands.describe(query="Search query")
@app_commands.allowed_installs(guilds=True, users=True)
@app_commands.allowed_contexts(guilds=True, dms=True, private_channels=True)
async def gogo(self, ctx: commands.Context, *, query:str=None):
await Gogoanime(ctx, query)
async def setup(bot: commands.Bot):
await bot.add_cog(CogGogo(bot))