// // GET: /Video/ public ActionResult Video() { string[] _selected = { "x_4CNvG1Q_M", "raRaxt_KM9Q", "8qSeYLhe09s" }; String _st = YouTubeScript.Get(_selected[0], true, 600, 600, false, "", "", 60); return(new VideoResult()); }
/// <summary> /// Invoked by <see cref="GrabAsync"/> method when the target video has a signature. /// This method downloads the necessary script (base.js) and decipher all grabbed links. /// </summary> protected virtual async Task Decipher(YouTubeEmbedPageData embedPageData, YouTubeMetadata metaData, CancellationToken cancellationToken) { // download base.js var client = HttpHelper.CreateClient(); using var response = await client.GetAsync(embedPageData.BaseJsUri, cancellationToken); var scriptContent = await response.Content.ReadAsStringAsync(); var script = new YouTubeScript(scriptContent); // find decipher function name var match = DecipherFunctionRegex.Match(scriptContent); if (!match.Success) { throw new GrabParseException("Failed to locate decipher function."); } var fn = match.Groups[1].Value; // prepare script host to execute the decipher function along with its used functions script.PrepareDecipherFunctionCall(fn); // call decipher function foreach (var streamInfo in metaData.AllStreams) { if (string.IsNullOrEmpty(streamInfo.Signature)) { continue; } // calculate decipher streamInfo.Decipher = script.CallDecipherFunction(fn, streamInfo.Signature); // update uri streamInfo.Url += $"&sig={Uri.EscapeDataString(streamInfo.Decipher)}"; } }