Beispiel #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)
Beispiel #2
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)
Beispiel #3
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)
Beispiel #4
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)
Beispiel #5
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
Beispiel #6
0
 def _getJS(self) -> None:
     try:
         response = urlopen('https://youtube.com/watch', timeout = None)
         watch_html = response.read().decode('utf_8')
         age_restricted = extract.is_age_restricted(watch_html)
         self._js_url = extract.js_url(watch_html)
         if pytube.__js_url__ != self._js_url:
             response = urlopen(self._js_url, timeout = None)
             self._js = response.read().decode('utf_8')
             pytube.__js__ = self._js
             pytube.__js_url__ = self._js_url
         else:
             self._js = pytube.__js__
     except:
         raise Exception('ERROR: Could not make request.')
Beispiel #7
0
 def getJS(self) -> None:
     response = urlopen("https://youtube.com/watch", timeout=None)
     watch_html = response.read().decode('utf_8')
     age_restricted = extract.is_age_restricted(watch_html)
     if age_restricted:
         response = urlopen("https://www.youtube.com/embed", timeout=None)
         embed_html = response.read().decode('utf_8')
         self.js_url = extract.js_url(embed_html)
     else:
         self.js_url = extract.js_url(watch_html)
     if pytube.__js_url__ != self.js_url:
         response = urlopen(self.js_url, timeout=None)
         self.js = response.read().decode('utf_8')
         pytube.__js__ = self.js
         pytube.__js_url__ = self.js_url
     else:
         self.js = pytube.__js__
Beispiel #8
0
 async def getJavaScript(self) -> None:
     '''Gets player JavaScript from YouTube, avoid calling more than once.
     '''
     global js_url
     async with httpx.AsyncClient() as client:
         response = await client.get('https://youtube.com/watch',
                                     timeout=None)
     watch_html = response.text
     age_restricted = extract.is_age_restricted(watch_html)
     if age_restricted:
         async with httpx.AsyncClient() as client:
             response = await client.get('https://www.youtube.com/embed',
                                         timeout=None)
         embed_html = response.text
         self.js_url = extract.js_url(embed_html)
     else:
         self.js_url = extract.js_url(watch_html)
     if js_url != self.js_url:
         async with httpx.AsyncClient() as client:
             response = await client.get(self.js_url, timeout=None)
         self.js = response.text
Beispiel #9
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)
Beispiel #10
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__
Beispiel #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)
        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)
Beispiel #13
0
def test_non_age_restricted(cipher_signature):
    assert not extract.is_age_restricted(cipher_signature.watch_html)
Beispiel #14
0
def test_non_age_restricted(cipher_signature):
    assert not extract.is_age_restricted(cipher_signature.watch_html)
Beispiel #15
0
def test_age_restricted(age_restricted):
    assert extract.is_age_restricted(age_restricted["watch_html"])
Beispiel #16
0
def test_age_restricted(age_restricted):
    assert extract.is_age_restricted(age_restricted['watch_html'])
Beispiel #17
0
 def age_restricted(self):
     if self._age_restricted:
         return self._age_restricted
     self._age_restricted = extract.is_age_restricted(self.watch_html)
     return self._age_restricted