Skip to content
Related Articles

Related Articles

Pafy – Getting Playlist ID

Improve Article
Save Article
  • Last Updated : 02 Aug, 2022
Improve Article
Save Article

In this article we will see how we can get the youtube playlist ID 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. When one video finishes playing, the next starts automatically so you don’t have to click or search to start playing a new video. A Youtube playlist ID is an unique ID to identify a playlist which is uploaded to Youtube. 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 ‘playlist_id’ as key with the return playlist 4. Store the result in variable and print 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)
 
# printing playlist ID
i_d = playlist["playlist_id"]
 
print(i_d)

Output :

PLqM7alHXFySGqCvcwfqqMrteqWukz9ZoE

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)
 
# printing playlist ID
i_d = playlist["playlist_id"]
 
print(i_d)

Output :

PLqM7alHXFySE71A2bQdYp37vYr0aReknt

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!