Friday, August 29, 2025
HomeLanguagesPafy – Getting Meta Data for Each Item of Playlist

Pafy – Getting Meta Data for Each Item of Playlist

In this article we will see how we can get the meta data of 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. Metadata is “data that provides information about other data”. In other words, it is “data about data.” Many distinct types of metadata exist, including descriptive metadata, structural metadata, administrative metadata, reference metadata and statistical metadata. 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 to get the playlist ID 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 6. Store the result in a variable and save it.

Below is the implementation 

Python3




# importing pafy
import pafy
   
# url of playlist
url = "https://www.youtube.com / playlist?list = PLqM7alHXFySGqCvcwfqqMrteqWukz9ZoE"
 
# getting playlist
playlist = pafy.get_playlist(url)
 
# getting playlist items
items = playlist["items"]
 
# selecting single item
item = items[1]
 
# getting pafy object
i_pafy = item['pafy']
     
# getting meta data
metadata = item['playlist_meta']
 
# printing meta data
print(metadata)


Output :

{'added': '06/01/2016', 'is_cc': False, 'is_hd': True, 'likes': 1111, 'title': 'Write a program to print all permutations of a given string | neveropen', 'views': '334, 905', 'rating': 4.0, 'author': 'neveropen', 'user_id': '0RhatS1pyxInC00YKjjBqQ', 'privacy': 'public', 'start': 0.0, 'dislikes': 227, 'duration': '11:52', 'comments': '116', 'keywords': '', 'thumbnail': 'https://i.ytimg.com/vi/AfxHGNRtFac/default.jpg', 'cc_license': False, 'category_id': 22, 'description': 'Explanation for the Article: https://www.geeksforgeeks.org/write-a-c-program-to-print-all-permutations-of-a-given-string/\n\nThis video is contributed by Sephiri.\n#neveropen', 'encrypted_id': 'AfxHGNRtFac', 'time_created': 1490874673, 'time_updated': None, 'length_seconds': 712, 'end': 712}

Another example 

Python3




# importing pafy
import pafy
   
# url of playlist
url = "https://www.youtube.com / playlist?list = PLqM7alHXFySE71A2bQdYp37vYr0aReknt"
   
# getting playlist
playlist = pafy.get_playlist(url)
 
# getting playlist items
items = playlist["items"]
 
# selecting single item
item = items[2]
 
# getting meta data
metadata = item['playlist_meta']
 
# printing meta data
print(metadata)


Output :

{'added': '27/09/2017', 'is_cc': True, 'is_hd': True, 'likes': 192, 'title': 'Find subarray with given sum | Set 1 (Non-negative Numbers) | neveropen', 'views': '32, 716', 'rating': 3.0, 'author': 'neveropen', 'user_id': '0RhatS1pyxInC00YKjjBqQ', 'privacy': 'public', 'start': 0.0, 'dislikes': 78, 'duration': '2:50', 'comments': '24', 'keywords': 'neveropen Programming Algorithms "Data Structures" Coding Tutorial array "non-negative numbers"', 'thumbnail': 'https://i.ytimg.com/vi/GY-KULykGaw/default.jpg', 'cc_license': False, 'category_id': 27, 'description': "Find Complete Code at neveropen Article: https://www.geeksforgeeks.org/find-subarray-with-given-sum/\n\nPractice Problem Online Judge: http://practice.geeksforgeeks.org/problems/subarray-with-given-sum/0\n\nThis video is contributed by Shubham Kumar\n\nPlease Like, Comment and Share the Video among your friends.\n\nAlso, Subscribe if you haven't already! :)", 'encrypted_id': 'GY-KULykGaw', 'time_created': 1506577926, 'time_updated': None, 'length_seconds': 170, 'end': 170}
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32247 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6615 POSTS0 COMMENTS
Nicole Veronica
11788 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11835 POSTS0 COMMENTS
Shaida Kate Naidoo
6731 POSTS0 COMMENTS
Ted Musemwa
7011 POSTS0 COMMENTS
Thapelo Manthata
6686 POSTS0 COMMENTS
Umr Jansen
6699 POSTS0 COMMENTS