# Path: pytube/request.py
# def _execute_request(
#     url,
#     method=None,
#     headers=None,
#     data=None,
#     timeout=socket._GLOBAL_DEFAULT_TIMEOUT
# ):
# def get(url, extra_headers=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
# def post(url, extra_headers=None, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
# def seq_stream(
#     url,
#     timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
#     max_retries=0
# ):
# def stream(
#     url,
#     timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
#     max_retries=0
# ):
# def filesize(url):
# def seq_filesize(url):
# def head(url):
# 
# Path: pytube/helpers.py
# def safe_filename(s: str, max_length: int = 255) -> str:
#     """Sanitize a string making it safe to use as a filename.
# 
#     This function was based off the limitations outlined here:
#     https://en.wikipedia.org/wiki/Filename.
# 
#     :param str s:
#         A string to make safe for use as a file name.
#     :param int max_length:
#         The maximum filename character length.
#     :rtype: str
#     :returns:
#         A sanitized string.
#     """
#     # Characters in range 0-31 (0x00-0x1F) are not allowed in ntfs filenames.
#     ntfs_characters = [chr(i) for i in range(0, 31)]
#     characters = [
#         r'"',
#         r"\#",
#         r"\$",
#         r"\%",
#         r"'",
#         r"\*",
#         r"\,",
#         r"\.",
#         r"\/",
#         r"\:",
#         r'"',
#         r"\;",
#         r"\<",
#         r"\>",
#         r"\?",
#         r"\\",
#         r"\^",
#         r"\|",
#         r"\~",
#         r"\\\\",
#     ]
#     pattern = "|".join(ntfs_characters + characters)
#     regex = re.compile(pattern, re.UNICODE)
#     filename = regex.sub("", s)
#     return filename[:max_length].rsplit(" ", 0)[0]
# 
# def target_directory(output_path: Optional[str] = None) -> str:
#     """
#     Function for determining target directory of a download.
#     Returns an absolute path (if relative one given) or the current
#     path (if none given). Makes directory if it does not exist.
# 
#     :type output_path: str
#         :rtype: str
#     :returns:
#         An absolute directory path as a string.
#     """
#     if output_path:
#         if not os.path.isabs(output_path):
#             output_path = os.path.join(os.getcwd(), output_path)
#     else:
#         output_path = os.getcwd()
#     os.makedirs(output_path, exist_ok=True)
#     return output_path


import math
import os
import time
import xml.etree.ElementTree as ElementTree
from html import unescape
from typing import Dict, Optional
from pytube import request
from pytube.helpers import safe_filename, target_directory
    ) -> str:
        """Write the media stream to disk.

        :param title:
            Output filename (stem only) for writing media file.
            If one is not specified, the default filename is used.
        :type title: str
        :param srt:
            Set to True to download srt, false to download xml. Defaults to True.
        :type srt bool
        :param output_path:
            (optional) Output path for writing media file. If one is not
            specified, defaults to the current working directory.
        :type output_path: str or None
        :param filename_prefix:
            (optional) A string that will be prepended to the filename.
            For example a number in a playlist or the name of a series.
            If one is not specified, nothing will be prepended
            This is separate from filename so you can use the default
            filename but still add a prefix.
        :type filename_prefix: str or None

        :rtype: str
        """
        if title.endswith(".srt") or title.endswith(".xml"):
            filename = ".".join(title.split(".")[:-1])
        else:
            filename = title

        if filename_prefix:

# Path: pytube/request.py
# def _execute_request(
#     url,
#     method=None,
#     headers=None,
#     data=None,
#     timeout=socket._GLOBAL_DEFAULT_TIMEOUT
# ):
# def get(url, extra_headers=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
# def post(url, extra_headers=None, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
# def seq_stream(
#     url,
#     timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
#     max_retries=0
# ):
# def stream(
#     url,
#     timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
#     max_retries=0
# ):
# def filesize(url):
# def seq_filesize(url):
# def head(url):
# 
# Path: pytube/helpers.py
# def safe_filename(s: str, max_length: int = 255) -> str:
#     """Sanitize a string making it safe to use as a filename.
# 
#     This function was based off the limitations outlined here:
#     https://en.wikipedia.org/wiki/Filename.
# 
#     :param str s:
#         A string to make safe for use as a file name.
#     :param int max_length:
#         The maximum filename character length.
#     :rtype: str
#     :returns:
#         A sanitized string.
#     """
#     # Characters in range 0-31 (0x00-0x1F) are not allowed in ntfs filenames.
#     ntfs_characters = [chr(i) for i in range(0, 31)]
#     characters = [
#         r'"',
#         r"\#",
#         r"\$",
#         r"\%",
#         r"'",
#         r"\*",
#         r"\,",
#         r"\.",
#         r"\/",
#         r"\:",
#         r'"',
#         r"\;",
#         r"\<",
#         r"\>",
#         r"\?",
#         r"\\",
#         r"\^",
#         r"\|",
#         r"\~",
#         r"\\\\",
#     ]
#     pattern = "|".join(ntfs_characters + characters)
#     regex = re.compile(pattern, re.UNICODE)
#     filename = regex.sub("", s)
#     return filename[:max_length].rsplit(" ", 0)[0]
# 
# def target_directory(output_path: Optional[str] = None) -> str:
#     """
#     Function for determining target directory of a download.
#     Returns an absolute path (if relative one given) or the current
#     path (if none given). Makes directory if it does not exist.
# 
#     :type output_path: str
#         :rtype: str
#     :returns:
#         An absolute directory path as a string.
#     """
#     if output_path:
#         if not os.path.isabs(output_path):
#             output_path = os.path.join(os.getcwd(), output_path)
#     else:
#         output_path = os.getcwd()
#     os.makedirs(output_path, exist_ok=True)
#     return output_path


# Path: pytube/captions.py
import math
import os
import time
import xml.etree.ElementTree as ElementTree
from html import unescape
from typing import Dict, Optional
from pytube import request
from pytube.helpers import safe_filename, target_directory

    ) -> str:
        """Write the media stream to disk.

        :param title:
            Output filename (stem only) for writing media file.
            If one is not specified, the default filename is used.
        :type title: str
        :param srt:
            Set to True to download srt, false to download xml. Defaults to True.
        :type srt bool
        :param output_path:
            (optional) Output path for writing media file. If one is not
            specified, defaults to the current working directory.
        :type output_path: str or None
        :param filename_prefix:
            (optional) A string that will be prepended to the filename.
            For example a number in a playlist or the name of a series.
            If one is not specified, nothing will be prepended
            This is separate from filename so you can use the default
            filename but still add a prefix.
        :type filename_prefix: str or None

        :rtype: str
        """
        if title.endswith(".srt") or title.endswith(".xml"):
            filename = ".".join(title.split(".")[:-1])
        else:
            filename = title

        if filename_prefix:

            filename = f"{safe_filename(filename_prefix)}{filename}"