Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I can't make a foor loop to put number before video_title and URL in pytube

i just want to give program a url of a playlist and print the title and urls and before titles and urls i want be Ordinal numbers also i new in python

i try for loop and while loop an i get list error

from pytube import YouTube
from pytube import Playlist

SAVE_PATH = "E:/"
i =0
p = Playlist("the play list url")

for i in p:
    print(i + p.title)
    print(i +p.video_urls )
    i += 1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I think you are missing in "for" loop, you tried to use as index for videos, you can do it using with this way;

from pytube import YouTube
from pytube import Playlist
from pprint import pp

save_path = '.'
my_list = Playlist("https://www.youtube.com/playlist?app=desktop&list=PL4A1F702CEBDEAAA3")
list_details = []

for order, video in enumerate(my_list):
    current_video = YouTube(video)
    list_details.append({
        'order': order+1,
        'title': current_video.title,
        'author': current_video.author
    })
pp(list_details)

here is the sample output;

[{'order': 1, 'title': 'Stars & Stripes', 'author': 'WSB111'},
 {'order': 2, 'title': 'Lincoln Memorial', 'author': 'WSB111'},
 {'order': 3, 'title': 'Spring has Sprung', 'author': 'WSB111'},
 {'order': 4, 'title': 'Purple Monument Majesty', 'author': 'WSB111'},
 {'order': 5, 'title': 'Freedom', 'author': 'WSB111'},
 {'order': 6, 'title': 'American Montage', 'author': 'WSB111'}]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading