问题描述
错误:
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
之类的库 - 使用
aiohttp
(pafy
的异步版本)和re
查找视频ID。最后一个选择可能是最快的选择。
如果您想要一个更简单的解决方案,可以使用pytube
,但它速度较慢,并且最多支持python 3.7。