Exemple #1
0
    def prefetch(self):
        """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 'id="player-unavailable"' in self.watch_html:
            raise VideoUnavailable('This video is not available.')
        self.embed_html = request.get(url=self.embed_url)
        self.age_restricted = extract.is_age_restricted(self.watch_html)
        self.vid_info_url = extract.video_info_url(
            video_id=self.video_id,
            watch_url=self.watch_url,
            watch_html=self.watch_html,
            embed_html=self.embed_html,
            age_restricted=self.age_restricted,
        )
        self.vid_info = request.get(self.vid_info_url)
        if not self.age_restricted:
            self.js_url = extract.js_url(self.watch_html, self.age_restricted)
            self.js = request.get(self.js_url)
Exemple #2
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)
Exemple #3
0
def test_info_url_age_restricted(cipher_signature):
    video_info_url = extract.video_info_url(
        video_id=cipher_signature.video_id,
        watch_url=cipher_signature.watch_url,
    )
    assert video_info_url.startswith('https://www.youtube.com/get_video_info')
    assert 'video_id=2lAe1cqCOXo' in video_info_url
Exemple #4
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
                or '<img class="icon meh" src="/yts/img'  # noqa: W503
                not in self.watch_html  # noqa: W503
            ):
            raise VideoUnavailable(video_id=self.video_id)

        self.embed_html = request.get(url=self.embed_url)
        self.age_restricted = extract.is_age_restricted(self.watch_html)
        self.vid_info_url = extract.video_info_url(
            video_id=self.video_id,
            watch_url=self.watch_url,
            embed_html=self.embed_html,
            age_restricted=self.age_restricted,
        )
        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.age_restricted)
            self.js = request.get(self.js_url)
Exemple #5
0
	def prefetch(self):
		"""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)
		#with open("/tmp/watch_html",'w') as f:					# Debug
		#	f.write(self.watch_html)	
		
		# 30.07.2020 siehe  github.com/nficano/pytube/issues/499 +
		#	github.com/nficano/pytube/issues/337:
		#if '<img class="icon meh" src="/yts/img' not in self.watch_html:
		#	raise VideoUnavailable('This video is unavailable.')
		self.embed_html = request.get(url=self.embed_url)
		self.age_restricted = extract.is_age_restricted(self.watch_html)
		self.vid_info_url = extract.video_info_url(
			video_id=self.video_id,
			watch_url=self.watch_url,
			watch_html=self.watch_html,
			embed_html=self.embed_html,
			age_restricted=self.age_restricted,
		)
		self.vid_info = request.get(self.vid_info_url)
		if not self.age_restricted:
			self.js_url = extract.js_url(self.watch_html, self.age_restricted)
			self.js = request.get(self.js_url)
Exemple #6
0
def test_info_url_age_restricted(cipher_signature):
    video_info_url = extract.video_info_url(
        video_id=cipher_signature.video_id,
        watch_url=cipher_signature.watch_url,
    )
    expected = ("https://youtube.com/get_video_info?video_id=2lAe1cqCOXo"
                "&ps=default&eurl=https%253A%2F%2Fyoutube.com%2Fwatch%253Fv%"
                "253D2lAe1cqCOXo&hl=en_US")
    assert video_info_url == expected
Exemple #7
0
def test_info_url_age_restricted(cipher_signature):
    video_info_url = extract.video_info_url(
        video_id=cipher_signature.video_id,
        watch_url=cipher_signature.watch_url)
    expected = (
        "https://youtube.com/get_video_info?video_id=9bZkp7q19f0&el=%24el"
        "&ps=default&eurl=https%253A%2F%2Fyoutube.com%2Fwatch%253Fv%"
        "253D9bZkp7q19f0&hl=en_US")
    assert video_info_url == expected
