Tadevosyan Mikael
Tadevosyan Mikael

Reputation: 31

Pytube error when I'm trying download video

When I tried to download video with pytube there was error: pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple.

I saw this here, but when I tried it didn't work. (if it's only decision please send all code of cipher.py)

Here's the code

from pytube import YouTube

stream = YouTube("https://www.youtube.com/watch?v=SBQprWeOx8g").streams.get_highest_resolution()
stream.download('video.mp4')

Upvotes: 3

Views: 5726

Answers (2)

Raspberry Jam
Raspberry Jam

Reputation: 1

I was having a similar issue.

Tracing the error, it seems like the point of failure was at 286 of cipher.py

array = re.search(
    r'var {nfunc}\s*=\s*(\[.+?\]);'.format(
        nfunc=re.escape(function_match.group(1))),
    js
)

This line is supposed to find a particular assignment within the youtubeObject.js it's given, and in my case the line in question did in fact exist and looked like this:

var Msa=[ema],Jsa=!1;

Now I'm pretty sure it's that comma that's throwing a wrench in things, the regex is expecting the line to end in a plain semicolon and since the line it would have found did not have a ; after the ], array found None and threw the error

I edited line 287 from

r'var {nfunc}\s*=\s*(\[.+?\]);'.format(

to

r'var {nfunc}\s*=\s*(\[.+?\])[;,]'.format(

in order for it to be able to match either the assignment being on its own or the assignment being done together with a second variable (as it was here)

Unfortunately I am an amateur and can't reliably tell you where the packages are located, but in my figuring this out I reinstalled python via the microsoft store and my cipher.py is located at C:\Users\###\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pytube\cipher.py

Upvotes: 0

debugger
debugger

Reputation: 1746

Upgarde pytube to 12.0.0

python3 -m pip install --upgrade pytube

Then if you get error: AttributeError: 'NoneType' object has no attribute 'span' go to your python root folder like:

C:\Users\#\AppData\Local\Programs\Python\Python310\Lib\site-packages\pytube\parser.py

Change this line: 152: func_regex = re.compile(r"function\([^)]+\)")

to this: 152: func_regex = re.compile(r"function\([^)]?\)")

if it doesn't work then try : in pytube/cipher.py on line 311:

change : name = re.escape(get_throttling_function_name(js))

to : name = "hha"

Upvotes: 1

Related Questions