*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.com",
"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.com/watch?v=oGeAFd9zjDI",
"vss_host": "s.youtube.com",
"oid": "h6xIstk06YQWVvfO-FkUjg",
"cver": "1.20180108",
"ldpj": "-35",
"timestamp": "1515577216",
"thumbnail_url": "https://i.ytimg.com/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.com/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.com/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"