Forked from cheadrian/Youtube_Livestream_Parts_download.py
Created
September 5, 2021 15:57
-
-
Save cnleo/cdacbd5ee53186e2b454c90863a394f7 to your computer and use it in GitHub Desktop.
Download Youtube Live streamed video from the start or selected time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#With the help of this script you can download parts from the Youtube Video that is live streamed, from start of the stream till the end | |
import urllib.request | |
import os | |
#E.G: "https://r4---sn-gqn-p5ns.googlevideo.com/videoplayback?expire=1603041842& ..... 2.20201016.02.00&sq=" | |
#The sound link should contain: &mime=audio in it. | |
#Here's an example from NASA LIVE: | |
#VIDEO: https://r5---sn-gqn-p5ns.googlevideo.com/videoplayback?expire=1603165657&ei=eQmOX8TeFtS07gO1xLWwDA&ip=79.115.11.159&id=DDU-rZs-Ic4.1&itag=137&aitags=133%2C134%2C135%2C136%2C137%2C160&source=yt_live_broadcast&requiressl=yes&mh=PU&mm=44%2C29&mn=sn-gqn-p5ns%2Csn-c0q7lnsl&ms=lva%2Crdu&mv=m&mvi=5&pl=20&initcwndbps=1350000&vprv=1&live=1&hang=1&noclen=1&mime=video%2Fmp4&gir=yes&mt=1603143920&fvip=5&keepalive=yes&fexp=23915654&c=WEB&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cvprv%2Clive%2Chang%2Cnoclen%2Cmime%2Cgir&sig=AOq0QJ8wRQIgQMnxy1Yk3HLTpqbOGmjZYH1CXCTNx6u6PgngAVGi4EQCIQDWyaye-u_KGyVQ0HRUsyKVaAzyXbmzDqOGVGpIyP7VtA%3D%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgR5QVZh23NcLE2nRpo5IT-axGEfUCJrXKMmJHjXQdkCYCIFLsIFacvPpy98zaNSB0RfXswacyc-Ru3sYeEjTFym43&alr=yes&cpn=LlPCcTsE_3Xao9Xh&cver=2.20201016.02.00&sq=2504043&rn=13&rbuf=21958 | |
#AUDIO: https://r5---sn-gqn-p5ns.googlevideo.com/videoplayback?expire=1603165657&ei=eQmOX8TeFtS07gO1xLWwDA&ip=79.115.11.159&id=DDU-rZs-Ic4.1&itag=140&source=yt_live_broadcast&requiressl=yes&mh=PU&mm=44%2C29&mn=sn-gqn-p5ns%2Csn-c0q7lnsl&ms=lva%2Crdu&mv=m&mvi=5&pl=20&initcwndbps=1350000&vprv=1&live=1&hang=1&noclen=1&mime=audio%2Fmp4&gir=yes&mt=1603143920&fvip=5&keepalive=yes&fexp=23915654&c=WEB&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Clive%2Chang%2Cnoclen%2Cmime%2Cgir&sig=AOq0QJ8wRAIgWFTZLV1G33cKJoitlK7dUgNg1KuXyvC6F9F7Lc6x3gcCIHaGjehjvVAjUd6cqMnTLtBq9pPRfQWXM3bwI1qQYqpx&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgR5QVZh23NcLE2nRpo5IT-axGEfUCJrXKMmJHjXQdkCYCIFLsIFacvPpy98zaNSB0RfXswacyc-Ru3sYeEjTFym43&alr=yes&cpn=LlPCcTsE_3Xao9Xh&cver=2.20201016.02.00&sq=2504045&rn=20&rbuf=17971 | |
#Use VLC to play the parts. ffmpeg to re-encode / re-mux and then concatenate. | |
vid_link = "VIDEO LINK THE END -> &sq=" | |
sound_link = "AUDIO LINK THE END -> &sq= " | |
#Each part should be equivalent to 5 seconds of video | |
#Please note if what you got on the your link from the sq parameter looks like this &sq=2504043 don't expect | |
#the script to work with 1, 2504043, because the first part probably already expired. | |
#Try to download apropiate parts number, like range(2501043, 2504043). | |
#TO JOIN PARTS with ffmpeg, check this comment | |
#https://gist.github.com/cheadrian/b661fb68a6a87ea64069e641cef68c3e#gistcomment-3495351 | |
os.mkdir("vid", 0o666) | |
os.mkdir("aud", 0o666) | |
for i in range(1, 5000): #Change 5000 according to video lenght and 1 to where you want to start | |
vide_dow = vid_link + str(i) | |
sound_dow = sound_link + str(i) | |
name_vid = "vid/" + str(i) + ".mp4" | |
name_sound = "aud/" + str(i) + ".m4a" | |
urllib.request.urlretrieve(vide_dow, name_vid) | |
urllib.request.urlretrieve(sound_dow, name_sound) | |
print("Downloaded part ", i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment