internal YoutubeVideo(string title, UnscrambledQuery query, string jsPlayer) { _title = title; _uri = query.Uri; _jsPlayer = jsPlayer; _encrypted = query.IsEncrypted; _formatCode = int.Parse(new Query(_uri)["itag"]); }
internal YouTubeVideo(string title, UnscrambledQuery query, string jsPlayer) { this.Title = title; this.uri = query.Uri; this.jsPlayer = jsPlayer; this.encrypted = query.IsEncrypted; this.FormatCode = int.Parse(new Query(uri)["itag"]); }
internal YouTubeVideo(VideoInfo info, UnscrambledQuery query, string jsPlayer) { this.Info = info; this.Title = info?.Title; this.uri = query.Uri; this.uriQuery = new Query(uri); this.jsPlayer = jsPlayer; this.encrypted = query.IsEncrypted; this.FormatCode = int.Parse(uriQuery["itag"]); }
internal YouTubeVideo(string title, UnscrambledQuery query, string jsPlayer) { this.Title = title; this.uri = query.Uri; this.jsPlayer = jsPlayer; if (DFunctionRegex == null) { DFunctionRegex = new Regex(Task.Run(GetDecryptRegex).Result); } this.encrypted = query.IsEncrypted; this.FormatCode = int.Parse(new Query(uri)["itag"]); }
internal YouTubeVideo(string title, UnscrambledQuery query, string jsPlayer, bool manifestExist = false) { this.Title = title; this.uri = query.Uri; this.jsPlayer = jsPlayer; this.encrypted = query.IsEncrypted; if (manifestExist) { // Link contain "key/value" // separated by slash string x = uri.Substring(uri.IndexOf("itag/") + 5, 3); x = x.TrimEnd('/'); // In case format is 2-digit this.FormatCode = int.Parse(x); } else { this.FormatCode = int.Parse(new Query(uri)["itag"]); } }
private IEnumerable <YouTubeVideo> ParseVideos(string source) { IEnumerable <UnscrambledQuery> queries; string jsPlayer = ParseJsPlayer(source); if (jsPlayer == null) { yield break; } var playerResponseMap = Json.GetKey("player_response", source); var playerResponseJson = JToken.Parse(Regex.Unescape(playerResponseMap).Replace(@"\u0026", "&")); if (string.Equals(playerResponseJson.SelectToken("playabilityStatus.status")?.Value <string>(), "error", StringComparison.OrdinalIgnoreCase)) { throw new UnavailableStreamException($"Video has unavailable stream."); } var errorReason = playerResponseJson.SelectToken("playabilityStatus.reason")?.Value <string>(); if (string.IsNullOrWhiteSpace(errorReason)) { var isLiveStream = playerResponseJson.SelectToken("videoDetails.isLive")?.Value <bool>() == true; string title = playerResponseJson.SelectToken("videoDetails.title")?.Value <string>(); if (isLiveStream) { throw new UnavailableStreamException($"This is live stream so unavailable stream."); } // url_encoded_fmt_stream_map string map = Json.GetKey("url_encoded_fmt_stream_map", source); if (!string.IsNullOrWhiteSpace(map)) { queries = map.Split(',').Select(Unscramble); foreach (var query in queries) { yield return(new YouTubeVideo(title, query, jsPlayer)); } } else // player_response { List <JToken> streamObjects = new List <JToken>(); // Extract Muxed streams var streamFormat = playerResponseJson.SelectToken("streamingData.formats"); if (streamFormat != null) { streamObjects.AddRange(streamFormat.ToArray()); } // Extract AdaptiveFormat streams var streamAdaptiveFormats = playerResponseJson.SelectToken("streamingData.adaptiveFormats"); if (streamAdaptiveFormats != null) { streamObjects.AddRange(streamAdaptiveFormats.ToArray()); } foreach (var item in streamObjects) { var urlValue = item.SelectToken("url")?.Value <string>(); if (!string.IsNullOrEmpty(urlValue)) { var query = new UnscrambledQuery(urlValue, false); yield return(new YouTubeVideo(title, query, jsPlayer)); continue; } var cipherValue = (item.SelectToken("cipher") ?? item.SelectToken("signatureCipher")).Value <string>(); if (!string.IsNullOrEmpty(cipherValue)) { yield return(new YouTubeVideo(title, Unscramble(cipherValue), jsPlayer)); } } } // adaptive_fmts string adaptiveMap = Json.GetKey("adaptive_fmts", source); if (!string.IsNullOrWhiteSpace(adaptiveMap)) { queries = adaptiveMap.Split(',').Select(Unscramble); foreach (var query in queries) { yield return(new YouTubeVideo(title, query, jsPlayer)); } } else { // dashmpd string dashmpdMap = Json.GetKey("dashmpd", source); if (!string.IsNullOrWhiteSpace(adaptiveMap)) { using (HttpClient hc = new HttpClient()) { IEnumerable <string> uris = null; try { dashmpdMap = WebUtility.UrlDecode(dashmpdMap).Replace(@"\/", "/"); var manifest = hc.GetStringAsync(dashmpdMap) .GetAwaiter().GetResult() .Replace(@"\/", "/"); uris = Html.GetUrisFromManifest(manifest); } catch (Exception e) { throw new UnavailableStreamException(e.Message); } if (uris != null) { foreach (var v in uris) { yield return(new YouTubeVideo(title, UnscrambleManifestUri(v), jsPlayer)); } } } } } } }