2

I'm trying to get all the urls of the videos in a playlist. The playlist contains 700+ videos.

When I create a playlist with pafy.get_playlist it only creates an array with 194 videos, not all of them.

So is there a size limit for the playlist with pafy?

Drakalex
  • 1,488
  • 3
  • 19
  • 39

3 Answers3

3

According to this issue on their github page you can just use get_playlist2()

JalxP
  • 329
  • 3
  • 10
1

Hello Everyone this is my first answer:)
you can use get_playlist2() as @JalxP said
just checkout the below code and run it.
I think It should solve the problem Thanks!

import pafy
import sys
import time
url = sys.argv[1] # takes the playlist link as argument
details = pafy.get_playlist(url)
playlist = pafy.get_playlist2(url)
# below three statements print the tilte,author and number of videos
print(details['title'])
print(details['author'])
print(len(playlist))
# path to store the videos
userpath = input("enter path to save the playlist:")
# you can modify this for loop for a particular range of videos 
# this a bare-bone
# this loop downloads all the videos in the playlist
for item in range(len(playlist)):
    url = playlist[item].getbest()
    url.download(userpath)
    time.sleep(3)# just to not make immediate download calls
  • As it's your first answer, it would be great if you could get into the habit of posting some context with your answer, particularly when answering a 2 year old question with an already accepted answer. "Run it. It should work fine" won't make your answer valuable to people in the future looking for answers to their problems. See: [How do I write a good answer](https://stackoverflow.com/help/how-to-answer). – David Buck Jan 21 '20 at 11:13
  • Thanks for the suggestion David :) I meant to look at the solution as an extension to @JalxP's answer which had already solved the problem – rohith vishaal Jan 21 '20 at 14:53
-3
import os
from pafy import get_playlist
import pafy
from pafy import *
from socket import *

name_pc=gethostname()
var2=name_pc.split("-")[0] # ex: ("document-PC") -> ["document","PC"]to get #name pc 

os.chdir(r"C:\Users\\"+var2+"\\Downloads")
vobj=get_playlist(str(input("Enter a URL :")))

down_path=str(input("Enter a Dir ?: "))


for video in range(len(vobj['items'])):
     down=vobj['items'][video]['pafy'].getbest() # to get all items for item in playlist
     if 1:
          t=r"C:\Users\\"+var2+"\\Downloads"
          down.download(t)
     else:
          down.download(down_path)
B--rian
  • 5,578
  • 10
  • 38
  • 89
  • Hi Omar, welcome to SO! Please edit your answer so that it does not exist of code alone. Also, please adjust the typesetting (if not already done by somebody else). – B--rian Aug 06 '19 at 15:32
  • That answer from my programming and I made a program and it works 100% I'm sure of them and if no one understands a certain part of the code, please contact me via Facebook https://www.facebook.com/omarfithydepYf – Omar Fithy Desoky Aug 08 '19 at 12:05
  • Hi Omar, please just enter the explanation here which you would give on fb so that everybody profits from your knowledge. – B--rian Aug 10 '19 at 16:39