Skip to content
Related Articles

Related Articles

Pafy – Getting https URL of Stream
  • Last Updated : 20 Jul, 2020

In this article we will see how we can get secured 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 Resource Locator, and is used to specify addresses on the World Wide Web. A URL is the fundamental network identification for any resource connected to the web (e.g., hypertext pages, images, and sound files). The protocol specifies how information from the link is transferred. Https is the secured url.

We can get the pafy object with the help of new method and with the help of allstreams attribute we can get the 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 the youtube. YouTube is an American online video-sharing platform.

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

Syntax : stream.url_https



Argument : It takes no argument

Return : It returns string

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) 
  
# getting all the available streams
streams = video.allstreams
  
# selecting one stream
stream = streams[1]
  
# getting https url of stream
value = stream.url_https
  
# printing the value
print("URL Htttps : " + str(value))

Output :

URL Htttps : https://r7---sn-ci5gup-pmj6.googlevideo.com/videoplayback?expire=1594861438&ei=HlMPX-nrNayuz7sP_bGqkAo&ip=171.61.220.239&id=o-AJfFxmBn3FJ12CzPKBH36Nm9uavpac34Biht02INP8B9&itag=250&source=youtube&requiressl=yes&mh=rM&mm=31%2C29&mn=sn-ci5gup-pmj6%2Csn-ci5gup-qxae7&ms=au%2Crdu&mv=m&mvi=7&pl=19&initcwndbps=491250&vprv=1&mime=audio%2Fwebm&gir=yes&clen=554085&dur=65.521&lmt=1590825392886674&mt=1594839691&fvip=7&keepalive=yes&c=WEB&txp=5431432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRgIhANgTWTY-4ju_s8pnFzJy4gWHZ6QFUuG0jxpiNNzAB3j6AiEA5aykKDegON8rNiRVL6Frr4if8YmYiD5n-9eY0iaovDA%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhAJH2KIEr4_SwK2k4TmhZiqJgHSHbpognkeTApr8jk3xFAiEAwuH5fERHVoT5bTCC7faXjxRXECMBf3umqpwEMCUdrbs%3D&ratebypass=yes

Another example




# 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 https url of stream
value = stream.url_https
  
# printing the value
print("URL Htttps : " + str(value))

Output :

URL Htttps : https://r3---sn-ci5gup-pmjk.googlevideo.com/videoplayback?expire=1594861433&ei=GVMPX9yKBs-uwgPV2LHICA&ip=171.61.220.239&id=o-AMJ8u2W9CWH0eQFEr34g3qSXbDvUh5UJp_qaEwhdv4PH&itag=278&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278&source=youtube&requiressl=yes&mh=x9&mm=31%2C29&mn=sn-ci5gup-pmjk%2Csn-ci5gup-qxae7&ms=au%2Crdu&mv=m&mvi=3&pcm2cms=yes&pl=19&initcwndbps=585000&vprv=1&mime=video%2Fwebm&gir=yes&clen=8125774&dur=701.933&lmt=1594573565579581&mt=1594839691&fvip=3&keepalive=yes&c=WEB&txp=5535432&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRgIhAP6QlYxQyQnl7Z34mTkbO5PrMgpy-JhTRU_2z8kVtyxQAiEAxE2yYZYMTNGdMsTqyp_JX4P1ruo-Ceubi0zGYKisaqE%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpcm2cms%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRgIhAIY99OO_F3qWdoBbuKkVmK-j4moo6A_o6ToHV_0SjMe3AiEAm7w-BZIe_BPosyMCfyCINJLViYEKQwyPlW_L8UXchkU%3D&ratebypass=yes

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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :