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

Evet bildiğiniz gibi youtube’a ne zaman güncelleme gelirse pytube modülü çöküyor bir süreliğine bunu biliyoruz.Peki bu sefer nasıl çözeceğim? Önceki hatamdan farklı bir hata veriyor hatayı arattım ve daha eski bir soruya denk geldim başka bir forumda ancak o çözümleri denediğimde çalışmadı aldığım hata ise şu:

 Exception in thread Thread-4:
 Traceback (most recent call last):
   File "C:\Users\alper\PycharmProjects\Project2\venv\lib\site-packages\pytube\__main__.py", line 181, in fmt_streams
     extract.apply_signature(stream_manifest, self.vid_info, self.js)
   File "C:\Users\alper\PycharmProjects\Project2\venv\lib\site-packages\pytube\extract.py", line 409, in apply_signature
     cipher = Cipher(js=js)
   File "C:\Users\alper\PycharmProjects\Project2\venv\lib\site-packages\pytube\cipher.py", line 43, in __init__
     self.throttling_plan = get_throttling_plan(js)
   File "C:\Users\alper\PycharmProjects\Project2\venv\lib\site-packages\pytube\cipher.py", line 405, in get_throttling_plan
     raw_code = get_throttling_function_code(js)
   File "C:\Users\alper\PycharmProjects\Project2\venv\lib\site-packages\pytube\cipher.py", line 311, in get_throttling_function_code
     name = re.escape(get_throttling_function_name(js))
   File "C:\Users\alper\PycharmProjects\Project2\venv\lib\site-packages\pytube\cipher.py", line 296, in get_throttling_function_name
     raise RegexMatchError(
 pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple
 
 During handling of the above exception, another exception occurred:
 
 Traceback (most recent call last):
   File "C:\Users\alper\AppData\Local\Programs\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
     self.run()
   File "C:\Users\alper\AppData\Local\Programs\Python\Python39\lib\threading.py", line 892, in run
     self._target(*self._args, **self._kwargs)
   File "C:\Users\alper\PycharmProjects\Project2\a.py", line 183, in streams
     streams = YouTube(url=self.url).streams.filter(only_audio=True)
   File "C:\Users\alper\PycharmProjects\Project2\venv\lib\site-packages\pytube\__main__.py", line 296, in streams
     return StreamQuery(self.fmt_streams)
   File "C:\Users\alper\PycharmProjects\Project2\venv\lib\site-packages\pytube\__main__.py", line 188, in fmt_streams
     extract.apply_signature(stream_manifest, self.vid_info, self.js)
   File "C:\Users\alper\PycharmProjects\Project2\venv\lib\site-packages\pytube\extract.py", line 409, in apply_signature
     cipher = Cipher(js=js)
   File "C:\Users\alper\PycharmProjects\Project2\venv\lib\site-packages\pytube\cipher.py", line 43, in __init__
     self.throttling_plan = get_throttling_plan(js)
   File "C:\Users\alper\PycharmProjects\Project2\venv\lib\site-packages\pytube\cipher.py", line 405, in get_throttling_plan
     raw_code = get_throttling_function_code(js)
   File "C:\Users\alper\PycharmProjects\Project2\venv\lib\site-packages\pytube\cipher.py", line 311, in get_throttling_function_code
     name = re.escape(get_throttling_function_name(js))
   File "C:\Users\alper\PycharmProjects\Project2\venv\lib\site-packages\pytube\cipher.py", line 296, in get_throttling_function_name
     raise RegexMatchError(
 pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple
[INFO   ] [Base        ] Leaving application in progress...

Process finished with exit code 0

Yardımcı olursanız çok sevinirim, teşekkürler…

1 Beğeni
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

pytube’nin ciper.py’nin function_patterns’ini aşağıdakiyle değiştirmeniz gerekiyor.

r'a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&\s*'
r'\([a-z]\s*=\s*([a-zA-Z0-9$]{2,3})(\[\d+\])?\([a-z]\)',

Bunu yaptıktan sonra tahmini 290. satırı
nfunc=re.escape(function_match.group(1))),
Bu ifade ile değiştirince çalıştırmayı başardım.

1 Beğeni

Teşekkürler, çalıştı

1 Beğeni