【问题标题】:youtube_dl error: Failed to parse JSON (caused by JSONDecodeError('Expecting value: line 1 column 1 (char 0)')) disocrd erroryoutube_dl 错误:无法解析 JSON(由 JSONDecodeError('期望值:第 1 行第 1 列(char 0)')引起)disocrd 错误
【发布时间】:2021-02-07 20:06:28
【问题描述】:

错误:

youtube_dl.utils.DownloadError: ERROR: query "song": 无法解析 JSON(由 JSONDecodeError('Expecting value: line 1 column 1 (char 0)') 引起)

播放命令:

    @commands.command(name='play',aliases=['p'] )
    async def _play(self, ctx: commands.Context, *, search: str):
        async with ctx.typing():
            try:
                source = await YTDLSource.create_source(ctx, search, loop=self.bot.loop)
            except YTDLError as e:
                await ctx.send('Error: {}'.format(str(e)))
            else:
                song = Song(source)

                await ctx.voice_state.songs.put(song)

Youtube-DL 类:

class YTDLSource(discord.PCMVolumeTransformer):
    YTDL_OPTIONS = {
        'format': 'bestaudio/best',
        'extractaudio': True,
        'audioformat': 'mp3',
        '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 = {
        'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
        'options': '-vn',
    }

    ytdl = youtube_dl.YoutubeDL(YTDL_OPTIONS)

请指导我如何解决这个错误 这个错误是上周开始的,我的 youtube_dl 也更新了

如果您需要其他代码,请告诉我,但请解决我的问题

我也不知道如何获取包括堆栈跟踪在内的错误消息

【问题讨论】:

    标签: python discord discord.py youtube-dl ytdl


    【解决方案1】:

    您遇到此错误是因为 youtube-dl 已被删除,这意味着它不再可供公众访问。

    您可以使用pafy 之类的库,而不是直接使用youtube-dl,它使用youtube-dl 的命令行版本:

    from pafy import new
    
    @client.command(pass_context=True)
    async def play(ctx):
        ffmpeg_opts = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
        channel = ctx.author.voice.channel
        voice = await channel.connect()
    
        video = new("youtube video link")
        audio = video.getbestaudio().url
        voice.play(FFmpegPCMAudio(audio, **ffmpeg_opts))
        voice.is_playing()
    

    pafy 不包括 youtube 搜索,因此您必须自己做。为此,您有多种选择:

    • 使用bs4 进行一些网页抓取
    • 使用像 fast-youtube-search 这样的库
    • 使用aiohttp(这是requests的异步版本)和re查找视频ID。最后一个选项可能是最快的一个。

    如果您想要一个更简单的解决方案,您可以使用pytube,但它速度较慢并且最高支持 python 3.7。

    【讨论】:

    • 有什么方法可以使用这个 youtube-dl 吗?我什至可以付款,没问题
    • 不,你不能再使用它了。您可以尝试与存储库所有者交谈,但我认为这没有任何用处。如果你想知道它为什么被撤下,你可以去youtube-dl的github页面:github.com/ytdl-org/youtube-dl
    • 谢谢我用了第二种方法
    猜你喜欢
    • 1970-01-01
    • 2019-07-04
    • 1970-01-01
    • 2018-08-28
    • 2021-09-30
    • 1970-01-01
    • 2021-03-25
    • 2019-08-21
    • 1970-01-01
    相关资源
    最近更新 更多