Exemple #8
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
Exemple #9
0
def test_info_url(cipher_signature):
    video_info_url = extract.video_info_url(
        video_id=cipher_signature.video_id,
        watch_url=cipher_signature.watch_url,
        watch_html=cipher_signature.watch_html,
    )
    expected = (
        'https://youtube.com/get_video_info?video_id=9bZkp7q19f0&el=%24el'
        '&ps=default&eurl=https%253A%2F%2Fyoutube.com%2Fwatch%253Fv%'
        '253D9bZkp7q19f0&hl=en_US&t=%252C%2522t%2522%253A%25221%2522')
    assert video_info_url == expected
Exemple #10
0
def test_info_url(cipher_signature):
    video_info_url = extract.video_info_url(
        video_id=cipher_signature.video_id,
        watch_url=cipher_signature.watch_url,
        watch_html=cipher_signature.watch_html,
        embed_html='',
        age_restricted=False,
    )
    expected = (
        'https://youtube.com/get_video_info?video_id=9bZkp7q19f0&el=%24el'
        '&ps=default&eurl=https%253A%2F%2Fyoutube.com%2Fwatch%253Fv%'
        '253D9bZkp7q19f0&hl=en_US&t=%252C%2522t%2522%253A%25221%2522'
    )
    assert video_info_url == expected
Exemple #11
0
    def prefetch(self, multithread = True):
        """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

        """
        if multithread:
            threads, results = [None] * 2, [None] * 2
            for i, url in enumerate([self.watch_url, self.embed_url]):
                threads[i] = Thread(target=self.do_get, args=(url, results, i))
                threads[i].start()
            for i in range(len(threads)):
                threads[i].join()
            self.watch_html, self.embed_html = results
        else:
            self.watch_html = request.get(url=self.watch_url)
            self.embed_html = request.get(url=self.embed_url)
        if '<img class="icon meh" src="/yts/img' not in self.watch_html:
            raise VideoUnavailable('This video is unavailable.')
        self.age_restricted = extract.is_age_restricted(self.watch_html)
        self.vid_info_url = extract.video_info_url(
            video_id=self.video_id,
            watch_url=self.watch_url,
            watch_html=self.watch_html,
            embed_html=self.embed_html,
            age_restricted=self.age_restricted,
        )
        if multithread:
            threads, results = [None] * 2, [None] * 2
            threads[0] = Thread(target=self.do_get, args=(self.vid_info_url, results, 0))
            threads[0].start()
        else:
            self.vid_info = request.get(self.vid_info_url)
        if not self.age_restricted:
            self.js_url = extract.js_url(self.watch_html, self.age_restricted)
            if multithread:
                threads[1] = Thread(target=self.do_get, args=(self.js_url, results, 1))
                threads[1].start()
                threads[0].join()
                threads[1].join()
            else:
                self.js = request.get(self.js_url)
        else:
            threads[0].join()
        if multithread:
            self.vid_info, self.js = results
Exemple #12
0
    def prefetch(self):
        """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 extract.is_age_restricted(self.watch_html):
            raise AgeRestrictionError('Content is age restricted')
        self.vid_info_url = extract.video_info_url(
            video_id=self.video_id,
            watch_url=self.watch_url,
            watch_html=self.watch_html,
        )
        self.js_url = extract.js_url(self.watch_html)
        self.js = request.get(self.js_url)
        self.vid_info = request.get(self.vid_info_url)
Exemple #13
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)
Exemple #14
0
    def prefetch(self):
        """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.embed_html = request.get(url=self.embed_url)
        self.age_restricted = extract.is_age_restricted(self.watch_html)
        self.vid_info_url = extract.video_info_url(
            video_id=self.video_id,
            watch_url=self.watch_url,
            watch_html=self.watch_html,
            embed_html=self.embed_html,
            age_restricted=self.age_restricted,
        )
        self.vid_info = 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)
    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__
Exemple #16
0
def get_video_info(video_id: str) -> Dict[str, Any]:
    url = video_info_url(video_id,
                         f"https://www.youtube.com/watch?v={video_id}")
    resp: requests.Response = requests.get(url)
    return urllib.parse.parse_qs(resp.text)