我正在开发一个不和谐的机器人,它也可以播放youtube音乐。但是我也希望它打印出当前的视频(歌曲)队列,但是我做的效果不佳。我想从已经下载的视频中获取视频信息 这是代码:
@bot.command(pass_context=True, aliases=["play", "hraj"])
async def yt(ctx, url, member: discord.Member = None):
server = ctx.message.server
voice_client = bot.voice_client_in(server)
server = ctx.message.server
author = ctx.message.author
voice_channel = author.voice_channel
vc = await bot.join_voice_channel(voice_channel)
urls.append(url)
msg = "Stahuji audio..."
msg = await bot.say(msg)
player = await vc.create_ytdl_player(url, after = lambda: checkqueue(server.id))
await bot.edit_message(msg, new_content="Hotovo!")
players[server.id] = player
player.start()
队列:
def checkqueue(my_id):
if queued[my_id] != []:
#delete item from urls
del urls[0]
player = queued[my_id].pop(0)
players[my_id] = player
player.start()
@bot.command(pass_context=True, aliases = ["dofronty","add"]) #, aliases=
["fronta"])
async def queue(ctx, url):
server = ctx.message.server
voice_client = bot.voice_client_in(server)
player = await voice_client.create_ytdl_player(url, after = lambda: checkqueue(server.id))
if server.id in queued:
queued[server.id].append(player)
else:
queued[server.id] = [player]
await bot.say("Přidáno do fronty :ok_hand:")
urls.append(url)
信息收集器:
from __future__ import unicode_literals
import youtube_dl
ydl_opts = {}
def getvidinfo(url):
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
meta = ydl.extract_info(
url, download=False)
return meta