Pytube hatası : raise RegexMatchError( pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple

import webbrowser
import requests

def youtube(aranan_kelime:str, api_key:str) -> dict:
    url = f"https://youtube.googleapis.com/youtube/v3/search?maxResults=1&part=snippet&q={aranan_kelime.replace(' ','+')}&key={api_key}"
    response = requests.get(url)
    return response.json()

ARANAN_KELİME = "killka ghostface" # şarkı adı
API_KEY = "<API_KEY>"
videoID = youtube(aranan_kelime=ARANAN_KELİME, api_key=API_KEY)
webbrowser.open(f"https://www.youtube.com/watch?v={videoID['items'][0]['id']['videoId']}")

Youtube Data APIv3 kullandım.

Eğer birşekilde url ile işlem yapıp ilgili videoyu indirebilirseniz, Pytube kütüphanesine de gerek kalmayabilir.

EDİT:
mp3 indirmek için;
Pytube yerine youtube_dl kullandım. Kod şu hale geldi:

import webbrowser
import requests
import youtube_dl

def youtube(aranan_kelime:str, api_key:str) -> dict:
    url = f"https://youtube.googleapis.com/youtube/v3/search?maxResults=1&part=snippet&q={aranan_kelime.replace(' ','+')}&key={api_key}"
    response = requests.get(url)
    return response.json()

ARANAN_KELİME = "killka ghostface" # şarkı adı
API_KEY = "<API_KEY>"
videoID = youtube(aranan_kelime=ARANAN_KELİME, api_key=API_KEY)
link = f"https://www.youtube.com/watch?v={videoID['items'][0]['id']['videoId']}"

filename = f"{ARANAN_KELİME.replace(' ','_')}.mp3"
options={
    'format':'bestaudio/best',
    'keepvideo':False,
    'outtmpl':filename,
    }

with youtube_dl.YoutubeDL(options) as ydl:
    ydl.download([link])

Kaynak:

1 Beğeni