1

使用 pafy 转换视频时出现此错误

GdataError at / Youtube Error 403: The request cannot be completed because you have exceeded your <a href="/youtube/v3/getting-started#quota">quota</a>.

这是我的代码(views.py):

def download_video(request):
    global context
    form = DownloadForm(request.POST or None)
    if form.is_valid():
        video_url = form.cleaned_data.get("url")
        if 'm.' in video_url:
            video_url = video_url.replace(u'm.', u'')

        elif 'youtu.be' in video_url:
            video_id = video_url.split('/')[-1]
            video_url = 'https://www.youtube.com/watch?v=' + video_id

        if len(video_url.split("=")[-1]) != 11:
            return HttpResponse('Enter correct url.')

        video = pafy.new(video_url)
        stream = video.streams
        video_audio_streams = []
        for s in stream:
            video_audio_streams.append({
                'resolution': s.resolution,
                'extension': s.extension,
                'file_size': filesizeformat(s.get_filesize()),
                'video_url': s.url + "&title=" + video.title
            })

        stream_video = video.videostreams
        video_streams = []
        for s in stream_video:
            video_streams.append({
                'resolution': s.resolution,
                'extension': s.extension,
                'file_size': filesizeformat(s.get_filesize()),
                'video_url': s.url + "&title=" + video.title
            })

        stream_audio = video.audiostreams
        audio_streams = []
        for s in stream_audio:
            audio_streams.append({
                'resolution': s.resolution,
                'extension': s.extension,
                'file_size': filesizeformat(s.get_filesize()),
                'video_url': s.url + "&title=" + video.title
            })

        context = {
            'form': form,
            'title': video.title, 'streams': video_audio_streams,
            'description': video.description, 'likes': video.likes, 'thumb': video.bigthumbhd,
            'duration': video.duration, 'views': video.viewcount,
            'stream_video': video_streams, 'stream_audio': audio_streams
        }

        return render(request, 'home.html', context)

    return render(request, 'home.html', { 'form': form })

也许错误是从另一个文件触发的,我必须从扩展名更改后端的某些内容,但我不知道是什么。

我正在使用 Django、Pafy、Pytz 和 Youtube-dl

4

1 回答 1

0

您在 中执行了太多API操作YouTube。如果您每天达到 10.000 点,您将受到限制。在此处阅读:https ://developers.google.com/youtube/v3/getting-started#quota

您可以在另一个 StackOverflow Question中阅读类似的内容。

于 2022-02-05T18:52:55.573 回答