Пример #1
0
    def prefetch(self) -> None:
        """Eagerly download all necessary data.

        Eagerly executes all necessary network requests so all other
        operations don't does need to make calls outside of the interpreter
        which blocks for long periods of time.

        :rtype: None
        """
        self.watch_html = request.get(url=self.watch_url)
        if self.watch_html is None:
            raise VideoUnavailable(video_id=self.video_id)
        self.age_restricted = extract.is_age_restricted(self.watch_html)

        if not self.age_restricted and "This video is private" in self.watch_html:
            raise VideoUnavailable(video_id=self.video_id)

        if self.age_restricted:
            if not self.embed_html:
                self.embed_html = request.get(url=self.embed_url)
            self.vid_info_url = extract.video_info_url_age_restricted(
                self.video_id, self.watch_url
            )
        else:
            self.vid_info_url = extract.video_info_url(
                video_id=self.video_id, watch_url=self.watch_url
            )

        self.vid_info_raw = request.get(self.vid_info_url)
        if not self.age_restricted:
            self.js_url = extract.js_url(self.watch_html)
            self.js = request.get(self.js_url)
Пример #2
0
def test_info_url(age_restricted):
    video_info_url = extract.video_info_url_age_restricted(
        video_id="QRS8MkLhQmM",
        embed_html=age_restricted["embed_html"],
    )
    assert video_info_url.startswith('https://www.youtube.com/get_video_info')
    assert 'video_id=QRS8MkLhQmM' in video_info_url
Пример #3
0
def test_info_url(age_restricted):
    video_info_url = extract.video_info_url_age_restricted(
        video_id="QRS8MkLhQmM",
        embed_html=age_restricted["embed_html"],
    )
    expected = ("https://youtube.com/get_video_info?video_id=QRS8MkLhQmM&eurl"
                "=https%3A%2F%2Fyoutube.googleapis.com%2Fv%2FQRS8MkLhQmM&sts=")
    assert video_info_url == expected
Пример #4
0
    def vid_info_url(self):
        if self._vid_info_url:
            return self._vid_info_url

        if self.age_restricted:
            self._vid_info_url = extract.video_info_url_age_restricted(
                self.video_id, self.watch_url)
        else:
            self._vid_info_url = extract.video_info_url(
                video_id=self.video_id, watch_url=self.watch_url)
        return self._vid_info_url
Пример #5
0
    async def prefetch(self) -> None:
        """Eagerly download all necessary data.

        Eagerly executes all necessary network requests so all other
        operations don't does need to make calls outside of the interpreter
        which blocks for long periods of time.

        :rtype: None
        """
        self.watch_html = await request.get(url=self.watch_url)
        if self.watch_html is None:
            raise VideoUnavailable(video_id=self.video_id)
        self.age_restricted = extract.is_age_restricted(self.watch_html)

        if not self.age_restricted and (
                "This video is private" in self.watch_html or
                "This video is no longer available because the YouTube account "
                "associated with this video has been terminated."
                in self.watch_html
                or "This video is only available to Music Premium members"
                in self.watch_html or
                "This video is no longer available due to a copyright claim by"
                in self.watch_html):
            raise VideoUnavailable(video_id=self.video_id)

        if self.age_restricted:
            if not self.embed_html:
                self.embed_html = await request.get(url=self.embed_url)
            self.vid_info_url = extract.video_info_url_age_restricted(
                self.video_id, self.watch_url)
        else:
            self.vid_info_url = extract.video_info_url(
                video_id=self.video_id, watch_url=self.watch_url)

        self.vid_info_raw = await request.get(self.vid_info_url)
        if not self.age_restricted:
            self.js_url = extract.js_url(self.watch_html)
            self.js = await request.get(self.js_url)
    def prefetch(self) -> None:
        """Eagerly download all necessary data.

        Eagerly executes all necessary network requests so all other
        operations don't does need to make calls outside of the interpreter
        which blocks for long periods of time.

        :rtype: None
        """
        self.watch_html = request.get(url=self.watch_url)
        self.check_availability()
        self.age_restricted = extract.is_age_restricted(self.watch_html)

        if self.age_restricted:
            if not self.embed_html:
                self.embed_html = request.get(url=self.embed_url)
            self.vid_info_url = extract.video_info_url_age_restricted(
                self.video_id, self.watch_url)
            self.js_url = extract.js_url(self.embed_html)
        else:
            self.vid_info_url = extract.video_info_url(
                video_id=self.video_id, watch_url=self.watch_url)
            self.js_url = extract.js_url(self.watch_html)

        self.initial_data = extract.initial_data(self.watch_html)

        self.vid_info_raw = request.get(self.vid_info_url)

        # If the js_url doesn't match the cached url, fetch the new js and update
        #  the cache; otherwise, load the cache.
        if pytube.__js_url__ != self.js_url:
            self.js = request.get(self.js_url)
            pytube.__js__ = self.js
            pytube.__js_url__ = self.js_url
        else:
            self.js = pytube.__js__