【问题标题】:Pytube playlist doesn't download any videoPytube 播放列表不下载任何视频
【发布时间】:2020-12-15 18:32:40
【问题描述】:

我尝试使用带有此代码的 pytube3 库下载播放列表

import pytube
import os

# download playlist
playlist = pytube.Playlist(
    "https://www.youtube.com/playlist?list=PLQVvvaa0QuDcjD5BAw2DxE6OF2tius3V3")

i = 1
print(len(playlist.video_urls))
for link in playlist:
    #if i < 51:
        # break
        #i = i + 1
    #    continue
    yt = pytube.YouTube(link)
    file = yt.streams.get_highest_resolution().download() #"D:\YOUTUBE\Gabrysia"
    # find last backslash, because it is followed by an relative path
    # and insert number in the beginning
    last_backslash = file.rfind("\\")
    res = list(file)
    res.insert(last_backslash + 1, str(i) + " ")
    res = ''.join(res)
    # rename file
    os.rename(file, str(res))
    i = i + 1

print('done')

第一个打印语句打印 0,这意味着我的播放列表是空的。我尝试了很多播放列表,但它根本不起作用。我记得我前段时间下载了很多播放列表,但现在无法正常工作。也许 YouTube 后端有一些变化?但据我所知,有新版本的 pytube 库(pytube4、pytubeX),我安装了这个版本,但它仍然无法正常工作。

【问题讨论】:

    标签: python youtube youtube-api pytube


    【解决方案1】:

    我没有足够的声誉来发表评论。所以添加作为答案。 此错误已在 original pytube 存储库中修复。直接从 repo 进行 pip install ,它应该可以工作。

    【讨论】:

    • 我使用 pip 和 conda 安装,我得到这个错误: ImportError: cannot import name 'quote' from 'pytube.compat'
    • 我认为如果您不使用 python3,就会发生这种情况。此外,即使您安装了 python3,conda 也可能在 python2 环境中运行您的脚本。所以安装 python3 并在不使用 conda 的情况下运行你的脚本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-19
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    相关资源
    最近更新 更多