gpt4 book ai didi

python - Discord py - 错误 : Unable to extract JS player URL

转载 作者:行者123 更新时间:2023-12-04 08:40:30 25 4
gpt4 key购买 nike

嘿伙计们,
我正在尝试使用 youtube-dl 制作自己的不和谐音乐机器人。
由于原始的 youtube-dl 不再可用,我使用最新版本的副本

https://github.com/l1ving/youtube-dl


有时机器人工作正常,但有时我会收到此错误

ERROR: Unable to extract JS player URL


有趣的是,这种情况并非每次都发生 - 6/10 例
我的代码是什么样的:
import discord
import asyncio
import os
import youtube_dl

import urllib.parse, urllib.request, re
import requests

from discord.ext import commands
from discord import Embed, FFmpegPCMAudio
from discord.utils import get

'''

INSTALLING YOUTUBE-DL

pip install -U git+https://github.com/l1ving/youtube-dl

'''

queue = []

youtube_dl.utils.bug_reports_message = lambda: ''

ytdl_format_options = {
'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',
'source_address': '0.0.0.0'
}

ffmpeg_options = {
'options': '-vn'
}

ytdl = youtube_dl.YoutubeDL(ytdl_format_options)

class YTDLSource(discord.PCMVolumeTransformer):
def __init__(self, source, *, data, volume=0.5):
super().__init__(source, volume)

self.data = data

self.title = data.get('title')
self.url = data.get('url')

@classmethod
async def from_url(cls, url, *, loop=None, stream=False, play=False):
loop = loop or asyncio.get_event_loop()
data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream or play))

if 'entries' in data:
data = data['entries'][0]

filename = data['url'] if stream else ytdl.prepare_filename(data)
return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_options), data=data)


class Music(commands.Cog):
def __init__(self, bot):
self.bot = bot

@commands.command()
async def join(self, ctx):

if not ctx.message.author.voice:
await ctx.send("You are not connected to a voice channel!")
return
else:
channel = ctx.message.author.voice.channel
await ctx.send(f'Connected to ``{channel}``')

await channel.connect()

@commands.command()
async def play(self, ctx, *, url):

try:

async with ctx.typing():
player = await YTDLSource.from_url(url, loop=self.bot.loop, stream=True)
ctx.voice_client.play(player, after=lambda e: print('Player error: %s' % e) if e else None)

await ctx.send(f':mag_right: **Searching for** ``' + url + '``\n<:youtube:763374159567781890> **Now Playing:** ``{}'.format(player.title) + "``")

except:

await ctx.send("Somenthing went wrong - please try again!")

@commands.command()
async def pause(self, ctx):
voice = get(self.bot.voice_clients, guild=ctx.guild)

voice.pause()

user = ctx.message.author.mention
await ctx.send(f"Bot was paused by {user}")

@commands.command()
async def resume(self, ctx):
voice = get(self.bot.voice_clients, guild=ctx.guild)

voice.resume()

user = ctx.message.author.mention
await ctx.send(f"Bot was resumed by {user}")

@commands.command()
async def leave(self, ctx):
voice_client = ctx.message.guild.voice_client
user = ctx.message.author.mention
await voice_client.disconnect()
await ctx.send(f'Disconnected from {user}')


@play.before_invoke
async def ensure_voice(self, ctx):
if ctx.voice_client is None:
if ctx.author.voice:
await ctx.author.voice.channel.connect()
else:
await ctx.send("You are not connected to a voice channel.")
raise commands.CommandError("Author not connected to a voice channel.")
elif ctx.voice_client.is_playing():
ctx.voice_client.stop()

def setup(client):
client.add_cog(Music(client))
我不知道为什么有时会发生这种情况??也许你们中的一个人知道答案:)

最佳答案

由于 DMCA 删除,存储库不可用。
由于 ,此存储库当前已禁用DMCA 删除通知 .我们已禁用对存储库的公共(public)访问。该通知已公开发布。
https://github.com/ytdl-org/youtube-dl/issues/26168

关于python - Discord py - 错误 : Unable to extract JS player URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64590839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com