最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How to get download able url of live stream videos on youtube - Stack Overflow

matteradmin6PV0评论

I'm writing a tool for downloading videos from youtube including live stream videos in c#.What I'm doing is: get html source from youtube url like "" then I'll find a javascript fragment of code that contains the configurations for the playing video in JSON which contains a list of actual video url that I can be abale to download for 1080p-720p-480p-360p and so on,Its working perfectly with normal videos and some livestream videos but with Fox News Live chanel("") I can't find any urls for 080p-720p-480p-360p other than a .m3u8 url

(".1~23716582/go/1/gcr/vn/sparams/ei,gcr,go,hfr,id,ip,ipbits,itag,maudio,playlist_type,ratebypass,requiressl,source,tx,txs,expire/requiressl/yes/itag/0/playlist_type/DVR/signature/3696DA0D44C88FCB370F27A780985017099507B2.9D3CB7209C75E0656424848394DAB3C65161365D/txs/9486106,9486107,9486108,9486113,9486114/maudio/1/expire/1514883856/ipbits/0/ratebypass/yes/dover/8/source/yt_live_broadcast/ip/118.107.71.247/key/yt6/ei/sPZKWu7RG4qx4AKKwJmACg/tx/9486113/hfr/1/file/index.m3u8"),

I've tried that .m3u8 url with VLC media player but there was only one image display on screen. So anyone please tell me is my solution to get videos from youtube ok? is there a better way? I'm writing the tool in c# but I can switch to any other programming languages.

I'm writing a tool for downloading videos from youtube including live stream videos in c#.What I'm doing is: get html source from youtube url like "https://www.youtube./watch?v=bnpPLjEudoU" then I'll find a javascript fragment of code that contains the configurations for the playing video in JSON which contains a list of actual video url that I can be abale to download for 1080p-720p-480p-360p and so on,Its working perfectly with normal videos and some livestream videos but with Fox News Live chanel("https://www.youtube./watch?v=bnpPLjEudoU") I can't find any urls for 080p-720p-480p-360p other than a .m3u8 url

("https://manifest.googlevideo./api/manifest/hls_variant/keepalive/yes/id/bnpPLjEudoU.1~23716582/go/1/gcr/vn/sparams/ei,gcr,go,hfr,id,ip,ipbits,itag,maudio,playlist_type,ratebypass,requiressl,source,tx,txs,expire/requiressl/yes/itag/0/playlist_type/DVR/signature/3696DA0D44C88FCB370F27A780985017099507B2.9D3CB7209C75E0656424848394DAB3C65161365D/txs/9486106,9486107,9486108,9486113,9486114/maudio/1/expire/1514883856/ipbits/0/ratebypass/yes/dover/8/source/yt_live_broadcast/ip/118.107.71.247/key/yt6/ei/sPZKWu7RG4qx4AKKwJmACg/tx/9486113/hfr/1/file/index.m3u8"),

I've tried that .m3u8 url with VLC media player but there was only one image display on screen. So anyone please tell me is my solution to get videos from youtube ok? is there a better way? I'm writing the tool in c# but I can switch to any other programming languages.

Share Improve this question edited Jan 2, 2018 at 3:17 user2905416 asked Jan 2, 2018 at 3:10 user2905416user2905416 4428 silver badges25 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

*Finally I found a solution myself,with normal video on youtube: +I get HTMLpage source from a youtube url using:

    string pageSource = WebClient.DownloadString(youtubeURL)   

+From HTML source I find the configurations for the video I want to download using Regularexpression and convert what I found to JSON:

    var dataRegex = new Regex(@"ytplayer\.config\s*=\s*(\{.+?\});", RegexOptions.Multiline);
        string extractedJson = dataRegex.Match(pageSource).Result("$1");
        Object[] objs = new Object[] { url, JObject.Parse(extractedJson) };

+Json object that I got will has the format like this:

