예제 #1
0
    def init_option(self):
        self.driver_option = webdriver.ChromeOptions()
        prefs = {
            "profile.default_content_setting_values.plugins":
            1,
            "profile.content_settings.plugin_whitelist.adobe-flash-player":
            1,
            "profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player":
            1,
            "credentials_enable_service":
            False,
            "profile.password_manager_enabled":
            False
        }
        self.driver_option.add_argument("--headless")
        self.driver_option.add_argument("--no-sandbox")
        self.driver_option.add_argument("--disable-dev-shm-usage")
        self.driver_option.add_argument("--proxy-server=%s" %
                                        self.search_proxy)
        self.driver_option.add_argument(
            "user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
        )
        self.driver_option.add_argument("lang=ko_KR")
        self.driver_option.add_experimental_option("prefs", prefs)

        if self.search_proxy != '':
            install_proxy({
                "http": self.search_proxy,
                "https": self.search_proxy
            })
        else:
            install_proxy({})
예제 #2
0
    def __init__(
        self,
        url=None,
        defer_prefetch_init=False,
        on_progress_callback=None,
        on_complete_callback=None,
        proxies=None,
    ):
        """Construct a :class:`YouTube <YouTube>`.

        :param str url:
            A valid YouTube watch URL.
        :param bool defer_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 = None  # js fetched by js_url
        self.js_url = 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.

        self.vid_info = None  # content fetched by vid_info_url
        self.vid_info_url = None  # the url to vid info, parsed from watch html

        self.watch_html = None  # the html of /watch?v=<video_id>
        self.embed_html = None
        self.player_config_args = None  # inline js in the html containing
        # streams
        self.age_restricted = None

        self.fmt_streams = []  # list of :class:`Stream <Stream>` instances
        self.caption_tracks = []

        # video_id part of /watch?v=<video_id>
        self.video_id = extract.video_id(url)

        # https://www.youtube.com/watch?v=<video_id>
        self.watch_url = extract.watch_url(self.video_id)

        self.embed_url = extract.embed_url(self.video_id)
        # A dictionary shared between all instances of :class:`Stream <Stream>`
        # (Borg pattern).
        self.stream_monostate = {
            # user defined callback functions.
            'on_progress': on_progress_callback,
            'on_complete': on_complete_callback,
        }

        if proxies:
            install_proxy(proxies)

        if not defer_prefetch_init:
            self.prefetch_init()
예제 #3
0
 def __init__(self, url, suppress_exception=False, proxies=None):
     self.playlist_url = url
     self.video_urls = []
     self.suppress_exception = suppress_exception,
     if proxies:
         install_proxy(proxies)