/// <summary> /// Copies any parse errors to the channel. /// </summary> /// <param name="episode">The episode being created by this parser.</param> private void SaveParseErrors(PodcastEpisode episode) { foreach (string error in ParseErrors) { episode.ParseErrors.Add(error); } }
/// <summary> /// Parses the supplied RSS data. /// </summary> /// <returns>A <see cref="PodcastEpisode"/> instance represented by the RSS data.</returns> public PodcastEpisode Parse() { PodcastEpisode episode = new PodcastEpisode(); episode.Title = GetStringFromChildElement("title", NodeToParse); episode.Link = GetStringFromChildElement("link", NodeToParse); episode.Description = GetStringFromChildElement("description", NodeToParse); GetAuthor(episode); episode.EnclosureUrl = GetStringFromChildElementAttribute("enclosure", "url", NodeToParse); episode.EnclosureSize = GetLongFromChildElementAttribute("enclosure", "length", NodeToParse); episode.EnclosureContentType = GetStringFromChildElementAttribute("enclosure", "type", NodeToParse); episode.Guid = GetStringFromChildElement("guid", NodeToParse); episode.PublishDate = GetDateTimeFromChildElement("pubDate", NodeToParse); episode.Subtitle = GetStringFromChildElement("itunes:subtitle", NodeToParse); episode.ITunesExplicit = GetBooleanFromChildElement("itunes:explicit", NodeToParse); episode.Duration = GetTimeSpanFromChildElement("itunes:duration", NodeToParse); GetImage(episode); SaveParseErrors(episode); if (RemoveParsedContent) { UnparsedContent.Seek(0, System.IO.SeekOrigin.Begin); episode.UnparsedRssData = new StreamReader(UnparsedContent).ReadToEnd(); } return(episode); }
/// <summary> /// Gets the image for the episode. /// </summary> /// <param name="episode">The episode being parsed.</param> private void GetImage(PodcastEpisode episode) { string imageUrl = GetStringFromChildElementAttribute("itunes:image", "href", NodeToParse); episode.Image = new CachedImage(); if (string.IsNullOrEmpty(imageUrl)) { ParseErrors.Add("No image found"); } else { episode.Image.RemoteUrl = imageUrl; } }
/// <summary> /// Gets the author. /// </summary> /// <param name="episode">The episode being parsed.</param> private void GetAuthor(PodcastEpisode episode) { string author = GetStringFromChildElement("author", NodeToParse); string iTunesAuthor = GetStringFromChildElement("itunes:author", NodeToParse); if (!string.IsNullOrEmpty(author)) { episode.Author = author; } else if (!string.IsNullOrEmpty(iTunesAuthor)) { episode.Author = iTunesAuthor; } else { episode.Author = string.Empty; ParseErrors.Add("No author found"); } }
/// <summary> /// Parses the RSS feed. /// </summary> /// <returns>The <see cref="PodcastChannel"/> instance represented by the RSS data.</returns> public PodcastChannel Parse() { XmlNode channelElement = ((XmlNode)NodeToParse).SelectSingleNode("rss/channel"); if (channelElement == null) { ParseErrors.Add("No rss/channel node found"); SaveParseErrors(_channel); return(_channel); } GetTitle(channelElement); GetLink(channelElement); GetRssUrl(channelElement); GetDescription(channelElement); GetLanguage(channelElement); GetCopyright(channelElement); GetLastBuildDate(channelElement); GetPublishDate(channelElement); GetAuthor(channelElement); GetImage(channelElement); GetCategories(channelElement); GetKeywords(channelElement); GetDocuments(channelElement); GetGenerator(channelElement); GetManagingEditor(channelElement); GetSubtitle(channelElement); _channel.ITunesExplicit = GetBooleanFromChildElement("itunes:explicit", channelElement); XmlNode ownerElement = channelElement.SelectSingleNode("itunes:owner", NamespaceManager); if (ownerElement != null) { _channel.OwnerEmail = GetStringFromChildElement("itunes:email", ownerElement); _channel.OwnerName = GetStringFromChildElement("itunes:name", ownerElement); if (RemoveParsedContent && ownerElement.ChildNodes.Count == 0) { channelElement.RemoveChild(ownerElement); SaveUnparsedContent(); } } if (RemoveParsedContent && channelElement.ChildNodes.Count == 0) { channelElement.ParentNode.RemoveChild(channelElement); SaveUnparsedContent(); } XmlNodeList items = channelElement.SelectNodes("item"); foreach (XmlNode item in items) { PodcastEpisodeParser p = new PodcastEpisodeParser(item, NamespaceManager); p.RemoveParsedContent = RemoveParsedContent; PodcastEpisode episode = p.Parse(); if (episode.Image.LocalPath == CachedImage.DefaultImage) { episode.Image = _channel.Image; } _channel.Episodes.Add(episode); if (RemoveParsedContent) { channelElement.RemoveChild(item); SaveUnparsedContent(); } } SaveParseErrors(_channel); if (RemoveParsedContent) { UnparsedContent.Seek(0, SeekOrigin.Begin); _channel.UnparsedRssData = new StreamReader(UnparsedContent).ReadToEnd(); } return(_channel); }