How to use the pytube.exceptions.RegexMatchError 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 mraza007 / videodownloader / gui.py View on Github external
text = f'Codec: {stream.audio_codec}, ' \
                           f'ABR: {stream.abr} ' \
                           f'File Type: {stream.mime_type.split("/")[1]}, Size: {stream.filesize // 1024} KB'
                else:
                    if stream.video_codec is None:
                        continue
                    text = f'Res: {stream.resolution}, FPS: {stream.fps},' \
                           f' Video Codec: {stream.video_codec}, Audio Codec: {stream.audio_codec}, ' \
                           f'File Type: {stream.mime_type.split("/")[1]}, Size: {stream.filesize // 1024} KB'
                radio_button = tk.Radiobutton(self.frame, text=text, variable=self.stream, value=stream.itag)
                self.last_row += 1
                radio_button.grid(row=self.last_row, column=0, columnspan=4)
                self.stream_widgets.append(radio_button)
        except PytubeError as e:
            messagebox.showerror('Something went wrong...', e)
        except RegexMatchError as e:
            messagebox.showerror('Something went wrong...', e)
        finally:
            self.btn_check_id['text'] = 'Check Video'
            self.btn_check_id.config(state=tk.NORMAL)
github YouTubeDownload / YouTubeDownload / qt_assets / tabs / downloader.py View on Github external
self.__download_manager.stream_tree.clear()
        self.__download_manager.streams_to_download = {}
        try:
            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))
github nficano / pytube / pytube / helpers.py View on Github external
A target string to search.
    :param bool groups:
        Should the return value be ``.groups()``.
    :param int group:
        Index of group to return.
    :param int flags:
        Expression behavior modifiers.
    :rtype:
        str or tuple
    :returns:
        Substring pattern matches.
    """
    regex = re.compile(pattern, flags)
    results = regex.search(string)
    if not results:
        raise RegexMatchError(
            'regex pattern ({pattern}) had zero matches'
            .format(pattern=pattern),
        )
    else:
        logger.debug(
            'finished regex search: %s',
            pprint.pformat(
                {
                    'pattern': pattern,
                    'results': results.group(0),
                }, indent=2,
            ),
        )
        if groups:
            return results.groups()
        elif group is not None:
github nficano / pytube / pytube / cipher.py View on Github external
('{\w\.reverse\(\)}', reverse),
        # function(a,b){a.splice(0,b)}
        ('{\w\.splice\(0,\w\)}', splice),
        # function(a,b){var c=a[0];a[0]=a[b%a.length];a[b]=c}
        ('{var\s\w=\w\[0\];\w\[0\]=\w\[\w\%\w.length\];\w\[\w\]=\w}', swap),
        # function(a,b){var c=a[0];a[0]=a[b%a.length];a[b%a.length]=c}
        (
            '{var\s\w=\w\[0\];\w\[0\]=\w\[\w\%\w.length\];'
            '\w\[\w\%\w.length\]=\w}', swap,
        ),
    )

    for pattern, fn in mapper:
        if re.search(pattern, js_func):
            return fn
    raise RegexMatchError(
        'could not find python equivalent function for: ',
        js_func,
    )
github rols1 / Kodi-Addon-ARDundZDF / resources / lib / pytube / extract.py View on Github external
def is_age_restricted(watch_html):
	"""Check if content is age restricted.

	:param str watch_html:
		The html contents of the watch page.
	:rtype: bool
	:returns:
		Whether or not the content is age restricted.
	"""
	try:
		regex_search(r'og:restrictions:age', watch_html, group=0)
	except RegexMatchError:
		return False
	return True
github rols1 / Kodi-Addon-ARDundZDF / resources / lib / pytube / cipher.py View on Github external
('{\w\.reverse\(\)}', reverse),
		# function(a,b){a.splice(0,b)}
		('{\w\.splice\(0,\w\)}', splice),
		# function(a,b){var c=a[0];a[0]=a[b%a.length];a[b]=c}
		('{var\s\w=\w\[0\];\w\[0\]=\w\[\w\%\w.length\];\w\[\w\]=\w}', swap),
		# function(a,b){var c=a[0];a[0]=a[b%a.length];a[b%a.length]=c}
		(
			'{var\s\w=\w\[0\];\w\[0\]=\w\[\w\%\w.length\];'
			'\w\[\w\%\w.length\]=\w}', swap,
		),
	)

	for pattern, fn in mapper:
		if re.search(pattern, js_func):
			return fn
	raise RegexMatchError(
		'could not find python equivalent function for: ',
		js_func,
	)
github nficano / pytube / pytube / extract.py View on Github external
def is_age_restricted(watch_html):
    """Check if content is age restricted.

    :param str watch_html:
        The html contents of the watch page.
    :rtype: bool
    :returns:
        Whether or not the content is age restricted.
    """
    try:
        regex_search(r'og:restrictions:age', watch_html, group=0)
    except RegexMatchError:
        return False
    return True