youtube_dl错误:无法解析JSON由JSONDecodeError'Expecting value:line 1 column 1char 0'造成disocrd错误

问题描述

错误

youtube_dl.utils.DownloadError:错误查询“歌曲”:无法解析JSON(由JSONDecodeError('期望值:第1行第1列(字符0)')

播放命令:

       <mat-form-field fxFlex=20 appearance="outline" 
         *ngFor="let pay of loanDetails.paymentOptions; index as i;">
            <mat-label>Start Date</mat-label>
             <!--see that use always 'picker'-->
            <input matInput [matDatepicker]="picker" placeholder="Start date" [(ngModel)]="pay.paymentDate" (dateChange)="getLoanOutputData()">
            <!--again 'picker'-->
            <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
            <!--and again 'picker'-->
            <mat-datepicker #picker></mat-datepicker>
        </mat-form-field>

Youtube-DL类:

    @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也已更新

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

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

解决方法

出现此错误是因为youtube-dl被删除了,这意味着它不再可供公众使用。

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

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() 不包含youtube搜索,因此您必须自己做。为此,您有多种选择:

  • 使用bs4
  • 进行网络抓取
  • 使用fast-youtube-search之类的库
  • 使用aiohttppafy的异步版本)和re查找视频ID。最后一个选择可能是最快的选择。

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...