Pafy – Getting Description for each item of Playlist
Last Updated :
28 Jul, 2020
In this article we will see how we get the description for each item of playlist in pafy. Pafy is a python library to download YouTube content and retrieve metadata. Pafy object is the object which contains all the information about the given video. A playlist in YouTube is a list, or group, of videos that plays in order, one video after the other. A description of the item is the text that give information about the given item of the playlist.
We can get the playlist from youtube in pafy with the help of get_playlist
method, below is the command given to do this
pafy.get_playlist(url)
The playlist url should exist on youtube as it get the information of those videos which are present on the youtube. YouTube is an American online video-sharing platform.
Steps for implementation
1. Import the pafy module
2. Get the playlist with the help of URL of playlist
3. Return play list work as dictionary so use ‘items’ as key with the return playlist
4. Store the result in variable and from the items select the single item
5. With the single item use ‘playlist_meta’ key with it to get the meta data
6. With the meta data use ‘description’ key this will return description for given item
Below is the implementation
import pafy
playlist = pafy.get_playlist(url)
items = playlist[ "items" ]
item = items[ 1 ]
i_pafy = item[ 'pafy' ]
metadata = item[ 'playlist_meta' ]
value = metadata[ 'description' ]
print ( "Description : " + str (value))
|
Output :
Description : Explanation for the Article: https://www.geeksforgeeks.org/write-a-c-program-to-print-all-permutations-of-a-given-string/
This video is contributed by Sephiri.
#geeksforgeeks
Another example
import pafy
playlist = pafy.get_playlist(url)
items = playlist[ "items" ]
item = items[ 2 ]
metadata = item[ 'playlist_meta' ]
value = metadata[ 'description' ]
print ( "Description : " + str (value))
|
Output :
Description : Find Complete Code at GeeksforGeeks Article: https://www.geeksforgeeks.org/find-subarray-with-given-sum/
Practice Problem Online Judge: http://practice.geeksforgeeks.org/problems/subarray-with-given-sum/0
This video is contributed by Shubham Kumar
Please Like, Comment and Share the Video among your friends.
Also, Subscribe if you haven't already! :)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...