gpt4 book ai didi

python - 是否可以使用 discord.py(从视频中的给定时间戳播放)搜索流式 youtube 音频?

转载 作者:行者123 更新时间:2023-12-04 22:58:17 25 4
gpt4 key购买 nike

不幸的是,传入带有 &t= 标签的 URL 不会导致 discord.pyVoiceClient在该时间戳开始播放。我正在使用 youtube_dl .

是否可以在 discord.py 中寻找音频,以便从开头以外的某个地方开始流式传输 YouTube 视频?

我知道一些专业的机器人,例如 Groovy具有用于流式 YouTube 视频的搜索命令,因此 Discord API 本身能够做到这一点。

我使用的代码来自 here .

最佳答案

ffmpeg_options ,您可以使用 -ss 查找特定的时间戳。旗帜。

如果您希望从例如 40 秒开始,这就是选项的外观:

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

当然,您可以将可选变量添加到 stream命令:

import typing # for the optional argument of the timestamp

@classmethod
async def from_url(cls, url, *, loop=None, stream=False, timestamp=0):
# moved the options from outside the class to inside the method.
# this allows the use of variables in the options
ffmpeg_options = {
'options': f'-vn -ss {timestamp}'
}
# rest of the from_url code

@commands.command()
async def stream(self, ctx, timestamp: typing.Optional[int]=0, *, url): # add the arg
"""Streams from a url (same as yt, but doesn't predownload)"""

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

我只添加了我从音乐机器人示例编辑的代码,所以我希望我编辑的内容很清楚。如果需要进一步澄清/某些东西是如何工作的,那么我很乐意进行编辑。

引用文献:
  • FFMPEG Docs - Ctrl + F 用于 -ss .
  • Optional arguments in discord commands
  • f-strings - Python 3.6.0+
  • 关于python - 是否可以使用 discord.py(从视频中的给定时间戳播放)搜索流式 youtube 音频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62354887/

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