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 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. 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 the youtube. YouTube is an American online video-sharing platform. In order to do this we use url attribute with the pafy object of video
Syntax : stream.url Argument : It takes no argument Return : It returns string
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[ 1 ] # getting url of stream value = stream.url # printing the value print ("URL : " + str (value)) |
Output :
URL : https://r7---sn-ci5gup-pmj6.googlevideo.com/videoplayback?expire=1594860925&ei=HVEPX62pGozmvwTroYioDQ&ip=171.61.220.239&id=o-ABGKfYL2zfzM02gQs2UDuKQhEteEMoIC2xCH6K7IQj0v&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&pcm2cms=yes&pl=19&initcwndbps=472500&vprv=1&mime=audio%2Fwebm&gir=yes&clen=554085&dur=65.521&lmt=1590825392886674&mt=1594839211&fvip=7&keepalive=yes&c=WEB&txp=5431432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRAIgMhq983QOGWQZAA2eFGKQEyxY1n0xJC9DEZgTAtLiqXYCIC-rXtlUPsuJ9GZj5GwtRMosgFJfttC6BAoa41c6Gmsn&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpcm2cms%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIhAMS2ZVj37jMWTLAe1Z5pUh5hZgaScudgAP_xwr6wDbbBAiAEyxwPwYVIVNfYcoP7pg5QrV3y6CPlGzWvEVfsL27xbg%3D%3D&ratebypass=yes
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 url of stream value = stream.url # printing the value print ("URL : " + str (value)) |
Output :
URL : https://r3---sn-ci5gup-pmjk.googlevideo.com/videoplayback?expire=1594860934&ei=JVEPX6P4OeLW4-EPsaWvgAU&ip=171.61.220.239&id=o-AP4eJDZeRovXfTcJC7nirnR2mFWhuUym4TbwvLgP8j16&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&pl=19&pcm2=no&initcwndbps=591250&vprv=1&mime=video%2Fwebm&gir=yes&clen=8125774&dur=701.933&lmt=1594573565579581&mt=1594839211&fvip=3&keepalive=yes&c=WEB&txp=5535432&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cpcm2%2Cvprv%2Cmime%2Cgir%2Cclen%2Cdur%2Clmt&sig=AOq0QJ8wRgIhAINLqM5ms2bTAZdWrMmejz_11HqKnzC-tsE1WOomPA6dAiEAkuGowLis8kUTYCE0Yf4CtIs4ftni_EY3WwCrYxpMIHk%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgdO1854F8W8wb6YjYROdQ0uDtCd8ef6pGUIQ3Qe-kZVMCICmtOj19ekFBmzcxrWMlM2FwDt3kW8AbVQw_nJKwWWyR&ratebypass=yes