【问题标题】:I'm trying to do a program to download videos of a playlist with pytube, but it doesnt works我正在尝试做一个程序来使用 pytube 下载播放列表的视频,但它不起作用
【发布时间】:2021-01-20 19:23:42
【问题描述】:

我正在尝试做一个从 youtube 下载播放列表视频的程序,这就是程序:

from pytube import Playlist
from pytube import YouTube



playlist = Playlist('https://www.youtube.com/playlist?list=PLZ1u221jNfYGCxHU4RbChwG60X-_nq8HK')
print('Number of videos in playlist: %s' % len(playlist.video_urls))
for video_url in playlist.video_urls:
f = open (r'D:\Nueva carpeta (4)\lista_viejas.txt','a')
f.write("\n")
f.write(str(video_url))

f.close()

with open(r'D:\Nueva carpeta (4)\lista_viejas.txt', 'r') as file1:
with open(r'D:\Nueva carpeta (4)\lista_viejass.txt', 'r') as file2:
    with open (r'D:\Nueva carpeta (4)\output.txt', "w") as out_file:
        f2_lines = set(file2)
        for line in file1:
            if line not in f2_lines:
                
                yt = YouTube(str(line))
                video = yt.streams.first()
                video.download(r'D:\Nueva carpeta (4)')
                
                out_file.write(line)
                f2_lines.add(line)
                

我不知道为什么我在这部分得到这个错误:

Exception has occurred: RegexMatchError
regex_search: could not find match for (?:v=|\/)([0-9A-Za-z_-]{11}).*
File "C:\Users\Andres\Desktop\Untitled-1.py", line 22, in <module>
yt = YouTube(str(line))



yt = YouTube(str(line))
                video = yt.streams.first()
                video.download(r'D:\Nueva carpeta (4)')
                

如果我将参数“line”更改为line_prove=input(),它可以工作。

【问题讨论】:

  • 对于初学者来说,你的缩进是关闭的

标签: python pytube


【解决方案1】:

好吧,我不知道为什么,但我尝试用另一种方式编写它,并且我刚刚添加了它的修复

    YouTube(line).streams.first().download(r'D:\Nueva carpeta (4)' 

【讨论】:

    猜你喜欢
    • 2020-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多