{

"attrs": {

"id": "movie_player"

},

"params": {

"allowscriptaccess": "always",
"allowfullscreen": "true",
"bgcolor": "#000000"

},

"args": {

"c": "WEB",
"vmap": "",
"iv_load_policy": "1",
"innertube_api_version": "v1",
"xhr_apiary_host": "youtubei.youtube.",
"length_seconds": "3826",
"relative_loudness": "-8.05900001526",
"pltype": "contentugc",
"title": "",
"host_language": "vi",
"enablecsi": "1",
"vm": "CAEQARgE",
"eventid": "gN9VWsD2HYu1qQHYh6DYCQ",
"plid": "AAViaNGgboLtCsQo",
"watermark": "",
"enablejsapi": "1",
"no_get_video_log": "1",
"loaderUrl": "https://www.youtube./watch?v=oGeAFd9zjDI",
"vss_host": "s.youtube.",
"oid": "h6xIstk06YQWVvfO-FkUjg",
"cver": "1.20180108",
"ldpj": "-35",
"timestamp": "1515577216",
"thumbnail_url": "https://i.ytimg./vi/oGeAFd9zjDI/default.jpg",
"view_count": "941366",
"idpj": "-9",
"fexp":"",
"loudness": "-29.0590000153",
"allow_ratings": "1",
"pyv_ad_channel": "",
"apiary_host": "",
"tmi": "1",
"fmt_list": "22/1280x720,43/640x360,18/640x360,36/320x180,17/176x144",
"video_id": "oGeAFd9zjDI",
"subtitles_xlb": "https://s.ytimg./yts/xlbbin/subtitles-strings-vi_VN-vfl-WQ1GC.xlb",
"videostats_playback_base_url": " ",
"player_response": "{}",
"ptk": "youtube_single",
"ucid": "UCIt0gjo6BZk37cLWm04LmCQ",
"apiary_host_firstparty": "",
"t": "1",
"swf_player_response": "1",
"ssl": "1",
"avg_rating": "4.11271858215",
"allow_embed": "1",
"is_listed": "1",
"cr": "VN",
"itct": "CAMQu2kiEwjAtvmMjc3YAhWLWioKHdgDCJso-B0=",
 "atc":"",
 "fflags":"",
"cl": "181278566",
"iv_invideo_url": "",
"player_error_log_fraction": "1.0",
"of": "Ds_CbA89Q3Fyo-EOejl1bA",
"token": "1",
"external_play_video": "1",
"show_pyv_in_related": false,
"account_playback_token": "",
"innertube_api_key": "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8",
"csi_page_type": "watch,watch7_html5",
"adaptive_fmts": "",
"gapi_hint_params": "",
"author": "Mr Dolphin",
"ppv_remarketing_url": "",
"innertube_context_client_version": "1.20180108",
"hl": "vi_VN",
"url_encoded_fmt_stream_map": "list of actual urls for 1080p,720p,360p and so on, that will be able to download after decode",
"iv3_module": "1",
"keywords": " ",
"ismb": "8340000",
"watch_xlb": "https://s.ytimg./yts/xlbbin/watch-strings-vi_VN-vflzKZ5ht.xlb"

},

"url": "",

"min_version": "8.0.0",

"sts": 17536,

"assets": {

"js": "/yts/jsbin/player-vfluepRD8/vi_VN/base.js",
"css": "/yts/cssbin/player-vfl_z2Ycb/www-player.css"

}, "html5": true }

+Now when I have JsonObject I will find all the urls that can be able to download the video using:

     string urlsToDownload = json["args"]["url_encoded_fmt_stream_map"].ToString();

*With Live stream video I go through the same process as normal video but in last step instead of get a list of download able urls I have to get the .m3u8 url by:

   string downloadUrl = WebUtility.UrlDecode(json["args"]["hlsvp"].ToString());

+When I have .m3u8 url I download the livestream video using "FFMPEG"

Post a comment

comment list (0)

  1. No comments so far