How to use the pytube.request function in pytube

To help you get started, we’ve selected a few pytube examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nficano / pytube / tests / test_request.py View on Github external
def test_get(mock_urlopen):
    response = mock.Mock()
    response.read.return_value = ''.encode('utf-8')
    mock_urlopen.return_value = response
    response = request.get('fakeassurl.gov')
    assert response == ''
github nficano / pytube / tests / test_streams.py View on Github external
def test_filesize(cipher_signature, mocker):
    mocker.patch.object(request, 'get')
    request.get.return_value = {'content-length': '6796391'}
    assert cipher_signature.streams.first().filesize == 6796391
github nficano / pytube / tests / test_streams.py View on Github external
def test_filesize(cipher_signature, mocker):
    mocker.patch.object(request, 'get')
    request.get.return_value = {'content-length': '6796391'}
    assert cipher_signature.streams.first().filesize == 6796391
github ksharindam / quartz-browser-qt5 / quartz_browser / pytube / contrib / playlist.py View on Github external
def parse_links(self):
        """Parse the video links from the page source, extracts and
        returns the /watch?v= part from video link href
        It's an alternative for BeautifulSoup
        """

        url = self.construct_playlist_url()
        req = request.get(url)

        # split the page source by line and process each line
        content = [x for x in req.split('\n') if 'pl-video-title-link' in x]
        link_list = [x.split('href="', 1)[1].split('&', 1)[0] for x in content]

        # The above only returns 100 or fewer links
        # Simulating a browser request for the load more link
        load_more_url = self._load_more_url(req)
        while len(load_more_url):   # there is an url found
            logger.debug('load more url: %s' % load_more_url)
            req = request.get(load_more_url)
            load_more = json.loads(req)
            videos = re.findall(
                r'href=\"(/watch\?v=[\w-]*)',
                load_more['content_html'],
            )
github nficano / pytube / pytube / contrib / playlist.py View on Github external
def parse_links(self):
        """Parse the video links from the page source, extracts and
        returns the /watch?v= part from video link href
        It's an alternative for BeautifulSoup
        """

        url = self.construct_playlist_url()
        req = request.get(url)

        # split the page source by line and process each line
        content = [x for x in req.split('\n') if 'pl-video-title-link' in x]
        link_list = [x.split('href="', 1)[1].split('&', 1)[0] for x in content]

        # The above only returns 100 or fewer links
        # Simulating a browser request for the load more link
        load_more_url = self._load_more_url(req)
        while len(load_more_url):   # there is an url found
            logger.debug('load more url: %s' % load_more_url)
            req = request.get(load_more_url)
            load_more = json.loads(req)
            videos = re.findall(
                r'href=\"(/watch\?v=[\w-]*)',
                load_more['content_html'],
            )
github ksharindam / quartz-browser-qt5 / quartz_browser / pytube / contrib / playlist.py View on Github external
It's an alternative for BeautifulSoup
        """

        url = self.construct_playlist_url()
        req = request.get(url)

        # split the page source by line and process each line
        content = [x for x in req.split('\n') if 'pl-video-title-link' in x]
        link_list = [x.split('href="', 1)[1].split('&', 1)[0] for x in content]

        # The above only returns 100 or fewer links
        # Simulating a browser request for the load more link
        load_more_url = self._load_more_url(req)
        while len(load_more_url):   # there is an url found
            logger.debug('load more url: %s' % load_more_url)
            req = request.get(load_more_url)
            load_more = json.loads(req)
            videos = re.findall(
                r'href=\"(/watch\?v=[\w-]*)',
                load_more['content_html'],
            )
            # remove duplicates
            link_list.extend(list(OrderedDict.fromkeys(videos)))
            load_more_url = self._load_more_url(
                load_more['load_more_widget_html'],
            )

        return link_list
github rols1 / Kodi-Addon-ARDundZDF / resources / lib / pytube / streams.py View on Github external
def stream_to_buffer(self):
		"""Write the media stream to buffer

		:rtype: io.BytesIO buffer
		"""
		buffer = io.BytesIO()
		bytes_remaining = self.filesize
		PLog(
			'streams: downloading (%s total bytes) file to BytesIO buffer',
			self.filesize,
		)

		for chunk in request.get(self.url, streaming=True):
			# reduce the (bytes) remainder by the length of the chunk.
			bytes_remaining -= len(chunk)
			# send to the on_progress callback.
			self.on_progress(chunk, buffer, bytes_remaining)
		self.on_complete(buffer)
		return buffer
github rols1 / Kodi-Addon-ARDundZDF / resources / lib / pytube / __main__.py View on Github external
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 '
github rols1 / Kodi-Addon-ARDundZDF / resources / lib / pytube / captions.py View on Github external
def xml_captions(self):
		"""Download the xml caption tracks."""
		return request.get(self.url)
github nficano / pytube / pytube / streams.py View on Github external
filename = '{prefix}{filename}'\
                .format(
                    prefix=safe_filename(filename_prefix),
                    filename=filename,
                )

        # file path
        fp = os.path.join(output_path, filename)
        bytes_remaining = self.filesize
        logger.debug(
            'downloading (%s total bytes) file to %s',
            self.filesize, fp,
        )

        with open(fp, 'wb') as fh:
            for chunk in request.get(self.url, streaming=True):
                # reduce the (bytes) remainder by the length of the chunk.
                bytes_remaining -= len(chunk)
                # send to the on_progress callback.
                self.on_progress(chunk, fh, bytes_remaining)
        self.on_complete(fh)
        return fp