mps-youtube / pafy

Python library to download YouTube content and retrieve metadata
1.38k stars 315 forks source link

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

Closed FLYAX closed 2 years ago

FLYAX commented 2 years ago

I'm getting this error and I dont know what to do about it.

GdataError at /

Youtube Error 403: The request cannot be completed because you have exceeded your <a href="/youtube/v3/getting-started#quota">quota</a>.
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 })
FLYAX commented 2 years ago

Okay, so the error was that the YouTube API key from pafy is used to often so I had to create and define my own one.

https://pythonhosted.org/pafy/#api-keys https://cloud.google.com/docs/authentication/api-keys?authuser=1&hl=de