python - 是否可以使用discord.py 查找流式YouTube 音频(从视频中给定的时间戳开始播放)?

标签 python ffmpeg discord.py youtube-dl

遗憾的是,传入带有 &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

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


引用文献:

关于python - 是否可以使用discord.py 查找流式YouTube 音频(从视频中给定的时间戳开始播放)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62354887/

相关文章:

video - ffmpeg 编辑元数据major_brand

bash - 如何使用 FFmpeg 将视频拆分为 <2.5GB 的部分

python - Pandas 中的滚动行过滤器/交叉表?

python - Matplotlib 均匀分布的轮廓线

dll - 在 XP 上部署 ffmpeg 流应用程序时出现 strncpy_s 错误

python - 如果用户在 channel 中发送命令,则等待 DM 中的消息问题

python - 在 discord.py 中更改昵称会引发错误

python - 从消息中提取用户名模式

python - 从Python中的排序列表中获取某些数据

python - 如何将 for 循环转换为递归方法?