python - 当我尝试使用 Paffy 获取 YouTube 播放列表的视频链接时出现错误

标签 python python-3.x pafy

import pafy
plurl = input("Enter The Link : ")
playlist = pafy.get_playlist(plurl)
l = len(playlist['author'])

#file = open("VideoInformation.txt","w+")

def extract_name_from_title(s):
c=0
name=""
start = s.find("-")
start = start+2
start = int(start)
end = s.find("|")
end = end-1
end = int(end)
name = s[start:end]

return name

for i in range(0,l-1) :
  id = playlist['items'][i]['pafy'].videoid
  v=pafy.new(id)
  #video = pafy.new('https://www.youtube.com/watch?v='+id)
  print("Video Number : {}".format(i))
  name = extract_name_from_title(v.title)
  link = "https://www.youtube.com/watch?v={}".format(id)
  print("Video title :{}".format(name))
  print("Video Link : {}".format(link))

IThis is the code and error window I am using **Spyder**

获得正确的输出后,它向我显示错误列表索引超出范围 谁能帮我解决如何避免错误?

"Youtube link I am using is:

最佳答案

只是在这里猜测,但您可能应该将 l = len(playlist['author']) 更改为 l = len(playlist['items']),如下您想要循环播放列表项目。

关于python - 当我尝试使用 Paffy 获取 YouTube 播放列表的视频链接时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58572376/

相关文章:

python - 我如何用pafy为进度条制作线程

python - 合并两个数组python的所有元素

python - Python 重启后 Gzip 输出不同

python - 开泰结构 : calculated instances with a condition

python - 如何绘制给定函数 f(x) 的基于文本的图形?

python - 在列表中查找小于或等于键的值

python-3.x - Pandas 跨行的最小值和最大值

python-3.x - 反转字符串,但不反转整数

python - Youtube-dl移除,无需流式传输YouTube视频