How to use the pytube.helpers.regex_search 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 YouTubeDownload / YouTubeDownload / qt_assets / tabs / downloader.py View on Github external
print('get video id')
            print(extract.video_id(self.__download_manager.url.text()))
            self.sig_step.emit(self.id, f'Loading video')
            loaded_url = YouTube(self.__download_manager.url.text(), proxies=proxies)
            self.sig_step.emit(self.id, f'Loaded video: {loaded_url.title}')
            self.sig_msg.emit(f'Found {loaded_url.title}')
            if self.__abort:
                self.sig_progress_status.emit(f'Aborted!')
                self.sig_done.emit(self.id)
                return
            self.__download_manager.videos.append(loaded_url)

        except RegexMatchError:
            print('playlist')
            if 'playlist' in self.__download_manager.url.text():
                regex_search(r'(?:list=|\/)([0-9A-Za-z_-]{11}).*', self.__download_manager.url.text(), group=1)
                loaded_url = Playlist(self.__download_manager.url.text())
                self.sig_msg.emit(f'Loaded playlist. Discovering videos...')
                loaded_url.populate_video_urls()
                i = 0
                self.sig_progress_status.emit(0)

                for video_url in loaded_url.video_urls:
                    self.sig_step.emit(self.id, f'Loading video {i}')
                    if self.__abort:
                        self.sig_progress_status.emit(f'Aborted!')
                        self.sig_done.emit(self.id)
                        return
                    self.sig_progress_total.emit(int((i / (len(loaded_url.video_urls) * 2)) * 100))
                    vid = YouTube(video_url, proxies=proxies)
                    self.sig_step.emit(self.id, f'Loaded video: {vid.title}')
                    if self.__abort:
github nficano / pytube / pytube / cipher.py View on Github external
:param str var:
        The obfuscated variable name that stores an object with all functions
        that descrambles the signature.

    **Example**:

    >>> get_transform_object(js, 'DE')
    ['AJ:function(a){a.reverse()}',
    'VR:function(a,b){a.splice(0,b)}',
    'kT:function(a,b){var c=a[0];a[0]=a[b%a.length];a[b]=c}']

    """
    pattern = r'var %s={(.*?)};' % re.escape(var)
    logger.debug('getting transform object')
    return (
        regex_search(pattern, js, group=1, flags=re.DOTALL)
        .replace('\n', ' ')
        .split(', ')
    )
github rols1 / Kodi-Addon-ARDundZDF / resources / lib / pytube / cipher.py View on Github external
:param str var:
		The obfuscated variable name that stores an object with all functions
		that descrambles the signature.

	**Example**:

	>>> get_transform_object(js, 'DE')
	['AJ:function(a){a.reverse()}',
	'VR:function(a,b){a.splice(0,b)}',
	'kT:function(a,b){var c=a[0];a[0]=a[b%a.length];a[b]=c}']

	"""
	pattern = r'var %s={(.*?)};' % re.escape(var)
	PLog('cipher: getting transform object')
	return (
		regex_search(pattern, js, group=1, flags=re.DOTALL)
		.replace('\n', ' ')
		.split(', ')
	)
github nficano / pytube / pytube / extract.py View on Github external
def video_id(url):
    """Extract the ``video_id`` from a YouTube url.

    This function supports the following patterns:

    - :samp:`https://youtube.com/watch?v={video_id}`
    - :samp:`https://youtube.com/embed/{video_id}`
    - :samp:`https://youtu.be/{video_id}`

    :param str url:
        A YouTube url containing a video id.
    :rtype: str
    :returns:
        YouTube video id.
    """
    return regex_search(r'(?:v=|\/)([0-9A-Za-z_-]{11}).*', url, group=1)
