|
|
@ -2,17 +2,34 @@ import discord |
|
|
|
import yt_dlp as youtube_dl |
|
|
|
import yt_dlp as youtube_dl |
|
|
|
import time |
|
|
|
import time |
|
|
|
import asyncio |
|
|
|
import asyncio |
|
|
|
|
|
|
|
import requests |
|
|
|
|
|
|
|
import json |
|
|
|
|
|
|
|
|
|
|
|
g_client = discord.Client() |
|
|
|
g_client = discord.Client() |
|
|
|
queue = [] |
|
|
|
queue = [] |
|
|
|
voice_client = None |
|
|
|
voice_client = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def q_vid(url): |
|
|
|
|
|
|
|
global voice_client |
|
|
|
|
|
|
|
global queue |
|
|
|
|
|
|
|
ydl = youtube_dl.YoutubeDL({"simulate": True}) |
|
|
|
|
|
|
|
res = ydl.extract_info(url, force_generic_extractor=ydl.params.get('force_generic_extractor', False)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
link = None |
|
|
|
|
|
|
|
for format in res["requested_formats"]: |
|
|
|
|
|
|
|
if not (format["asr"] is None): |
|
|
|
|
|
|
|
link = format["url"] |
|
|
|
|
|
|
|
if not link: return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
queue.append({"link": link, "ctx": res}) |
|
|
|
|
|
|
|
|
|
|
|
@g_client.event |
|
|
|
@g_client.event |
|
|
|
async def on_ready(): |
|
|
|
async def on_ready(): |
|
|
|
print("ohai") |
|
|
|
print("ohai") |
|
|
|
while True: |
|
|
|
while True: |
|
|
|
await asyncio.sleep(.1) |
|
|
|
await asyncio.sleep(.1) |
|
|
|
if len(queue) > 0: |
|
|
|
if len(queue) > 0: |
|
|
|
if not voice_client.is_playing() and voice_client is not None: |
|
|
|
if (voice_client is not None) and (not voice_client.is_playing()): |
|
|
|
voice_client.play(discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(queue[0]["link"], before_options="-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5"), volume=1.0)) |
|
|
|
voice_client.play(discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(queue[0]["link"], before_options="-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5"), volume=1.0)) |
|
|
|
print("playan") |
|
|
|
print("playan") |
|
|
|
sav = queue[0]["link"] |
|
|
|
sav = queue[0]["link"] |
|
|
@ -41,16 +58,9 @@ async def on_message(message): |
|
|
|
if message.content.startswith("*play"): |
|
|
|
if message.content.startswith("*play"): |
|
|
|
try: voice_client = await message.author.voice.channel.connect() |
|
|
|
try: voice_client = await message.author.voice.channel.connect() |
|
|
|
except: pass |
|
|
|
except: pass |
|
|
|
ydl = youtube_dl.YoutubeDL({"simulate": True}) |
|
|
|
|
|
|
|
res = ydl.extract_info(message.content.split(" ")[1], force_generic_extractor=ydl.params.get('force_generic_extractor', False)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
link = None |
|
|
|
await q_vid(message.content.split(" ")[1]) |
|
|
|
for format in res["requested_formats"]: |
|
|
|
|
|
|
|
if not (format["asr"] is None): |
|
|
|
|
|
|
|
link = format["url"] |
|
|
|
|
|
|
|
if not link: return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
queue.append({"link": link, "ctx": res}) |
|
|
|
|
|
|
|
await message.channel.send("k") |
|
|
|
await message.channel.send("k") |
|
|
|
|
|
|
|
|
|
|
|
if message.content.startswith("*np"): |
|
|
|
if message.content.startswith("*np"): |
|
|
@ -71,6 +81,21 @@ async def on_message(message): |
|
|
|
if message.content.startswith("*s"): |
|
|
|
if message.content.startswith("*s"): |
|
|
|
queue.pop(0) |
|
|
|
queue.pop(0) |
|
|
|
voice_client.stop() |
|
|
|
voice_client.stop() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if message.content.startswith("*b"): |
|
|
|
|
|
|
|
try: voice_client = await message.author.voice.channel.connect() |
|
|
|
|
|
|
|
except: pass |
|
|
|
|
|
|
|
res = json.loads(requests.get(f"https://vid.puffyan.us/api/v1/search?q={'%20'.join(message.content.split(' ')[1:])}&pretty=1").text) |
|
|
|
|
|
|
|
res = [item for item in res if item["type"] == "video"] |
|
|
|
|
|
|
|
if message.content.split(' ')[0][-1] in list("012345"): |
|
|
|
|
|
|
|
await q_vid(f"https://www.youtube.com/watch?v={res[int(message.content.split(' ')[0][-1])]['videoId']}") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
embed = discord.Embed(title="does this look right") |
|
|
|
|
|
|
|
for i, q in enumerate(res): |
|
|
|
|
|
|
|
if i > 5: break |
|
|
|
|
|
|
|
embed.add_field(name=str(i), value=q["title"], inline=False) |
|
|
|
|
|
|
|
await message.channel.send(embed=embed) |
|
|
|
|
|
|
|
|
|
|
|
conf = open("token", "r") |
|
|
|
conf = open("token", "r") |
|
|
|
g_client.run(conf.read(), bot=True) |
|
|
|
g_client.run(conf.read(), bot=True) |
|
|
|
conf.close() |
|
|
|
conf.close() |