public async Task <MovieStream> GetStreamSetAsync() { var request = WebHttp.CreateRequest(uri); request.CookieContainer = new System.Net.CookieContainer(); var response = await WebHttp.GetWebResponse(request); var streamInfo = new MovieStream(); streamInfo.Cookies = request.CookieContainer.GetCookies(uri); using (var sr = new StreamReader(response.GetResponseStream())) { var match = VideoRegex.Match(sr.ReadToEnd()); if (!match.Success) { throw new InvalidDOMStructureException("Unable to find the video source uri"); } streamInfo.VideoStreams.Add(new VideoStream { AVStream = match.Groups[1].Value }); } return(streamInfo); }
public async Task <MovieStream> GetStreamSetAsync() { var response = await WebHttp.GetWebResponse(uri); using (var reader = new StreamReader(response.GetResponseStream())) { var content = await reader.ReadToEndAsync(); int startIndex = content.IndexOf(SearchPattern, StringComparison.CurrentCultureIgnoreCase); if (startIndex < 0) { throw new InvalidDOMStructureException("Unable to find the start point of the escaped flash"); } startIndex += SearchPattern.Length; var endIndex = content.IndexOf('\"', startIndex); if (endIndex < 0) { throw new InvalidDOMStructureException("Unable to find the end point of the escaped flash"); } var flashContent = Utilities.EscapeJavaScript(content.Substring(startIndex, endIndex - startIndex)); startIndex = flashContent.IndexOf('{'); if (startIndex < 0) { throw new InvalidDOMStructureException("Unable to find the start character for the Json data"); } endIndex = flashContent.LastIndexOf('}'); if (endIndex < 0) { throw new InvalidDOMStructureException("Unable to find the end character for the Json data"); } var json = Newtonsoft.Json.Linq.JObject.Parse(flashContent.Substring(startIndex, endIndex - startIndex + 1)); var movieStreamSet = new MovieStream(); JToken token; if (json.TryGetValue("provider", out token) && !token.ToString().Equals("http", StringComparison.CurrentCultureIgnoreCase)) { logger.Warning(string.Format("An non HTTP provider was found: {0}", token.ToString())); } if (!json.TryGetValue(((string)token) + ".startparam", out token)) { logger.Warning("Unable to find a valid value for the http.startparam"); } if (!json.TryGetValue("file", out token)) { throw new InvalidDOMStructureException("Unable to find the 'file' value in the JSON data"); } movieStreamSet.VideoStreams.Add(new VideoStream { AVStream = CreateUri((string)token).ToString(), }); if (json.TryGetValue("tracks", out token)) { foreach (var jcaption in token.OfType <JObject>()) { var caption = new Caption { Language = (string)jcaption["label"], Address = CreateUri((string)jcaption["file"]).ToString() }; movieStreamSet.Captions.Add(caption); } } return(movieStreamSet); } }