github rols1 / Kodi-Addon-ARDundZDF / resources / lib / pytube / extract.py View on Github external
def video_id(url):
	"""Extract the ``video_id`` from a YouTube url.

	This function supports the following patterns:

	- :samp:`https://youtube.com/watch?v={video_id}`
	- :samp:`https://youtube.com/embed/{video_id}`
	- :samp:`https://youtu.be/{video_id}`

	:param str url:
		A YouTube url containing a video id.
	:rtype: str
	:returns:
		YouTube video id.
	"""
	return regex_search(r'(?:v=|\/)([0-9A-Za-z_-]{11}).*', url, group=1)
github nficano / pytube / pytube / extract.py View on Github external
watch html and serves as the primary source of obtaining the stream
    manifest data.

    :param str watch_html:
        The html contents of the watch page.
    :param bool age_restricted:
        Is video age restricted.
    :rtype: str
    :returns:
        Substring of the html containing the encoded manifest data.
    """
    if age_restricted:
        pattern = r";yt\.setConfig\(\{'PLAYER_CONFIG':\s*({.*})(,'EXPERIMENT_FLAGS'|;)"  # noqa: E501
    else:
        pattern = r';ytplayer\.config\s*=\s*({.*?});'
    yt_player_config = regex_search(pattern, html, group=1)
    return json.loads(yt_player_config)
github rols1 / Kodi-Addon-ARDundZDF / resources / lib / pytube / extract.py View on Github external
A YouTube video identifier.
	:param str watch_url:
		A YouTube watch url.
	:param str watch_html:
		The html contents of the watch page.
	:param str embed_html:
		The html contents of the embed page (for age restricted videos).
	:param bool age_restricted:
		Is video age restricted.
	:rtype: str
	:returns:
		:samp:`https://youtube.com/get_video_info` with necessary GET
		parameters.
	"""
	if age_restricted:
		sts = regex_search(r'"sts"\s*:\s*(\d+)', embed_html, group=1)
		# Here we use ``OrderedDict`` so that the output is consistent between
		# Python 2.7+.
		params = OrderedDict([
			('video_id', video_id),
			('eurl', eurl(video_id)),
			('sts', sts),
		])
	else:
		params = OrderedDict([
			('video_id', video_id),
			('el', '$el'),
			('ps', 'default'),
			('eurl', quote(watch_url)),
			('hl', 'en_US'),
		])
	return 'https://youtube.com/get_video_info?' + urlencode(params)
github nficano / pytube / pytube / cipher.py View on Github external
pattern = [
        r'\b[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?P[a-zA-Z0-9$]+)\(',  # noqa: E501
        r'\b[a-zA-Z0-9]+\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*encodeURIComponent\s*\(\s*(?P[a-zA-Z0-9$]+)\(',  # noqa: E501
        r'(?P[a-zA-Z0-9$]+)\s*=\s*function\(\s*a\s*\)\s*{\s*a\s*=\s*a\.split\(\s*""\s*\)',  # noqa: E501
        r'(["\'])signature\1\s*,\s*(?P[a-zA-Z0-9$]+)\(',
        r'\.sig\|\|(?P[a-zA-Z0-9$]+)\(',
        r'yt\.akamaized\.net/\)\s*\|\|\s*.*?\s*[cs]\s*&&\s*[adf]\.set\([^,]+\s*,\s*(?:encodeURIComponent\s*\()?\s*(?P[a-zA-Z0-9$]+)\(',  # noqa: E501
        r'\b[a-zA-Z0-9]+\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*(?P[a-zA-Z0-9$]+)\(',  # noqa: E501
        r'\bc\s*&&\s*a\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P[a-zA-Z0-9$]+)\(',  # noqa: E501
        r'\bc\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P[a-zA-Z0-9$]+)\(',  # noqa: E501
        r'\bc\s*&&\s*[a-zA-Z0-9]+\.set\([^,]+\s*,\s*\([^)]*\)\s*\(\s*(?P[a-zA-Z0-9$]+)\(',  # noqa: E501
    ]

    logger.debug('finding initial function name')
    return regex_search(pattern, js, group=1)