/// <summary> /// Parses a syndication feed. /// </summary> /// <param name="url">The URL to the feed.</param> /// <returns> /// Extracted articles. /// </returns> protected IEnumerable<Article> ParseFeed(string url) { var xml = Utils.GetXML(url); var rss = SyndicationFeed.Load(xml.CreateReader()); if (rss == null) { yield break; } foreach (var item in rss.Items) { var article = new Article(this); try { article.Title = HtmlEntity.DeEntitize(item.Title.Text); article.Summary = Regex.Replace(HtmlEntity.DeEntitize(item.Summary.Text), @"\s*<[^>]+>\s*", string.Empty).Trim(); article.Date = item.PublishDate.DateTime; article.Link = HtmlEntity.DeEntitize(item.Links[0].Uri.ToString()); } catch { continue; } yield return article; } }
/// <summary> /// Gets the cached articles from the last search on this service. /// </summary> /// <param name="query">The name of the TV show to get the cached articles for.</param> /// <returns>List of cached articles from the last search or <c>null</c>.</returns> public List<Article> GetCache(string query) { var list = new List<Article>(); var path = Path.Combine(Signature.FullPath, @"feeds\" + Utils.CreateSlug(Name, false) + @"\" + Utils.CreateSlug(query, false)); if (!File.Exists(path)) { return list; } using (var fs = File.OpenRead(path)) using (var br = new BinaryReader(fs)) { var ver = br.ReadByte(); var upd = br.ReadUInt32(); var cnt = br.ReadUInt32(); for (var i = 0; i < cnt; i++) { var article = new Article(this); article.Title = br.ReadString(); article.Date = ((double)br.ReadInt32()).GetUnixTimestamp(); article.Summary = br.ReadString(); article.Link = br.ReadString(); list.Add(article); } } return list; }