/// <summary> /// Load the days for catch up /// </summary> /// <param name="parentCategory"></param> /// <returns></returns> public static List<Category> LoadCatchUpDays(Category parentCategory) { var doc = new HtmlDocument(); var results = new List<Category>(); var webRequest = (HttpWebRequest)WebRequest.Create(Properties.Resources._4OD_CatchUpUrl); var webResponse = (HttpWebResponse)webRequest.GetResponse(); if (webResponse.StatusCode != HttpStatusCode.OK) throw new OnlineVideosException("Unable to retrieve response for 4OD Catch Up Category from " + Properties.Resources._4OD_CatchUpUrl + ", received " + webResponse.StatusCode.ToString()); doc.Load(webResponse.GetResponseStream()); // Load all the days from the page foreach(HtmlNode node in doc.GetElementsByTagName("a").Where(x=>x.GetAttribute("href").StartsWith("/programmes/4od/catchup/date/"))) { var result = new ExtendedCategory(); var dateParts = node.GetAttribute("href").Replace("/programmes/4od/catchup/date/", "").Split('/'); var videoDate = new DateTime(Convert.ToInt32(dateParts[0]), Convert.ToInt32(dateParts[1]), Convert.ToInt32(dateParts[2])); result.Name = parentCategory.Name + " - " + videoDate.ToString("dd MMMM yyyy"); result.SortValue = videoDate.ToString("yyyyMMdd"); result.Other = "U~" + parentCategory.CategoryId() + "~" + Properties.Resources._4OD_RootUrl + node.GetAttribute("href"); result.Thumb = parentCategory.Thumb; result.HasSubCategories = false; result.ParentCategory = parentCategory; results.Add(result); } return results; }
/// <summary> /// Load videos for the specified catch up category (day/channel) /// </summary> /// <param name="parentCategory"></param> /// <returns></returns> public static List<VideoInfo> LoadCatchUpVideos(Category parentCategory) { var doc = new HtmlDocument(); var results = new List<VideoInfo>(); var webRequest = (HttpWebRequest)WebRequest.Create(parentCategory.CategoryInformationPage()); var webResponse = (HttpWebResponse)webRequest.GetResponse(); if (webResponse.StatusCode != HttpStatusCode.OK) throw new OnlineVideosException("Unable to retrieve response for 4OD Catch Up Video from " + parentCategory.CategoryInformationPage() + ", received " + webResponse.StatusCode.ToString()); doc.Load(webResponse.GetResponseStream()); var node = doc.GetElementsByTagName("span").Where(x => x.GetAttribute("class").Contains("tx-" + parentCategory.CategoryId())).FirstOrDefault(); if (node != null) { foreach (HtmlNode listItem in node.ParentNode.ParentNode.SelectSingleNode("ul").SelectNodes("li")) { var item = new VideoInfo(); item.Title = listItem.GetNodeByClass("title").InnerText + (listItem.GetNodeByClass("series-info") == null ? string.Empty : " - " + listItem.GetNodeByClass("series-info").InnerText); item.Description = listItem.GetNodeByClass("synopsis").InnerText; item.Airdate = listItem.GetNodeByClass("txtime").InnerText; //item.ImageUrl = Properties.Resources._4OD_RootUrl + listItem.SelectSingleNode("a/img").GetAttribute("src"); item.Thumb = listItem.SelectSingleNode("a/img").GetAttribute("src"); item.Other = MakeWebSafe(listItem.GetNodeByClass("title").InnerText) + "~" + listItem.SelectSingleNode("a").GetAttribute("href").Split('#')[1]; results.Add(item); } } return results; }
/// <summary> /// Load general categories from the 4OD api page /// </summary> /// <param name="parentCategory"></param> /// <returns></returns> private List<Category> LoadGeneralCategory(string url, Category parentCategory) { var doc = new HtmlDocument(); var results = new List<Category>(); var webRequest = (HttpWebRequest)WebRequest.Create(url); var webResponse = (HttpWebResponse)webRequest.GetResponse(); if (webResponse.StatusCode != HttpStatusCode.OK) throw new OnlineVideosException("Unable to retrieve response for 4OD from " + url + ", received " + webResponse.StatusCode.ToString()); doc.Load(webResponse.GetResponseStream()); // Load all the list items from the page into categories results.AddRange(doc.GetElementsByTagName("li").Where(x => !string.IsNullOrEmpty(x.GetAttribute("class"))).Select(x => x.LoadGeneralCategoryFromListItem(parentCategory))); // See if there's a next page of results to load var nextPage = doc.GetElementsByTagName("ol").First().GetAttribute("data-nexturl"); if (nextPage != "endofresults") results.AddRange(LoadGeneralCategory(Properties.Resources._4OD_RootUrl + nextPage, parentCategory)); return results; }