# Path: pytube/exceptions.py
# class RegexMatchError(ExtractError):
#     """Regex pattern did not return any matches."""
# 
#     def __init__(self, caller: str, pattern: Union[str, Pattern]):
#         """
#         :param str caller:
#             Calling function
#         :param str pattern:
#             Pattern that failed to match
#         """
#         super().__init__(f"{caller}: could not find match for {pattern}")
#         self.caller = caller
#         self.pattern = pattern
# 
# class MaxRetriesExceeded(PytubeError):
#     """Maximum number of retries exceeded."""
# 
# Path: pytube/helpers.py
# def regex_search(pattern: str, string: str, group: int) -> str:
#     """Shortcut method to search a string for a given pattern.
# 
#     :param str pattern:
#         A regular expression pattern.
#     :param str string:
#         A target string to search.
#     :param int group:
#         Index of group to return.
#     :rtype:
#         str or tuple
#     :returns:
#         Substring pattern matches.
#     """
#     regex = re.compile(pattern)
#     results = regex.search(string)
#     if not results:
#         raise RegexMatchError(caller="regex_search", pattern=pattern)
# 
#     logger.debug("matched regex search: %s", pattern)
# 
#     return results.group(group)


import http.client
import json
import logging
import re
import socket
from functools import lru_cache
from urllib import parse
from urllib.error import URLError
from urllib.request import Request, urlopen
from pytube.exceptions import RegexMatchError, MaxRetriesExceeded
from pytube.helpers import regex_search
    while seq_num <= segment_count:
        # Create sequential request URL
        querys['sq'] = seq_num
        url = base_url + parse.urlencode(querys)

        yield from stream(url, timeout=timeout, max_retries=max_retries)
        seq_num += 1
    return  # pylint: disable=R1711


def stream(
    url,
    timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
    max_retries=0
):
    """Read the response in chunks.
    :param str url: The URL to perform the GET request for.
    :rtype: Iterable[bytes]
    """
    file_size: int = default_range_size  # fake filesize to start
    downloaded = 0
    while downloaded < file_size:
        stop_pos = min(downloaded + default_range_size, file_size) - 1
        range_header = f"bytes={downloaded}-{stop_pos}"
        tries = 0

        # Attempt to make the request multiple times as necessary.
        while True:
            # If the max retries is exceeded, raise an exception
            if tries >= 1 + max_retries:

# Path: pytube/exceptions.py
# class RegexMatchError(ExtractError):
#     """Regex pattern did not return any matches."""
# 
#     def __init__(self, caller: str, pattern: Union[str, Pattern]):
#         """
#         :param str caller:
#             Calling function
#         :param str pattern:
#             Pattern that failed to match
#         """
#         super().__init__(f"{caller}: could not find match for {pattern}")
#         self.caller = caller
#         self.pattern = pattern
# 
# class MaxRetriesExceeded(PytubeError):
#     """Maximum number of retries exceeded."""
# 
# Path: pytube/helpers.py
# def regex_search(pattern: str, string: str, group: int) -> str:
#     """Shortcut method to search a string for a given pattern.
# 
#     :param str pattern:
#         A regular expression pattern.
#     :param str string:
#         A target string to search.
#     :param int group:
#         Index of group to return.
#     :rtype:
#         str or tuple
#     :returns:
#         Substring pattern matches.
#     """
#     regex = re.compile(pattern)
#     results = regex.search(string)
#     if not results:
#         raise RegexMatchError(caller="regex_search", pattern=pattern)
# 
#     logger.debug("matched regex search: %s", pattern)
# 
#     return results.group(group)


# Path: pytube/request.py
import http.client
import json
import logging
import re
import socket
from functools import lru_cache
from urllib import parse
from urllib.error import URLError
from urllib.request import Request, urlopen
from pytube.exceptions import RegexMatchError, MaxRetriesExceeded
from pytube.helpers import regex_search

    while seq_num <= segment_count:
        # Create sequential request URL
        querys['sq'] = seq_num
        url = base_url + parse.urlencode(querys)

        yield from stream(url, timeout=timeout, max_retries=max_retries)
        seq_num += 1
    return  # pylint: disable=R1711


def stream(
    url,
    timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
    max_retries=0
):
    """Read the response in chunks.
    :param str url: The URL to perform the GET request for.
    :rtype: Iterable[bytes]
    """
    file_size: int = default_range_size  # fake filesize to start
    downloaded = 0
    while downloaded < file_size:
        stop_pos = min(downloaded + default_range_size, file_size) - 1
        range_header = f"bytes={downloaded}-{stop_pos}"
        tries = 0

        # Attempt to make the request multiple times as necessary.
        while True:
            # If the max retries is exceeded, raise an exception
            if tries >= 1 + max_retries:

                raise MaxRetriesExceeded()