英文:
Pytube error while running in Google Colab
问题
I am getting the following error in colab notebook while trying to use pytube for downloading youtube video as mp3 file. I cannot find any solution that works for Colab. Please help me out.
RegexMatchError: __init__: could not find match for ^\w+\W
Here is my code:
for url in url_list:
print(url)
# try:
yt = YouTube(url)
title = yt.title
print("processing " + title)
if os.path.exists(os.path.join(destination, title + ".mp3")):
print("file exists")
continue
video = yt.streams.filter(only_audio=True).first()
print(video)
out_file = video.download(output_path=destination)
base, ext = os.path.splitext(out_file)
new_file = base + '.mp3'
os.rename(out_file, new_file)
英文:
I am getting the following error in colab notebook while trying to use pytube for downloading youtube video as mp3 file. I cannot find any solution that works for Colab. Please help me out.
RegexMatchError: __init__: could not find match for ^\w+\W
Here is my code :
for url in url_list:
print(url)
# try:
yt = YouTube(url)
title = yt.title
print("processing " + title)
if os.path.exists(os.path.join(destination, title + ".mp3")):
print("file exists")
continue
video = yt.streams.filter(only_audio=True).first()
print(video)
out_file = video.download(output_path=destination)
base, ext = os.path.splitext(out_file)
new_file = base + '.mp3'
os.rename(out_file, new_file)
答案1
得分: 1
I solved the above issue in the following manner.
- 我以以下方式解决了上述问题。
- Then in a new branch, I made the following edits to cipher.py file of pytube package - In line 30, I replaced
var_regex = re.compile(r"^\w+\W")
withvar_regex = re.compile(r"^\$*\w+\W")
- 然后在一个新分支中,我对pytube包的cipher.py文件进行了以下编辑 - 在第30行,我将
var_regex = re.compile(r"^\w+\W")
替换为var_regex = re.compile(r"^\$*\w+\W")
- Finally installed the package in colab from my github branch
- 最后,从我的GitHub分支在Colab中安装了该包
!pip install pytube@git+https://github.com/priyankaj1311/pytube.git@master_copy
英文:
I solved the above issue in the following manner.
- I forked the github copy of the pytube package
- Then in a new branch, I made the following edits to cipher.py file of pytube package -In line 30, I replaced
var_regex = re.compile(r"^\w+\W")
withvar_regex = re.compile(r"^\$*\w+\W")
- Finally installedthe package in colab from my github branch
!pip install pytube@git+https://github.com/priyankaj1311/pytube.git@master_copy
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论