-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
297 lines (186 loc) · 7.17 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
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
287
288
289
290
291
292
293
294
295
296
297
import discord
from collections import defaultdict
import re
import urllib.request
from keep_alive import keep_alive
keep_alive()
from discord.ext import commands
import youtube_dl
import os
import asyncio
import nacl
intents = discord.Intents.all()
intents.members = True
bot = commands.Bot(command_prefix='+', intents=intents)
bot.remove_command('help')
@bot.event
async def on_ready():
activity = discord.Game(name="lel", type=3)
await bot.change_presence(status=discord.Status.online, activity=activity)
print('We have logged in as {0.user}'.format(bot))
new = defaultdict(list)
@bot.command()
async def add(ctx, *, name = ' '):
bruh = new[ctx.guild.id].append(name)
print (dict(new))
ydl_opts = {
'format': 'bestaudio/best',
'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
'restrictfilenames': True,
'noplaylist': True,
'nocheckcertificate': True,
'ignoreerrors': False,
'logtostderr': False,
'quiet': True,
'no_warnings': True,
'default_search': 'auto',
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
result = ydl.extract_info(name, download=False)
audio = result['entries'][0]['url']
title = result['entries'][0]['title']
new_title = title.replace(' ', '')
html = urllib.request.urlopen("https://www.youtube.com/results?search_query=" + new_title)
video_ids = re.findall(r"watch\?v=(\S{11})", html.read().decode())
link = ("https://www.youtube.com/watch?v=" + video_ids[0])
embed = discord.Embed(title = 'Song added to queue', description = f'Added [{title}]({link}) to queue ', color = discord.Color.green())
def play_next(ctx):
data = dict(new).get(next(iter(dict(new))))
lel = new[ctx.guild.id]
if len(lel) == 0:
print('helo')
return
else:
lel = new[ctx.guild.id]
song = lel[0]
print(song)
voice = ctx.guild.voice_client
FFMPEG_OPTS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
ydl_opts = {
'format': 'bestaudio/best',
'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
'restrictfilenames': True,
'noplaylist': True,
'nocheckcertificate': True,
'ignoreerrors': False,
'logtostderr': False,
'quiet': True,
'no_warnings': True,
'default_search': 'auto',
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
result = ydl.extract_info(song, download=False)
audio = result['entries'][0]['url']
title = result['entries'][0]['title']
new_title = title.replace(' ', '')
html = urllib.request.urlopen("https://www.youtube.com/results?search_query=" + new_title)
video_ids = re.findall(r"watch\?v=(\S{11})", html.read().decode())
link = ("https://www.youtube.com/watch?v=" + video_ids[0])
embed = discord.Embed(title = 'Song added to queue', description = f'Now Playing [{title}]({link}) ', color = discord.Color.green())
voice.play(discord.FFmpegPCMAudio( result['entries'][0]['url']))
del lel[0]
def skip(ctx):
lel = new[ctx.guild.id]
if len(lel) == 0:
print('helo')
return
else:
lel = new[ctx.guild.id]
song = lel[0]
voice = ctx.guild.voice_client
voice.stop()
FFMPEG_OPTS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
ydl_opts = {
'format': 'bestaudio/best',
'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
'restrictfilenames': True,
'noplaylist': True,
'nocheckcertificate': True,
'ignoreerrors': False,
'logtostderr': False,
'quiet': True,
'no_warnings': True,
'default_search': 'auto',
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
result = ydl.extract_info(song, download=False)
del lel[0]
audio = result['entries'][0]['url']
title = result['entries'][0]['title']
new_title = title.replace(' ', '')
html = urllib.request.urlopen("https://www.youtube.com/results?search_query=" + new_title)
video_ids = re.findall(r"watch\?v=(\S{11})", html.read().decode())
link = ("https://www.youtube.com/watch?v=" + video_ids[0])
embed = discord.Embed(title = 'Song added to queue', description = f'Now Playing [{title}]({link}) ', color = discord.Color.green())
voice.play(discord.FFmpegPCMAudio(audio,options = FFMPEG_OPTS), after=lambda e: play_next(ctx))
@bot.command()
async def next(ctx):
skip(ctx)
@bot.command()
async def play(ctx, *, url = '' ):
voice = ctx.guild.voice_client
FFMPEG_OPTS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
ydl_opts = {
'format': 'bestaudio/best',
'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
'restrictfilenames': True,
'noplaylist': True,
'nocheckcertificate': True,
'ignoreerrors': False,
'logtostderr': False,
'quiet': True,
'no_warnings': True,
'default_search': 'auto',
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
result = ydl.extract_info(url, download=False)
audio = result['entries'][0]['url']
title = result['entries'][0]['title']
if ' ' in title:
new_title = title.replace(' ', '')
else:
new_title = title.replace(' ', '')
html = urllib.request.urlopen("https://www.youtube.com/results?search_query=" + new_title)
video_ids = re.findall(r"watch\?v=(\S{11})", html.read().decode())
link = ("https://www.youtube.com/watch?v=" + video_ids[0])
voice.play(discord.FFmpegPCMAudio(audio,options = FFMPEG_OPTS), after=lambda e: play_next(ctx))
embed = discord.Embed(title = 'Song playing', description = f'Now playing [{title}]({link})')
await ctx.send(embed = embed)
@bot.command()
async def join(ctx):
voice_state = ctx.author.voice
if voice_state is None:
await ctx.send('You have to be in a voice channel to use that command')
else:
channel = ctx.author.voice.channel
await channel.connect()
@bot.command()
async def pause(ctx):
voice = discord.utils.get(bot.voice_clients, guild=ctx.guild)
if voice.is_playing():
message = ctx.message
await message.add_reaction('⏸️')
voice.pause()
else:
await ctx.send("Currently no audio is playing.")
@bot.command()
async def resume(ctx):
voice = discord.utils.get(bot.voice_clients, guild=ctx.guild)
if voice.is_paused():
message = ctx.message
await message.add_reaction('✅')
voice.resume()
else:
await ctx.send("The audio is not paused.")
@bot.command()
async def stop(ctx):
voice = discord.utils.get(bot.voice_clients, guild=ctx.guild)
voice.stop()
@bot.command()
async def leave(ctx):
voice = ctx.guild.voice_client
if voice.is_connected():
await voice.disconnect()
else:
await ctx.send("The bot is not connected to a voice channel.")
bot.run(os.getenv('token'))