Open In App

Pafy – Creating a Pafy Object

Last Updated : 20 Jul, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads