Pytube RegexMatchError

删除回忆录丶 提交于 2020-01-05 13:02:43

问题


I am trying to write script in python where a user is prompted to enter a youtube link on the command line. This link should then be downloaded

from pytube import YouTube

downloadFile = raw_input("Enter your Youtube link: ")
YouTube(downloadFile).streams.first().download()

However when the link is entered on the command line I get the following:

File "dl.py", line 10, in <module>
    YouTube(downloadFile).streams.first().download()
  File "build/bdist.linux-x86_64/egg/pytube/__main__.py", line 69, in __init__
  File "build/bdist.linux-x86_64/egg/pytube/extract.py", line 43, in video_id
  File "build/bdist.linux-x86_64/egg/pytube/helpers.py", line 39, in regex_search
pytube.exceptions.RegexMatchError: regex pattern ((?:v=|\/)([0-9A-Za-z_-]{11}).*) had zero matches

I am able to get get it working via python interpeter.

Any suggestions are welcome!


回答1:


Ok, after a bit of rooting around this seems to do the trick

import sys # import sys 
import pytube

link = raw_input('Please enter a url link\n')
yt = pytube.YouTube(link)
stream = yt.streams.first()
finished = stream.download()
print 'Download is complete'

sys.exit()


来源:https://stackoverflow.com/questions/52190699/pytube-regexmatcherror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!