discord.py 和 youtube_dl,“读取错误";和“会话因某种原因已失效" [英] discord.py and youtube_dl, "Read error" and "The session has been invalidated for some reason"

查看:34
本文介绍了discord.py 和 youtube_dl,“读取错误";和“会话因某种原因已失效"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 discord.py 和 youtube_dl 时遇到了这个问题,在队列中播放 YouTube 链接给我一个错误,似乎滚雪球"进入队列中的其他歌曲.第一首歌通常播放得很好,但其他歌曲在很短的时间后就会出现这个错误.这是错误:

I have been running into this issue with discord.py and youtube_dl where playing YouTube links in a queue gives me an error that seems to "snowball" into the other songs in the queue. The first song usually plays just fine, but then the rest of the songs give this error after a very short period of time. This is the error:

[tls @ 000001e5618bc200] Error in the pull function.
[matroska,webm @ 000001e5613f9740] Read error
[tls @ 000001e5618bc200] The specified session has been invalidated for some reason.
Last message repeated 1 times
[really long link] I/O error

这是我的 YTDL 源代码和队列函数:

And this is my code for the YTDL source and the queue function:

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):
        loop = loop or asyncio.get_event_loop()
        data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream))

        if 'entries' in data:
            # take first item from a playlist
            data = data['entries'][0]

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



queues = {}

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

    @commands.command()
    async def q(self, ctx, *, url):
        channel = discord.utils.get(ctx.guild.voice_channels, name="Melodies of Arts")

        if ctx.voice_client is None:
            await channel.connect()


        def check_queue(error):
            if(queues[ctx.guild.id] != []):
                player = queues[ctx.guild.id].pop(0)
                ctx.voice_client.play(player, after=check_queue)     

        async with ctx.typing():
            player = await YTDLSource.from_url(url, loop=self.bot.loop, stream=True)

            if ctx.guild.id in queues:
                queues[ctx.guild.id].append(player)
            else:
                queues[ctx.guild.id] = [player]

            await ctx.send("Video __" + str(player.title) + "__" + " queued at **Position #" + str(len(queues[ctx.guild.id])) + "**", delete_after=15)

            if(not ctx.voice_client.is_playing()):
                ctx.voice_client.play(player, after=check_queue)
                await ctx.send('***Now playing:*** __{}__'.format(player.title), delete_after=10)

Github 问题页面建议重新下载 url",但我正在使用 youtube_dl 流式传输链接,并且我希望尽可能避免下载视频.无论如何,很多 Github 问题似乎都已经过时了,因此任何与代码相关的解决方案都不再适用.如果我需要提供更多代码/信息,请告诉我!

A Github issue page recommended to "redownload the url", but I am streaming the the link using youtube_dl, and I would like to avoid downloading the video if possible. A lot of the Github issues seem to be too outdated anyway, so any solutions relating to code do not work anymore. If I need to provide more code/information let me know!

推荐答案

正如人们常说的,这真的不是你的错".这通常发生在 YouTube 方面.

As people like to say, "It's really not your fault". This usually happens from the YouTube side.

看看:Python Youtube ffmpeg 会话已失效

另外,请检查您是否使用 https 进行了调用.YouTube 不再接受 http 连接.

Also, check that you called using https. YouTube no longer accepts http connections.

这篇关于discord.py 和 youtube_dl,“读取错误";和“会话因某种原因已失效"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