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, 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, on_progress_callback: Optional[OnProgress] = None, on_complete_callback: Optional[OnComplete] = None, ): """Dont construct the YouTube class directly. Use create()""" 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)