pythonpython-3.xpafy

I am getting error when I am trying to get video links of YouTube playlist using Paffy


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**

After getting the proper output it is showing me an error as list index out of range Can anyone help me out how to avoid the error?

"Youtube link I am using is:


Solution

  • Just guessing here but you should probably change l = len(playlist['author']) to l = len(playlist['items']), as you want to loop over the playlist items.