Search code examples
pythonyoutubepytubecustomtkinter

pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match


def video_downloader(video_url_list: List[str], download_folder: str) -> None:
    """
    Download videos from a list of YouTube video URLs.
    
    Args:
        video_urls (List[str]): The list of YouTube video URLs to download.
        download_folder (str): The folder to save the downloaded videos.
    """
    successful_downloads = 0
    valid_urls: List[str] = []

    for url in video_url_list:
        if not url:
            continue

        try:
            with tempfile.TemporaryDirectory() as temp_dir:
                cleaned_url = clean_youtube_url(url=url)
                if _get_streams(url=cleaned_url, temp_dir=temp_dir):
                    create_folder(download_folder)
                    _merge_streams(
                        temp_dir=temp_dir, url=url, download_folder=download_folder
                    )
                    logger.info(f"The video from {url} was downloaded successfully")
                    successful_downloads += 1
                    valid_urls.append(url)
                else:
                    logger.warning(f"No valid video found at the URL: {url}")

        except Exception as e:
            logger.error(
                f"Error has occurred while downloading the video from {url}: {e}"
            )
            print(e)
    if successful_downloads != 0 and (successful_downloads == len(valid_urls)):
        messagebox.showinfo(
            title="Finished download",
            message=f"Your download is complete!.\n\n\t{successful_downloads}/{len(video_url_list[1:])}",
        )

This is the main function I was using to download YouTube videos using Pytube. It was working fine last night, but this morning it's not. I'm getting the error "pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple", which prevents me from downloading any video or audio. Any possible solutions?


Solution

  • The work around in the official github page issue: https://github.com/pytube/pytube/issues/1684

    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]\)',]