gpt4 book ai didi

ffmpeg - Python Youtube ffmpeg session 已失效

转载 作者:行者123 更新时间:2023-12-04 17:41:53 30 4
gpt4 key购买 nike

使用机器人播放 YouTube 音频时出现以下错误

[tls @ 0000024ef8c4d480] Error in the pull function.
[matroska,webm @ 0000024ef8c4a400] Read error
[tls @ 0000024ef8c4d480] The specified session has been invalidated for some reason.
Last message repeated 1 times

YouTube 链接好像过期了?我真的不知道,但我需要解决这个问题。这是我的代码:

    class YTDLSource(discord.PCMVolumeTransformer):

def __init__(self, source, *, data, requester):
super().__init__(source)
self.requester = requester

self.title = data['title']
self.description = data['description']
self.uploader = data['uploader']
self.duration = data['duration']
self.web_url = data['webpage_url']
self.thumbnail = data['thumbnail']

def __getitem__(self, item: str):
return self.__getattribute__(item)

@classmethod
async def create_source(cls, ctx, player, search: str, *, loop, download=True):
async with ctx.typing():
loop = loop or asyncio.get_event_loop()
to_run = partial(ytdl.extract_info, url=search, download=download)
raw_data = await loop.run_in_executor(None, to_run)

if 'entries' in raw_data:
# take first item from a playlist
if len(raw_data['entries']) == 1:
data = raw_data['entries'][0]
else:
data = raw_data['entries']
#loops entries to grab each video_url
total_duration = 0
try:
for i in data:
webpage = i['webpage_url']
title = i['title']
description = i['description']
uploader = i['uploader']
duration = i['duration']
thumbnail = i['thumbnail']
total_duration += duration

if download:
source = ytdl.prepare_filename(i)
source = cls(discord.FFmpegPCMAudio(source), data=i, requester=ctx.author)
else:
source = {'webpage_url': webpage, 'requester': ctx.author, 'title': title, 'uploader': uploader, 'description': description, 'duration': duration, 'thumbnail': thumbnail}

player.queue.append(source)

except Exception as e:
print(e)
return

embed=discord.Embed(title="Playlist", description="Queued", color=0x30a4fb, timestamp=datetime.now(timezone.utc))
embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url)
embed.set_thumbnail(url=data[0]['thumbnail'])
embed.add_field(name=raw_data['title'], value=f"{len(data)} videos queued.", inline=True)
embed.set_footer(text=raw_data["uploader"] + ' - ' + '{0[0]}m {0[1]}s'.format(divmod(total_duration, 60)))
await ctx.send(embed=embed)
return

embed=discord.Embed(title="Playlist", description="Queued", color=0x30a4fb, timestamp=datetime.now(timezone.utc))
embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url)
embed.set_thumbnail(url=data['thumbnail'])
embed.add_field(name=data['title'], value=(data["description"][:72] + (data["description"][72:] and '...')), inline=True)
embed.set_footer(text=data["uploader"] + ' - ' + '{0[0]}m {0[1]}s'.format(divmod(data["duration"], 60)))
await ctx.send(embed=embed)

if download:
source = ytdl.prepare_filename(data)
else:
source = {'webpage_url': data['webpage_url'], 'requester': ctx.author, 'title': data['title'], 'uploader': data['uploader'], 'description': data['description'], 'duration': data['duration'], 'thumbnail': data['thumbnail']}
player.queue.append(source)
return

source = cls(discord.FFmpegPCMAudio(source), data=data, requester=ctx.author)
player.queue.append(source)


@classmethod
async def regather_stream(cls, data, *, loop):
loop = loop or asyncio.get_event_loop()
requester = data['requester']

to_run = partial(ytdl.extract_info, url=data['webpage_url'], download=True)
data = await loop.run_in_executor(None, to_run)

return(cls(discord.FFmpegPCMAudio(data['url']), data=data, requester=requester))

我正在为机器人使用 discord.py 的重写分支。
我不确定是否需要提供更多详细信息?请告诉我,我真的需要解决这个问题......

最佳答案

实际上,您的代码并不是真正的问题(许多人提示此错误)。

这只是流式传输视频时可能出现的问题。如果您绝对想流式传输它,则必须接受这是一个潜在问题。请注意(几乎)每个音乐机器人如何为您想要收听的视频/音乐设置限制。

如果您需要确保不会遇到此问题,则必须完全下载音乐。 (这也将使机器人在播放前加载更长的时间)。

关于ffmpeg - Python Youtube ffmpeg session 已失效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54139166/

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