-
pytube.exceptions.RegexMatchError Issue카테고리 없음 2022. 1. 23. 11:56
유투브에서 영상이나 음악을 받을 수 있는 Python 패키지중 오픈소스인 pytube가 있다. 손쉽게 Video 또는 Playlist를 다운받을 수 있는데, 최근, 아래와 같은 에러가 발생해서 구글링을 통해 이슈를 해결했다.
> python3 Python 3.8.8 (default, Apr 13 2021, 12:59:45) [Clang 10.0.0 ] :: Anaconda, Inc. on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from pytube import YouTube >>> yt = YouTube('https://www.youtube.com/watch?v=GzQ1FebwQHI') >>> yt.streams Traceback (most recent call last): File "/Users/jieunchon/opt/anaconda3/lib/python3.8/site-packages/pytube/__main__.py", line 177, in fmt_streams extract.apply_signature(stream_manifest, self.vid_info, self.js) File "/Users/jieunchon/opt/anaconda3/lib/python3.8/site-packages/pytube/extract.py", line 409, in apply_signature cipher = Cipher(js=js) File "/Users/jieunchon/opt/anaconda3/lib/python3.8/site-packages/pytube/cipher.py", line 33, in __init__ raise RegexMatchError( pytube.exceptions.RegexMatchError: __init__: could not find match for ^\w+\W During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/jieunchon/opt/anaconda3/lib/python3.8/site-packages/pytube/__main__.py", line 292, in streams return StreamQuery(self.fmt_streams) File "/Users/jieunchon/opt/anaconda3/lib/python3.8/site-packages/pytube/__main__.py", line 184, in fmt_streams extract.apply_signature(stream_manifest, self.vid_info, self.js) File "/Users/jieunchon/opt/anaconda3/lib/python3.8/site-packages/pytube/extract.py", line 409, in apply_signature cipher = Cipher(js=js) File "/Users/jieunchon/opt/anaconda3/lib/python3.8/site-packages/pytube/cipher.py", line 33, in __init__ raise RegexMatchError( pytube.exceptions.RegexMatchError: __init__: could not find match for ^\w+\W
cipher.py라는 파일에서 일어나는 이슈였다. Regex때문에 발생하는것으로 보였다.
여러가지 방법이 있었고, 버전을 낮춰라, 다시 설치해라등의 조언이 있었는데, 해결되지 않았고, 내 경우에는 ciper.py 파일을 수정해주는 것으로 해결했다. (source)
맥을 사용하고있는데, 아래 경로로 가면 pytube 가 있는 위치로 갈 수 있다.
> cd ~/opt/anaconda3/lib/python3.8/site-packages/pytube
윈도우는 아래 위치라고 한다.
C:\Users<Your Username>\AppData\Local\Programs\Python\Python38\Lib\site-packages\pytube
해법은 간단하다. 라인 30번째에 가서 (vim 을 이용했는데, 어떤 에디터를 쓰던지 상관 없다) 아래와 같이 고쳐주었다. (해법 github)
# Before: var_regex = re.compile(r"^\w+\W") # After: var_regex = re.compile(r"^\$*\w+\W")
수정후에 다시 시도해보자
> python Python 3.8.8 (default, Apr 13 2021, 12:59:45) [Clang 10.0.0 ] :: Anaconda, Inc. on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from pytube import YouTube >>> yt = YouTube('https://www.youtube.com/watch?v=GzQ1FebwQHI') >>> yt.streams [<Stream: itag="17" mime_type="video/3gpp" res="144p" fps="12fps" vcodec="mp4v.20.3" acodec="mp4a.40.2" progressive="True" type="video">, <Stream: itag="18" mime_type="video/mp4" res="360p" fps="24fps" vcodec="avc1.42001E" acodec="mp4a.40.2" progressive="True" type="video">, <Stream: itag="22" mime_type="video/mp4" res="720p" fps="24fps" vcodec="avc1.64001F" acodec="mp4a.40.2" progressive="True" type="video">, <Stream: itag="137" mime_type="video/mp4" res="1080p" fps="24fps" vcodec="avc1.640028" progressive="False" type="video">, <Stream: itag="248" mime_type="video/webm" res="1080p" fps="24fps" vcodec="vp9" progressive="False" type="video">, <Stream: itag="136" mime_type="video/mp4" res="720p" fps="24fps" vcodec="avc1.4d401f" progressive="False" type="video">, <Stream: itag="247" mime_type="video/webm" res="720p" fps="24fps" vcodec="vp9" progressive="False" type="video">, <Stream: itag="135" mime_type="video/mp4" res="480p" fps="24fps" vcodec="avc1.4d401e" progressive="False" type="video">, <Stream: itag="244" mime_type="video/webm" res="480p" fps="24fps" vcodec="vp9" progressive="False" type="video">, <Stream: itag="134" mime_type="video/mp4" res="360p" fps="24fps" vcodec="avc1.4d401e" progressive="False" type="video">, <Stream: itag="243" mime_type="video/webm" res="360p" fps="24fps" vcodec="vp9" progressive="False" type="video">, <Stream: itag="133" mime_type="video/mp4" res="240p" fps="24fps" vcodec="avc1.4d4015" progressive="False" type="video">, <Stream: itag="242" mime_type="video/webm" res="240p" fps="24fps" vcodec="vp9" progressive="False" type="video">, <Stream: itag="160" mime_type="video/mp4" res="144p" fps="24fps" vcodec="avc1.4d400c" progressive="False" type="video">, <Stream: itag="278" mime_type="video/webm" res="144p" fps="24fps" vcodec="vp9" progressive="False" type="video">, <Stream: itag="139" mime_type="audio/mp4" abr="48kbps" acodec="mp4a.40.5" progressive="False" type="audio">, <Stream: itag="140" mime_type="audio/mp4" abr="128kbps" acodec="mp4a.40.2" progressive="False" type="audio">, <Stream: itag="249" mime_type="audio/webm" abr="50kbps" acodec="opus" progressive="False" type="audio">, <Stream: itag="250" mime_type="audio/webm" abr="70kbps" acodec="opus" progressive="False" type="audio">, <Stream: itag="251" mime_type="audio/webm" abr="160kbps" acodec="opus" progressive="False" type="audio">] >>>
성공!
https://github.com/pytube/pytube/issues/1199
[BUG] RegexMatchError ? · Issue #1199 · pytube/pytube
Until now it's worked perfectly, but now it's showing a issue is this only for me or ?, can anyone help ty Ignoring exception in on_message Traceback (most recent call last): File "/.l...
github.com
https://github.com/pytube/pytube/issues/1105
pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple[BUG] · Issue #1105 · pytube
from pytube import YouTube #ask for the link from user link = input("Enter Video Url: ") video = YouTube(link) video_streams = video.streams.filter(file_extension ='mp4').get_by_i...
github.com
pytube — pytube 11.0.2 documentation
© Copyright Revision 56ccab4f.
pytube.io
pytube.exceptions.RegexMatchError: regex pattern had 0 matches
Im trying to make a youtube playlist downloader with pytube but whatever I try, I get yt = YouTube(link) File "C:\Users\stemb\AppData\Local\Programs\Python\Python37\lib\pytube\__main__.py", ...
stackoverflow.com
Pytube library - Receiving "pytube.exceptions.RegexMatchError: regex pattern" error when attempting to access video data
When attempting to access data such as the "title" of a Youtube video using the pytube API library, I am receiving the following error pytube.exceptions.RegexMatchError: regex pattern (yt.akamai...
stackoverflow.com