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
import pafy
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
Another example
import pafy
i_d = "vG2PNdI8axo"
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
Share your thoughts in the comments
Please Login to comment...