'How can I fix this pytube regex error python3 pytube3
I'm having issues with pytube on raspberry pi 4b running python 3.7. Im getting this error code:
%Run Pyoutube_downloader
https://www.youtube.com/watch?v=-QLVxOvESf4
Traceback (most recent call last):
File "/home/pi/Documents/My_Scripts/Pyoutube_downloader", line 5, in <module>
yt = YouTube(link)
File "/home/pi/.local/lib/python3.7/site-packages/pytube/__main__.py", line 71, in __init__
self.video_id = extract.video_id(url)
File "/home/pi/.local/lib/python3.7/site-packages/pytube/extract.py", line 162, in video_id
return regex_search(r"(?:v=|\/)([0-9A-Za-z_-]{11}).*", url, group=1)
File "/home/pi/.local/lib/python3.7/site-packages/pytube/helpers.py", line 129, in regex_search
raise RegexMatchError(caller="regex_search", pattern=pattern)
pytube.exceptions.RegexMatchError: regex_search: could not find match for (?:v=|\/)([0-9A-Za-z_-]{11}).*
I have tried all the changes and updates described on github, I've tried updating everything and ive tried copying and pasting the error code specifically into Google to no avail.
Has anyone had this and fixed it? Any help is greatly appreciated.
Solution 1:[1]
Credits: Modification of the regex expression created by Stack Overflow user kwarunek in his answer
I've modified the regex expression created by Stack Overflow user kwarunek in his answer and this is the result:
(?:https?:\/\/)?(?:www.)?(?:[0-9A-Z-]+\.)?(?:youtube|youtu|youtube-nocookie)\.(?:com|be)\/(?:watch\?v=|watch\?.+&v=|embed\/|v\/|.+\?v=)?([^&=\n%\?]{11})

You can test this regex expression in this demo available at Debuggex.com
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
