def __init__( self, url: str, defer_prefetch_init: bool = False, on_progress_callback: Optional[OnProgress] = None, on_complete_callback: Optional[OnComplete] = None, proxies: Dict[str, str] = None, ): """Construct a :class:`YouTube <YouTube>`. :param str url: A valid YouTube watch URL. :param bool defer_prefetch_init: Defers executing any network requests. :param func on_progress_callback: (Optional) User defined callback function for stream download progress events. :param func on_complete_callback: (Optional) User defined callback function for stream download complete events. """ self.js: Optional[str] = None # js fetched by js_url self.js_url: Optional[str] = None # the url to the js, parsed from watch html # note: vid_info may eventually be removed. It sounds like it once had # additional formats, but that doesn't appear to still be the case. # the url to vid info, parsed from watch html self.vid_info_url: Optional[str] = None self.vid_info_raw: Optional[str] = None # content fetched by vid_info_url self.vid_info: Optional[Dict] = None # parsed content of vid_info_raw self.watch_html: Optional[str] = None # the html of /watch?v=<video_id> self.embed_html: Optional[str] = None self.player_config_args: Dict = {} # inline js in the html containing self.player_response: Dict = {} # streams self.age_restricted: Optional[bool] = None self.fmt_streams: List[Stream] = [] # video_id part of /watch?v=<video_id> self.video_id = extract.video_id(url) self.watch_url = f"https://youtube.com/watch?v={self.video_id}" self.embed_url = f"https://www.youtube.com/embed/{self.video_id}" # Shared between all instances of `Stream` (Borg pattern). self.stream_monostate = Monostate( on_progress=on_progress_callback, on_complete=on_complete_callback ) if proxies: install_proxy(proxies) if not defer_prefetch_init: self.prefetch() self.descramble()
def __init__(self, url: str, proxies: Optional[Dict[str, str]] = None): if proxies: install_proxy(proxies) try: self.playlist_id: str = parse_qs(url.split("?")[1])["list"][0] except IndexError: # assume that url is just the id self.playlist_id = url self.playlist_url = ( f"https://www.youtube.com/playlist?list={self.playlist_id}") self.html = request.get(self.playlist_url) # Needs testing with non-English self.last_update: Optional[date] = None date_match = re.search( r"<li>Last updated on (\w{3}) (\d{1,2}), (\d{4})</li>", self.html) if date_match: month, day, year = date_match.groups() self.last_update = datetime.strptime(f"{month} {day:0>2} {year}", "%b %d %Y").date() self._js_regex = re.compile(r"window\[\"ytInitialData\"] = ([^\n]+)") self._video_regex = re.compile(r"href=\"(/watch\?v=[\w-]*)")
def __init__(self, url: str, on_progress_callback: Optional[Callable[[Any, bytes, int], None]] = None, on_complete_callback: Optional[Callable[[Any, Optional[str]], None]] = None, proxies: Dict[str, str] = None, use_oauth: bool = False, allow_oauth_cache: bool = True): """Construct a :class:`YouTube <YouTube>`. :param str url: A valid YouTube watch URL. :param func on_progress_callback: (Optional) User defined callback function for stream download progress events. :param func on_complete_callback: (Optional) User defined callback function for stream download complete events. """ self._js: Optional[str] = None # js fetched by js_url self._js_url: Optional[ str] = None # the url to the js, parsed from watch html self._vid_info: Optional[ Dict] = None # content fetched from innertube/player self._watch_html: Optional[ str] = None # the html of /watch?v=<video_id> self._embed_html: Optional[str] = None self._player_config_args: Optional[ Dict] = None # inline js in the html containing self._age_restricted: Optional[bool] = None self._fmt_streams: Optional[List[Stream]] = None self._initial_data = None self._metadata: Optional[YouTubeMetadata] = None # video_id part of /watch?v=<video_id> self.video_id = extract.video_id(url) self.watch_url = f"https://youtube.com/watch?v={self.video_id}" self.embed_url = f"https://www.youtube.com/embed/{self.video_id}" # Shared between all instances of `Stream` (Borg pattern). self.stream_monostate = Monostate(on_progress=on_progress_callback, on_complete=on_complete_callback) if proxies: install_proxy(proxies) self._author = None self._title = None self._publish_date = None self.use_oauth = use_oauth self.allow_oauth_cache = allow_oauth_cache
def __init__( self, url: str, on_progress_callback: Optional[Callable[[Any, bytes, int], None]] = None, on_complete_callback: Optional[Callable[[Any, Optional[str]], None]] = None, proxies: Dict[str, str] = None, ): """Construct a :class:`YouTube <YouTube>`. :param str url: A valid YouTube watch URL. :param func on_progress_callback: (Optional) User defined callback function for stream download progress events. :param func on_complete_callback: (Optional) User defined callback function for stream download complete events. """ self._js: Optional[str] = None # js fetched by js_url self._js_url: Optional[str] = None # the url to the js, parsed from watch html # note: vid_info may eventually be removed. It sounds like it once had # additional formats, but that doesn't appear to still be the case. # the url to vid info, parsed from watch html self._vid_info_url: Optional[str] = None self._vid_info_raw: Optional[str] = None # content fetched by vid_info_url self._vid_info: Optional[Dict] = None # parsed content of vid_info_raw self._watch_html: Optional[str] = None # the html of /watch?v=<video_id> self._embed_html: Optional[str] = None self._player_config_args: Optional[Dict] = None # inline js in the html containing self._player_response: Optional[Dict] = None # streams self._age_restricted: Optional[bool] = None self._fmt_streams: Optional[List[Stream]] = None self._initial_data = None self._metadata: Optional[YouTubeMetadata] = None # video_id part of /watch?v=<video_id> self.video_id = extract.video_id(url) self.watch_url = f"https://youtube.com/watch?v={self.video_id}" self.embed_url = f"https://www.youtube.com/embed/{self.video_id}" # Shared between all instances of `Stream` (Borg pattern). self.stream_monostate = Monostate( on_progress=on_progress_callback, on_complete=on_complete_callback ) if proxies: install_proxy(proxies) self._author = None self._title = None self._publish_date = None
def __init__(self, url: str, proxies: Optional[Dict[str, str]] = None): if proxies: install_proxy(proxies) self.playlist_id = extract.playlist_id(url) self.playlist_url = ( f"https://www.youtube.com/playlist?list={self.playlist_id}") self.html = request.get(self.playlist_url)
def __init__(self, url: str, proxies: Optional[Dict[str, str]] = None): if proxies: install_proxy(proxies) self._input_url = url # These need to be initialized as None for the properties. self._html = None self._ytcfg = None self._playlist_id = None
def __init__(self, url: str, proxies: Optional[Dict[str, str]] = None): if proxies: install_proxy(proxies) # These need to be initialized as None for the properties. self._html = None self._ytcfg = None self.playlist_id = extract.playlist_id(url) self.playlist_url = ( f"https://www.youtube.com/playlist?list={self.playlist_id}")
def __init__(self, url: str, proxies: Optional[Dict[str, str]] = None, session: ClientSession = None): if proxies: install_proxy(proxies) self._session = session if session else request.createSession() self._input_url = url # These need to be initialized as None for the properties. self._html = None self._ytcfg = None self._initial_data = None self._sidebar_info = None self._playlist_id = None