Reputation: 1
I cannot use the video download feature via pytube
The code I ran yesterday is not working today. How can I fix the error for pytube 15.0.0?
def video_indir(video_url, dosya_adi):
video = pytube.YouTube(video_url)
audio_stream = video.streams.filter(only_audio=True).first()
audio_dosya = f'{dosya_adi}.mp4'
audio_stream.download(filename=audio_dosya)
return audio_dosya
The error I got is here, the solution is elsewhere."
In Pytube version 15.0.0, you just need to remove ; in line 287 of cipher.py file.
Change r'var {nfunc}\s*=\s*(\[.+?\];)'.format(
to r'var {nfunc}\s*=\s*(\[.+?\])'.format(
" but I didn't understand it
RegexMatchError: get_throttling_function_name: could not find match for multiple
Traceback:
File "C:\Users\suleymanyasar\Desktop\staj\çalışmalarım\myenv\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 589, in _run_script
exec(code, module.__dict__)
File "C:\Users\suleymanyasar\Desktop\staj\çalışmalarım\07-DenemeAI\deneme_app.py", line 76, in <module>
audio_dosya = video_indir(video_url, dosya_adi)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\suleymanyasar\Desktop\staj\çalışmalarım\07-DenemeAI\deneme_app.py", line 30, in video_indir
audio_stream = video.streams.filter(only_audio=True).first()
^^^^^^^^^^^^^
File "C:\Users\suleymanyasar\Desktop\staj\çalışmalarım\myenv\Lib\site-packages\pytube\__main__.py", line 296, in streams
return StreamQuery(self.fmt_streams)
^^^^^^^^^^^^^^^^
File "C:\Users\suleymanyasar\Desktop\staj\çalışmalarım\myenv\Lib\site-packages\pytube\__main__.py", line 188, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "C:\Users\suleymanyasar\Desktop\staj\çalışmalarım\myenv\Lib\site-packages\pytube\extract.py", line 409, in apply_signature
cipher = Cipher(js=js)
^^^^^^^^^^^^^
File "C:\Users\suleymanyasar\Desktop\staj\çalışmalarım\myenv\Lib\site-packages\pytube\cipher.py", line 43, in __init__
self.throttling_plan = get_throttling_plan(js)
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\suleymanyasar\Desktop\staj\çalışmalarım\myenv\Lib\site-packages\pytube\cipher.py", line 405, in get_throttling_plan
raw_code = get_throttling_function_code(js)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\suleymanyasar\Desktop\staj\çalışmalarım\myenv\Lib\site-packages\pytube\cipher.py", line 311, in get_throttling_function_code
name = re.escape(get_throttling_function_name(js))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\suleymanyasar\Desktop\staj\çalışmalarım\myenv\Lib\site-packages\pytube\cipher.py", line 296, in get_throttling_function_name
raise RegexMatchError(
Upvotes: 0
Views: 1189
Reputation: 1
its an issue i have faced recently with pytube you can just use the pytubefix fork on github from the pytubefix
pip install pytubefix
Upvotes: 0
Reputation: 11
Change the function_patterns
array in cipher.py
at line 264 to include this one and it seems to work:
function_patterns = [
# https://github.com/ytdl-org/youtube-dl/issues/29326#issuecomment-865985377
# https://github.com/yt-dlp/yt-dlp/commit/48416bc4a8f1d5ff07d5977659cb8ece7640dcd8
# var Bpa = [iha];
# ...
# a.C && (b = a.get("n")) && (b = Bpa[0](b), a.set("n", b),
# Bpa.length || iha("")) }};
# In the above case, `iha` is the relevant function name
r'a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&.*?\|\|\s*([a-z]+)',
r'\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])?\([a-z]\)',
r'\([a-z]\s*=\s*([a-zA-Z0-9$]+)(\[\d+\])\([a-z]\)',
]
Reference: https://github.com/amckee/PodTube/blob/master/cipher.patch
Upvotes: 1