private void ParseEpisodeMetaPSC(XElement e, EpisodeRaw episode) { switch (e.Name.ToString().ToLower()) { case "{" + FeedNamespaceCollection.psc + "}chapters": if (e.HasElements) { episode.PSCChapters = new List <Chapter>(); foreach (var ee in e.Elements()) { if (ee.HasAttributes && ee.Attribute("start") != null && ee.Attribute("start").Value != "" && ee.Attribute("title") != null && ee.Attribute("title").Value != "") { TimeSpan start; if (TimeSpan.TryParse(ee.Attribute("start").Value.ToString(), out start)) { episode.PSCChapters.Add(new Chapter() { StartTime = start, Title = ee.Attribute("title").Value }); } } } } break; } }
private void ParseEpisodeMetaMedia(XElement e, EpisodeRaw episode) { switch (e.Name.ToString().ToLower()) { case "{" + FeedNamespaceCollection.media + "}category": if (!e.IsEmpty) { if (episode.MediaCategorys == null) { episode.MediaCategorys = new List <string>(); } episode.MediaCategorys.Add(e.Value); } break; case "{" + FeedNamespaceCollection.media + "}credit": if (!e.IsEmpty) { if (episode.MediaCredits == null) { episode.MediaCredits = new List <MediaCredit>(); } MediaCredit c = new MediaCredit(); c.Name = e.Value; if (e.HasAttributes && e.Attribute("role") != null) { c.Role = e.Attribute("role").Value; } episode.MediaCredits.Add(c); } break; } }
private void ParseEpisodeMetaItunes(XElement e, EpisodeRaw episode) { switch (e.Name.ToString().ToLower()) { case "{" + FeedNamespaceCollection.itunes + "}subtitle": episode.ItunesSubtitle = e.Value; break; case "{" + FeedNamespaceCollection.itunes + "}author": episode.ItunesAuthor = e.Value; break; case "{" + FeedNamespaceCollection.itunes + "}summary": episode.ItunesSummary = e.Value; break; case "{" + FeedNamespaceCollection.itunes + "}duration": episode.ItunesDuration = e.Value; break; case "{" + FeedNamespaceCollection.itunes + "}keywords": if (!e.IsEmpty) { if (episode.ItunesKeywords == null) { episode.ItunesKeywords = new List <string>(); } string k = e.Value; string[] kk = k.Split(','); foreach (var kkk in kk) { if (!string.IsNullOrEmpty(kkk)) { episode.ItunesKeywords.Add(kkk.Trim().ToLower()); } } } break; case "payment": if (e.HasAttributes && e.Attribute("href") != null && e.Attribute("title") != null) { if (episode.LinkPayments == null) { episode.LinkPayments = new List <Payment>(); } episode.LinkPayments.Add(new Payment() { URL = e.Attribute("href").Value, Title = e.Attribute("title").Value }); } break; } }
public MediaItem ParseMediaItem(EpisodeRaw eraw) { MediaItem item = new MediaItem(); item.URL = eraw.MediaItemURL.ToLower(); TimeSpan duration; if (!string.IsNullOrEmpty(eraw.ItunesDuration) && TimeSpan.TryParse(eraw.ItunesDuration, out duration)) { item.Duration = duration; } else { item.Duration = TimeSpan.Zero; } long filesize; if (!string.IsNullOrEmpty(eraw.MediaItemLength) && long.TryParse(eraw.MediaItemLength, out filesize)) { item.FileSize = filesize; } else { item.FileSize = 0; } if (!string.IsNullOrEmpty(eraw.MediaItemType)) { string[] mtsa = eraw.MediaItemType.Split('/'); string mts = mtsa.FirstOrDefault().Trim().ToLower(); MediaFileType mt; switch (mts) { case "audio": mt = MediaFileType.audio; break; case "video": mt = MediaFileType.video; break; default: mt = MediaFileType.unknown; break; } item.FileType = mt; } return(item); }
private void ParseEpisodeMeta(XElement e, EpisodeRaw episode) { switch (e.Name.ToString().ToLower()) { case "title": episode.Title = e.Value; break; case "link": episode.LinkWebsiteURL = e.Value; break; case "description": episode.Description = e.Value; break; case "pubdate": episode.PubDate = e.Value; break; case "guid": episode.guid = e.Value; break; case "comments": episode.LinkCommentsURL = e.Value; break; case "{" + FeedNamespaceCollection.content + "}encoded": episode.ContentEncoded = e.Value; break; case "enclosure": if (e.HasAttributes) { if (e.Attribute("url") != null && e.Attribute("url").Value != "") { episode.MediaItemURL = e.Attribute("url").Value; } if (e.Attribute("length") != null && e.Attribute("length").Value != "") { episode.MediaItemLength = e.Attribute("length").Value; } if (e.Attribute("type") != null && e.Attribute("type").Value != "") { episode.MediaItemType = e.Attribute("type").Value; } } break; } }
public EpisodeRaw ParseNewEpisodeRaw(XElement e) { EpisodeRaw episode = new EpisodeRaw(); foreach (var ee in e.Elements()) { ParseEpisodeMeta(ee, episode); ParseEpisodeMetaItunes(ee, episode); ParseEpisodeMetaExtra(ee, episode); ParseEpisodeMetaMedia(ee, episode); ParseEpisodeMetaPSC(ee, episode); } return(episode); }
private void ParseEpisodeMetaExtra(XElement e, EpisodeRaw episode) { switch (e.Name.ToString().ToLower()) { case "{" + FeedNamespaceCollection.wfw + "}commentrss": episode.WFWCommentFeed = e.Value; break; case "{" + FeedNamespaceCollection.slash + "}comments": episode.SlashComments = e.Value; break; case "{" + FeedNamespaceCollection.dc + "}creator": episode.DCCreator = e.Value; break; case "{" + FeedNamespaceCollection.atom + "}contributor": if (e.HasElements) { Contributor c = new Contributor(); foreach (var ee in e.Elements()) { if (ee.Name.ToString().ToLower() == "{" + FeedNamespaceCollection.atom + "}name" && !ee.IsEmpty) { c.Name = ee.Value; } if (ee.Name.ToString().ToLower() == "{" + FeedNamespaceCollection.atom + "}uri" && !ee.IsEmpty) { c.URI = ee.Value; } } if (c.Name != null && c.Name != "") { if (episode.Contributors == null) { episode.Contributors = new List <Contributor>(); } episode.Contributors.Add(c); } } break; } }
public Episode ParseEpisode(EpisodeRaw eraw) { Episode episode = new Episode(); episode.Title = eraw.Title; episode.GUID = eraw.guid; if (!string.IsNullOrEmpty(eraw.LinkWebsiteURL)) { episode.WebsiteURL = eraw.LinkWebsiteURL.ToLower(); } DateTime pubdate; if (DateTime.TryParse(eraw.PubDate, out pubdate)) { episode.PubDate = pubdate; } else { episode.PubDate = DateTime.Now; } if (!string.IsNullOrEmpty(eraw.Description)) { episode.Description = eraw.Description; if (PodHelper.CheckTextForHtmlEncode(episode.Description)) { episode.Description = System.Net.WebUtility.HtmlDecode(episode.Description); } episode.DescriptionContainsMarkup = PodHelper.CheckTextForMarkup(episode.Description); } if (!string.IsNullOrEmpty(eraw.ContentEncoded)) { episode.Content = eraw.ContentEncoded; if (PodHelper.CheckTextForHtmlEncode(episode.Content)) { episode.Content = System.Net.WebUtility.HtmlDecode(episode.Content); } episode.ContentContainsMarkup = PodHelper.CheckTextForMarkup(episode.Content); } if (!string.IsNullOrEmpty(eraw.ItunesSubtitle)) { episode.Subtitle = eraw.ItunesSubtitle; if (PodHelper.CheckTextForHtmlEncode(episode.Subtitle)) { episode.Subtitle = System.Net.WebUtility.HtmlDecode(episode.Subtitle); } } if (!string.IsNullOrEmpty(eraw.ItunesSummary)) { episode.Summary = eraw.ItunesSummary; if (PodHelper.CheckTextForHtmlEncode(episode.Summary)) { episode.Summary = System.Net.WebUtility.HtmlDecode(episode.Summary); } } episode.Keywords = eraw.ItunesKeywords; episode.Contributors = eraw.Contributors; if (eraw.MediaCredits != null && eraw.MediaCredits.Count > 0) { if (episode.Contributors == null) { episode.Contributors = new List <Contributor>(); } foreach (var mc in eraw.MediaCredits) { episode.Contributors.Add(new Contributor() { Name = mc.Name }); } } if (episode.HasContributors) { foreach (var c in episode.Contributors) { if (!string.IsNullOrEmpty(c.URI)) { c.URI = c.URI.ToLower(); } } } episode.Chapters = eraw.PSCChapters; episode.PaymentLinks = eraw.LinkPayments; if (episode.HasPaymentLinks) { foreach (var p in episode.PaymentLinks) { p.URL = p.URL.ToLower(); } } if (!string.IsNullOrEmpty(eraw.MediaItemURL)) { episode.MediaContent = ParseMediaItem(eraw); } return(episode); }