Get Video Information From A List Of Playlist With Youtube-dl
I'm tryng to get some informations from a list of playlists in youtube with youtube-dl. I've written this code but what it takes is not the video's informations but the playlist in
Solution 1:
The variable you call video
actually holds the playlist information, not the video information. You can find a list of the individual video information in the playlist's entries
attribute.
See below for a possible fix. I renamed your video
variable to playlist
and took the freedom to rewrite it a bit and add output:
import textwrap
import youtube_dl
playlists = [
"https://www.youtube.com/playlist?list=PLRQGRBgN_EnrPrgmMGvrouKn7VlGGCx8m"
]
for playlist in playlists:
with youtube_dl.YoutubeDL({"ignoreerrors": True, "quiet": True}) as ydl:
playlist_dict = ydl.extract_info(playlist, download=False)
# Pretty-printing the video information (optional)
for video in playlist_dict["entries"]:
print("\n" + "*" * 60 + "\n")
if not video:
print("ERROR: Unable to get info. Continuing...")
continue
for prop in ["thumbnail", "id", "title", "description", "duration"]:
print(prop + "\n" +
textwrap.indent(str(video.get(prop)), " | ", lambda _: True)
)
Solution 2:
run the command
youtube-dl --print-json https://www.youtube.com/playlist?list=<playlist_id> > example.json
you can also uses the --get
for retriving specific items for example
youtube-dl --get-title https://www.youtube.com/playlist?list=<playlist_id> > example.txt
Post a Comment for "Get Video Information From A List Of Playlist With Youtube-dl"