当我尝试使用Pytube下载整个YouTube播放列表时出错

时间:2020-11-06 22:10:55

标签: python pytube

我的代码:

from pytube import YouTube
import pytube
from pytube import Playlist
import re
import time

playlist = Playlist(input('Skriv in en link til en spilleliste for å laste ned MP3:\n'))

# this fixes the empty playlist.videos list
playlist._video_regex = re.compile(r"\"url\":\"(/watch\?v=[\w-]*)")

print(len(playlist.video_urls))

for url in playlist.video_urls:
    print(url)
    yt = YouTube(url)
    print("Downloading:"+yt.title)
    stream = yt.streams.filter(file_extension=('mp4'), progressive=('true')).get_highest_resolution() 
    stream.download('D:\Filmer\Youtube')
    time.sleep(3) # Sleep for 3 seconds

有时下载15个视频,有时下载17个视频。当我尝试下载播放列表时,我有200个视频,程序立即崩溃。每当我得到这个错误时:

Exception has occurred: RegexMatchError
get_ytplayer_config: could not find match for config_patterns

整个错误代码是:

Traceback (most recent call last):
  File "c:/Users/elias/OneDrive/E-postvedlegg/Dokumenter/Python/Youtube-nedlaster/Start.py", line 23, in <module>
    yt = YouTube(url)
  File "C:\Users\elias\OneDrive\E-postvedlegg\Dokumenter\Python\Youtube-nedlaster\.venv\lib\site-packages\pytube\__main__.py", line 103, in __init__
    self.descramble()
  File "C:\Users\elias\OneDrive\E-postvedlegg\Dokumenter\Python\Youtube-nedlaster\.venv\lib\site-packages\pytube\__main__.py", line 123, in descramble
    self.player_config_args = get_ytplayer_config(self.watch_html)[
  File "C:\Users\elias\OneDrive\E-postvedlegg\Dokumenter\Python\Youtube-nedlaster\.venv\lib\site-packages\pytube\extract.py", line 205, in get_ytplayer_config
    raise RegexMatchError(
pytube.exceptions.RegexMatchError: get_ytplayer_config: could not find match for config_patterns

我尝试使用this安装pytube,但由于某种原因我无法安装。

0 个答案:

没有答案