【问题标题】:pytube playlist is returning empty arraypytube 播放列表返回空数组
【发布时间】:2020-10-03 13:43:33
【问题描述】:
最近 pytube 开始返回一个空的播放列表。是什么导致此播放列表为空?
from pytube import Playlist
link = 'https://www.youtube.com/watch?
v=2HtaIvb61Uk&list=PLu8BgVaWowIG_0omesGRkKXK2mqWqAKXU'
print(Playlist(link))
result: []
此播放列表应返回多个链接。我不知道这是更新问题还是代码错误,但如果有人知道如何解决它,我将非常感激:)
【问题讨论】:
标签:
python-3.x
playlist
pytube
【解决方案1】:
pytube 中似乎还有另一个问题,这可能与 YouTube 更改其代码有关。下面的代码将输出播放列表中的项目数。
import re
from pytube import Playlist
playlist = Playlist('https://www.youtube.com/watch?v=2HtaIvb61Uk&list=PLu8BgVaWowIG_0omesGRkKXK2mqWqAKXU')
playlist._video_regex = re.compile(r"\"url\":\"(/watch\?v=[\w-]*)")
print(len(playlist.video_urls))
#output 14