Open In App

Pafy – Getting Weak Reference of Stream

Last Updated : 19 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will see how we can get weak reference if available for the given youtube video stream 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. Stream is basically available resolution of video is available on youtube. A weakly referenced object is cleared by the Garbage Collector when it’s weakly reachable. Weak reachability means that an object has neither strong nor soft references pointing to it. The object can be reached only by traversing a weak reference.

We can get the pafy object with the help of new method and with the help of allstreams attribute we can get all the streams available for the video, below is the command to get the pafy object for given video.

video = pafy.new(url)
streams = video.allstreams

The video url should exist on youtube as it get the information of those videos which are present on youtube. YouTube is an American online video-sharing platform.

In order to do this we use __weakref__ attribute with the pafy object of video 

Syntax : video.__weakref__

Argument : It takes no argument

Return : It returns list 
 

Below is the implementation  

Python3




# importing pafy
import pafy
   
# url of video
url = "https://www.youtube.com / watch?v = vG2PNdI8axo"
   
# getting video
video = pafy.new(url)
 
# getting all the available streams
streams = video.allstreams
 
# selecting one stream
stream = streams[2]
 
# getting weak reference of the stream
value = stream.__weakref__
 
# printing the value
print(value)


Output : 

None

Another example 

Python3




# importing pafy
import pafy
   
# url of video
url = "https://www.youtube.com / watch?v = i6rhnSoK_gc"
   
# getting video
video = pafy.new(url)
 
# getting all the available streams
streams = video.allstreams
 
# selecting one stream
stream = streams[4]
 
# getting weak reference of the stream
value = stream.__weakref__
 
# printing the value
print(value)


Output : 

None

 



Similar Reads

Pafy - Getting Pafy Object for Each Item of Playlist
In this article we will see how we can get the pafy object from playlist items 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. W
2 min read
Pafy - Getting File Size of Stream
In this article we will see how we can get file size given youtube video stream 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. Stream is basically available resolution of video is available on youtube. File size is in the form o
2 min read
Pafy - Getting URL of Stream
In this article we will see how we can get url of the given youtube video stream 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. Stream is basically available resolution of video is available on youtube. URL stands for Uniform Re
2 min read
Pafy - Getting Title of Stream
In this article we will see how we can get title of the given youtube video stream 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. Stream is basically available resolution of video is available on youtube. Title is basically the
2 min read
Pafy - Getting ITag Value of Stream
In this article we will see how we can get the itag value of the given youtube video stream 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. Itag is a youtube is a static youtube video format. We can get the pafy object with the h
2 min read
Pafy - Getting Extension of Stream
In this article we will see how we can get the appropriate extension of the given youtube video stream 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. Stream is basically available resolution of video is available on youtube. Ext
2 min read
Pafy - Getting Dimensions of Stream
In this article we will see how we can get dimensions of the given youtube video stream 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. Stream is basically available resolution of video is available on youtube. Video dimension is
2 min read
Pafy - Getting Dictionary of Stream
In this article we will see how we can get stream dictionary the given youtube video stream 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. Stream is basically available resolution of video is available on youtube. Dictionary con
2 min read
Pafy - Getting Best Video Stream of the given Video
In this article we will see how we can get best video stream of the given youtube video 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. Best video stream is basically a video stream which is available and in highest resolution. T
2 min read
Pafy - Getting Best Stream of the Video
In this article we will see how we can get best stream of the given youtube video 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. Best stream is basically a video + audio stream which is available and in highest resolution. This
2 min read
Article Tags :
Practice Tags :