Как получить информацию о видео с Youtube_dl? - PullRequest
0 голосов
/ 20 сентября 2018

Я занимаюсь разработкой диска-бота, который также может воспроизводить музыку с 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)

Информация scrapper:

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
...