Pytube在Google Colab中运行时出现错误。

huangapple go评论60阅读模式
英文:

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.

  1. 我以以下方式解决了上述问题。
  2. 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") with var_regex = re.compile(r"^\$*\w+\W")
  3. 然后在一个新分支中,我对pytube包的cipher.py文件进行了以下编辑 - 在第30行,我将var_regex = re.compile(r"^\w+\W")替换为var_regex = re.compile(r"^\$*\w+\W")
  4. Finally installed the package in colab from my github branch
  5. 最后,从我的GitHub分支在Colab中安装了该包
!pip install pytube@git+https://github.com/priyankaj1311/pytube.git@master_copy
英文:

I solved the above issue in the following manner.

  1. I forked the github copy of the pytube package
  2. 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") with var_regex = re.compile(r"^\$*\w+\W")
  3. Finally installedthe package in colab from my github branch
!pip install pytube@git+https://github.com/priyankaj1311/pytube.git@master_copy

huangapple
  • 本文由 发表于 2023年5月25日 00:51:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76325815.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定