question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG]: pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple

See original GitHub issue

Before creating an issue

Please confirm that you are on the latest version of pytube by installing from the source. You can do this by running python -m pip install git+https://github.com/pytube/pytube. Sometimes, the pypi library repository is not up to date, and your issue may have been fixed already!

Describe the bug Regex error?

To Reproduce Please provide the following information:

  • The video or playlist url that is causing the error.
  • The code where the problem is occurring.
# MIT License
#
# Copyright (c) 2022-Present Advik-B <advik.b@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# assert __name__ != "__main__", "This module should not be run directly. Import it instead."
import pytube
import py7zr
import requests
import asyncio
import os

CACHE_PATH = 'cache' 

def before_start():
    """ Before the bot starts """
    if not os.path.exists(CACHE_PATH):
        os.mkdir(CACHE_PATH)


async def search(query:str, max_results:int=None):
    """ Search for a video on YouTube """
    if max_results is None:
        max_results = 10
    return pytube.YouTube(query).search(max_results=max_results)

async def download_audio(video:pytube.YouTube):
    """ Download the audio of a video """
    audio = video.streams.filter(only_audio=True).first()
    path = os.path.join(CACHE_PATH, video.video_id + '.mp3')
    with open(path, 'wb') as f:
        audio.stream_to_buffer(f)
    return path

def cache_video(path:str):
    """ Cache a video and zip it """

    with py7zr.SevenZipFile(path, 'wb') as archive:
        archive.write(file=path)

def main():
    before_start()
    """ Main function """
    video = pytube.YouTube('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
    asyncio.run(download_audio(video))

if __name__ == "__main__":
    main()

Expected behavior It will download/stream the video to buffer and 7-zip it

Output

Traceback (most recent call last):
  File "E:\Github\PulseDiscord\src\venv\lib\site-packages\pytube\__main__.py", line 181, in fmt_streams   
    extract.apply_signature(stream_manifest, self.vid_info, self.js)
  File "E:\Github\PulseDiscord\src\venv\lib\site-packages\pytube\extract.py", line 409, in apply_signature
    cipher = Cipher(js=js)
  File "E:\Github\PulseDiscord\src\venv\lib\site-packages\pytube\cipher.py", line 43, in __init__
    self.throttling_plan = get_throttling_plan(js)
  File "E:\Github\PulseDiscord\src\venv\lib\site-packages\pytube\cipher.py", line 405, in get_throttling_plan
    raw_code = get_throttling_function_code(js)
  File "E:\Github\PulseDiscord\src\venv\lib\site-packages\pytube\cipher.py", line 311, in get_throttling_function_code
    name = re.escape(get_throttling_function_name(js))
  File "E:\Github\PulseDiscord\src\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 "e:\Github\PulseDiscord\src\modules\indexer.py", line 65, in <module>
    main()
  File "e:\Github\PulseDiscord\src\modules\indexer.py", line 62, in main
    asyncio.run(download_audio(video))
  File "D:\Program Files\Python39\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "D:\Program Files\Python39\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "e:\Github\PulseDiscord\src\modules\indexer.py", line 46, in download_audio
    audio = video.streams.filter(only_audio=True).first()
  File "E:\Github\PulseDiscord\src\venv\lib\site-packages\pytube\__main__.py", line 296, in streams
    return StreamQuery(self.fmt_streams)
  File "E:\Github\PulseDiscord\src\venv\lib\site-packages\pytube\__main__.py", line 188, in fmt_streams
    extract.apply_signature(stream_manifest, self.vid_info, self.js)
  File "E:\Github\PulseDiscord\src\venv\lib\site-packages\pytube\extract.py", line 409, in apply_signature
    cipher = Cipher(js=js)
  File "E:\Github\PulseDiscord\src\venv\lib\site-packages\pytube\cipher.py", line 43, in __init__
    self.throttling_plan = get_throttling_plan(js)
  File "E:\Github\PulseDiscord\src\venv\lib\site-packages\pytube\cipher.py", line 405, in get_throttling_plan
    raw_code = get_throttling_function_code(js)
  File "E:\Github\PulseDiscord\src\venv\lib\site-packages\pytube\cipher.py", line 311, in get_throttling_function_code
    name = re.escape(get_throttling_function_name(js))
  File "E:\Github\PulseDiscord\src\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

System information Please provide the following information:

  • Python version: Python 3.9.7
  • Pytube version: 2.0.0
  • Command used to install pytube: pip install pytube

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:11

github_iconTop GitHub Comments

19reactions
TinKurbatoffcommented, May 4, 2022

Hey, explored the error. And found the reason and a solution. For those who want to fix it immediately: image ——— Look for the file .local/lib/python<your version>/site-packages/pytube/cipher.py in my case: .local/lib/python3.8/site-packages/pytube/cipher.py Replace with the following regex string at line 272 (and don’t forget about the comma!):

r'a\.[a-zA-Z]\s*&&\s*\([a-z]\s*=\s*a\.get\("n"\)\)\s*&&\s*.*\|\|\s*(.*)\(',

And it will start to work flawlessly. Cheers!

5reactions
TinKurbatoffcommented, May 16, 2022

For those, who came here from a google search. Yu Jhin updated the code in the more correct way: file: .local/lib/python<your version>/site-packages/pytube/cipher.py update lines 272-273 with:

        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$]+)(\[\d+\])?\([a-z]\)',

No comma in this case! These regex expression groups work one by one…

Read more comments on GitHub >

github_iconTop Results From Across the Web

get_throttling_function_name: could not find match for multiple ...
I used to download songs the following way: from pytube import YouTube video = YouTube ...
Read more >
pytube.exceptions.RegexMatchError ... - GitHub
pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple[BUG] #1105.
Read more >
get_throttling_function_name: could not find match for multiple
[A-Z]&&\(b=a\. get \("n"\)\)&&\(b=([^(]+)\(b\)',In this video, you will leran how to fix the error : pytube. exceptions. RegexMatchError : get_t.
Read more >
www.xavierdupre.fr/app/ensae_projects/helpsphinx/_...
... multiple](https://stackoverflow.com/questions/68945080/pytube-exceptions-regexmatcherror-get-throttling-function-name-could-not-find/71903013#71903013).
Read more >
Regexmatcherror With Pytube - ADocLib
[BUG] pytube.exceptions.RegexMatchError: getthrottlingfunctionname: could not find match for multiple. I did this simple code for downloading videos:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found