public async Task <MovieStream> GetStreamSetAsync() { var html = await WebHttp.GetHtmlDocument(uri); var flashEmbedded = html.GetElementbyId("flash_video_obj"); if (flashEmbedded == null) { flashEmbedded = html.DocumentNode.SelectSingleNode("//embed[@type='application/x-shockwave-flash']") .ThrowExceptionIfNotExists("Not found the flash embedded element!"); } var query = HttpUtility.ParseQueryString(HttpUtility.HtmlDecode(flashEmbedded.GetAttributeValue("flashvars", null))); var streamSet = new MovieStream(); foreach (var kvp in SupportedVideos) { string movieUrl = HttpUtility.UrlDecode(query.Get(kvp.Key)); if (!string.IsNullOrEmpty(movieUrl)) { streamSet.VideoStreams.Add(new VideoStream { AVStream = movieUrl, Resolution = kvp.Value }); } } if (streamSet.VideoStreams.Count == 0) { throw new ArgumentException("Unable to determine any valid video stream"); } return(streamSet); }
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); }
private static async Task ParseMovieInfoAsync(IMovieBuilder builder, Uri uri) { var html = await WebHttp.GetHtmlDocument(uri); var movieRootElement = html.DocumentNode.SelectSingleNode("//div[@class='filmcontent']/div[@class='filmalti']") .ThrowExceptionIfNotExists("Unable to find the movie root element"); var imgElement = movieRootElement.SelectSingleNode("div[@class='filmaltiimg']/img").ThrowExceptionIfNotExists("Unable to find the 'img' tag element"); var movieDetailsElement = movieRootElement.SelectSingleNode("div[@class='filmaltiaciklama']") .ThrowExceptionIfNotExists("Unable to find the movie details element"); var categories = movieDetailsElement.SelectNodes("p[1]/a/text()") .ThrowExceptionIfNotExists("Unable to find the categories elements") .Select(li => HttpUtility.HtmlDecode(li.InnerText)); var movieInfo = new MovieInfo(new BasicMovieInfo(imgElement.GetAttributeValue("alt", null), uri)); movieInfo.CoverImage = new Uri(imgElement.GetAttributeValue("src", null)); var description = movieDetailsElement.SelectSingleNode("//p[last()]").ThrowExceptionIfNotExists("Unable to find the movie description element").InnerText; int idx = description.IndexOf(':'); if (idx > 0) { movieInfo.Description = HttpUtility.HtmlDecode(description.Substring(idx + 1).Trim()); } foreach (var embeddedMovies in html.DocumentNode.SelectNodes("//object[@type='application/x-shockwave-flash']/param[@name='flashvars']")) { var query = HttpUtility.ParseQueryString(HttpUtility.HtmlDecode(embeddedMovies.GetAttributeValue("value", null))); string captionFile = query.Get("captions.file"); var avstream = HttpUtility.UrlDecode(query.Get("streamer")); if (string.IsNullOrEmpty(captionFile) || string.IsNullOrEmpty(avstream)) { continue; } var streamSet = new MovieStream(); streamSet.Captions.Add(new Caption { Language = "Romanian", Address = captionFile }); streamSet.VideoStreams.Add(new VideoStream { AVStream = avstream }); movieInfo.Streams.Add(streamSet); } }
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); } }