Skip to content
Related Articles

Related Articles

Pafy – Creating a Pafy Object
  • Last Updated : 20 Jul, 2020

In this article we will see how we can create a pafy object. 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. The video 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 headquartered in San Bruno, California.

In order to do this we use pafy.new method

Syntax : pafy.new(video)

Argument : It takes youtube video url or 11 character video id

Return : It returns pafy object



Below is the implementation




# importing pafy
import pafy 
    
# url of video 
url = "https://www.youtube.com / watch?v = vG2PNdI8axo"
    
# getting video
video = pafy.new(url) 
  
# printing video object
print(video)

Output :

Title: DSA Self Paced Course | GeeksforGeeks
Author: GeeksforGeeks
ID: vG2PNdI8axo
Duration: 00:01:06
Rating: 4.6894979
Views: 75431
Thumbnail: http://i.ytimg.com/vi/vG2PNdI8axo/default.jpg

Another example




# importing pafy
import pafy 
    
# id of video 
i_d = "vG2PNdI8axo"
    
# getting video through id
video = pafy.new(url) 
  
print(video)

Output :

Title: DSA Self Paced Course | GeeksforGeeks
Author: GeeksforGeeks
ID: vG2PNdI8axo
Duration: 00:01:06
Rating: 4.6894979
Views: 75431
Thumbnail: http://i.ytimg.com/vi/vG2PNdI8axo/default.jpg

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :