|
|
@ -2,13 +2,10 @@ import discord |
|
|
|
import yt_dlp as youtube_dl |
|
|
|
import yt_dlp as youtube_dl |
|
|
|
import time |
|
|
|
import time |
|
|
|
import asyncio |
|
|
|
import asyncio |
|
|
|
import subprocess |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g_client = discord.Client() |
|
|
|
g_client = discord.Client() |
|
|
|
queue = []#dicts with keys link and type |
|
|
|
queue = [] |
|
|
|
last_playing = {} |
|
|
|
|
|
|
|
voice_client = None |
|
|
|
voice_client = None |
|
|
|
last_start = 0 |
|
|
|
|
|
|
|
@g_client.event |
|
|
|
@g_client.event |
|
|
|
async def on_ready(): |
|
|
|
async def on_ready(): |
|
|
|
print("ohai") |
|
|
|
print("ohai") |
|
|
@ -16,36 +13,14 @@ async def on_ready(): |
|
|
|
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 not voice_client.is_playing() and voice_client is not None: |
|
|
|
link = None |
|
|
|
voice_client.play(discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(queue[0]["link"], before_options="-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5"), volume=1.0)) |
|
|
|
res = {} |
|
|
|
|
|
|
|
if queue[0]["type"] == "yt": |
|
|
|
|
|
|
|
ydl = youtube_dl.YoutubeDL({"simulate": True}) |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
res = ydl.extract_info(queue[0]["link"], |
|
|
|
|
|
|
|
force_generic_extractor=ydl.params.get('force_generic_extractor', False))#lifted the second bit from the ytdl innards |
|
|
|
|
|
|
|
except: |
|
|
|
|
|
|
|
queue.pop(0) |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
if "requested_formats" in res: |
|
|
|
|
|
|
|
for format in res["requested_formats"]: |
|
|
|
|
|
|
|
if not (format["asr"] is None): |
|
|
|
|
|
|
|
link = format["url"] |
|
|
|
|
|
|
|
else: link = res["url"] |
|
|
|
|
|
|
|
last_playing = res |
|
|
|
|
|
|
|
last_playing["raw"] = False |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
link = queue[0]["link"] |
|
|
|
|
|
|
|
last_playing = {"raw":True} |
|
|
|
|
|
|
|
result = subprocess.run(['ffprobe', '-v', 'error', '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', queue[0]["link"]], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
|
|
|
|
|
|
|
res["duration"] = int(float(result.stdout))#you actually need to do this laffo |
|
|
|
|
|
|
|
voice_client.play(discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(link, before_options="-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5"), volume=1.0)) |
|
|
|
|
|
|
|
print("playan") |
|
|
|
print("playan") |
|
|
|
sav = queue[0] |
|
|
|
sav = queue[0]["link"] |
|
|
|
hack = False |
|
|
|
hack = False |
|
|
|
for sec in range(res["duration"]):# FIX SH1T HACK |
|
|
|
for sec in range(queue[0]["ctx"]["duration"]):# FIX SH1T HACK |
|
|
|
await asyncio.sleep(1) |
|
|
|
await asyncio.sleep(1) |
|
|
|
try:# how do i computer i just press keys please help |
|
|
|
try:# how do i computer i just press keys please help |
|
|
|
if not(sav == queue[0]): |
|
|
|
if not(sav == queue[0]["link"]): |
|
|
|
hack = True |
|
|
|
hack = True |
|
|
|
break |
|
|
|
break |
|
|
|
except: |
|
|
|
except: |
|
|
@ -53,12 +28,10 @@ async def on_ready(): |
|
|
|
break |
|
|
|
break |
|
|
|
if hack: |
|
|
|
if hack: |
|
|
|
continue |
|
|
|
continue |
|
|
|
#await asyncio.sleep(res["duration"]) |
|
|
|
|
|
|
|
queue.pop(0) |
|
|
|
queue.pop(0) |
|
|
|
print("popped") |
|
|
|
print("popped") |
|
|
|
@g_client.event |
|
|
|
@g_client.event |
|
|
|
async def on_message(message): |
|
|
|
async def on_message(message): |
|
|
|
global last_playing |
|
|
|
|
|
|
|
global voice_client |
|
|
|
global voice_client |
|
|
|
global queue |
|
|
|
global queue |
|
|
|
print(">>>", message.content) |
|
|
|
print(">>>", message.content) |
|
|
@ -66,31 +39,33 @@ async def on_message(message): |
|
|
|
return |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
if message.content.startswith("*play"): |
|
|
|
if message.content.startswith("*play"): |
|
|
|
if (len(message.content.split(" ")) < 2): |
|
|
|
try: voice_client = await message.author.voice.channel.connect() |
|
|
|
await message.channel.send("missing argument") |
|
|
|
except: pass |
|
|
|
return |
|
|
|
ydl = youtube_dl.YoutubeDL({"simulate": True}) |
|
|
|
try: |
|
|
|
res = ydl.extract_info(message.content.split(" ")[1], force_generic_extractor=ydl.params.get('force_generic_extractor', False)) |
|
|
|
voice_client = await message.author.voice.channel.connect() |
|
|
|
|
|
|
|
except: #already conn'd/user not in chan/probably something else (?). fails are not /broadly/ (really) destructive neway so who cares#nevermind |
|
|
|
link = None |
|
|
|
print("AAHHHHHHHHHHHHHHHHHHHH OH GOD") |
|
|
|
for format in res["requested_formats"]: |
|
|
|
pass #it's ok if we do it ON PURPOSE ;^) |
|
|
|
if not (format["asr"] is None): |
|
|
|
queue.append({"link":message.content.split(" ")[1], "type":("raw" if message.content.split(" ")[0] == "*playraw" else "yt")}) |
|
|
|
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 == "*np": |
|
|
|
if message.content.startswith("*np"): |
|
|
|
if last_playing["raw"]: |
|
|
|
embed = discord.Embed(title="now playan~", url=queue[0]["ctx"]["webpage_url"]) |
|
|
|
await message.channel.send("`source is raw! link: {0}`".format(queue[0]["link"])) |
|
|
|
embed.set_thumbnail(url=queue[0]["ctx"]["thumbnail"]) |
|
|
|
return |
|
|
|
embed.add_field(name="naem:", value=queue[0]["ctx"]["title"], inline=True) |
|
|
|
embed = discord.Embed(title="now playing...") |
|
|
|
embed.add_field(name="uploadah:", value=queue[0]["ctx"]["uploader"], inline=True) |
|
|
|
embed.add_field(name="song:", value=last_playing["title"], inline=False) |
|
|
|
embed.add_field(name="viewz:", value=queue[0]["ctx"]["view_count"], inline=True) |
|
|
|
embed.set_image(url = last_playing["thumbnail"]) |
|
|
|
embed.add_field(name="length:", value=str(queue[0]["ctx"]["duration"]/60)+" minutes", inline=True) |
|
|
|
embed.add_field(name="duration (in seconds):", value=last_playing["duration"], inline=False) |
|
|
|
|
|
|
|
await message.channel.send(embed=embed) |
|
|
|
await message.channel.send(embed=embed) |
|
|
|
|
|
|
|
|
|
|
|
if message.content.startswith("*q"): |
|
|
|
if message.content.startswith("*q"): |
|
|
|
embed = discord.Embed(title="queue") |
|
|
|
embed = discord.Embed(title="queue") |
|
|
|
for q in queue: |
|
|
|
for q in queue: |
|
|
|
embed.add_field(name=".", value=q["link"], inline=False) |
|
|
|
embed.add_field(name="song:", value=q["ctx"]["title"], inline=False) |
|
|
|
await message.channel.send(embed=embed) |
|
|
|
await message.channel.send(embed=embed) |
|
|
|
|
|
|
|
|
|
|
|
if message.content.startswith("*s"): |
|
|
|
if message.content.startswith("*s"): |
|
|
|