コード例 #1
0
ファイル: ParserPodcastRaw.cs プロジェクト: Keldrik/PodSharp
        private void ParsePodcastMeta(XElement e, PodcastRaw podcastRaw)
        {
            switch (e.Name.ToString().ToLower())
            {
                case "title":
                    podcastRaw.Title = e.Value;
                    break;

                case "link":
                    podcastRaw.LinkWebsiteURL = e.Value;
                    break;

                case "language":
                    podcastRaw.Language = e.Value;
                    break;

                case "description":
                    podcastRaw.Description = e.Value;
                    break;

                case "category":
                    podcastRaw.Category = e.Value;
                    break;

                case "pubdate":
                    podcastRaw.PubDate = e.Value;
                    break;

                case "lastbuilddate":
                    podcastRaw.LastBuildDate = e.Value;
                    break;

                case "image":
                    if (e.HasElements)
                    {
                        XElement x = e.Elements("url").FirstOrDefault();
                        if (x != null && !x.IsEmpty)
                        {
                            podcastRaw.ImageURL = x.Value;
                        }
                    }
                    break;

                case "copyright":
                    podcastRaw.Copyright = e.Value;
                    break;

                case "webmaster":
                    podcastRaw.Webmaster = e.Value;
                    break;

                case "managingeditor":
                    podcastRaw.ManagingEditor = e.Value;
                    break;

                case "generator":
                    podcastRaw.FeedGenerator = e.Value;
                    break;
            }
        }
コード例 #2
0
ファイル: FeedReader.cs プロジェクト: Keldrik/PodSharp
 private async Task<List<EpisodeRaw>> MultipageEpisodeListAsync(PodcastRaw praw)
 {
     List<EpisodeRaw> episodes = new List<EpisodeRaw>();
     string next = praw.LinkFeedNextPageURL;
     while (!string.IsNullOrEmpty(next))
     {
         PodcastRaw p = await GetPodcastRawAsync(next);
         episodes.AddRange(p.Episodes);
         next = p.LinkFeedNextPageURL;
     }
     return episodes;
 }
コード例 #3
0
ファイル: ParserPodcastRaw.cs プロジェクト: Keldrik/PodSharp
        public PodcastRaw ParseNewPodcast(XElement channel)
        {
            PodcastRaw podcastRaw = new PodcastRaw();

            foreach (var e in channel.Elements())
            {
                ParsePodcastMeta(e, podcastRaw);
                ParsePodcastMetaAtom(e, podcastRaw);
                ParsePodcastMetaItunes(e, podcastRaw);
            }

            return podcastRaw;
        }
コード例 #4
0
ファイル: FeedReader.cs プロジェクト: Keldrik/PodSharp
        public async Task<PodcastRaw> GetPodcastRawAsync(string url)
        {
            PodcastRaw podcast = new PodcastRaw();
            podcast.LinkFeedURL = url.ToLower();
            ParserPodcastRaw pparse = new ParserPodcastRaw();
            ParserEpisodeRaw eparse = new ParserEpisodeRaw();

            XElement root = await LoadWebFeedAsync(url);

            var channel = root.Descendants("channel").FirstOrDefault();
            podcast = pparse.ParseNewPodcast(channel);

            var items = root.Descendants("item");
            podcast.Episodes = eparse.ParseNewEpisodeRawList(items);

            return podcast;
        }
コード例 #5
0
ファイル: ParserPodcast.cs プロジェクト: Keldrik/PodSharp
        public Podcast ParsePodcast(PodcastRaw praw)
        {
            Podcast podcast = new Podcast();

            podcast.Title = praw.Title;
            podcast.Author = praw.ItunesAuthor;

            if (!string.IsNullOrEmpty(praw.LinkWebsiteURL))
            {
                podcast.WebsiteURL = praw.LinkWebsiteURL.ToLower();
            }

            if (!string.IsNullOrEmpty(praw.ItunesImageURL))
            {
                podcast.ImageURL = praw.ItunesImageURL.ToLower();
                podcast.ImageURI = new Uri(podcast.ImageURL);
            }
            else
            {
                if (!string.IsNullOrEmpty(praw.ImageURL))
                {
                    podcast.ImageURL = praw.ImageURL.ToLower();
                    podcast.ImageURI = new Uri(podcast.ImageURL);
                }
            }

            podcast.Language = praw.Language;
            podcast.Copyright = praw.Copyright;

            DateTime lastbuilddate;
            if (DateTime.TryParse(praw.PubDate, out lastbuilddate))
            {
                podcast.LastBuild = lastbuilddate;
            }
            else
            {
                podcast.LastBuild = DateTime.Now;
            }

            podcast.FeedAlt = praw.LinkAlternateFeeds;
            if (podcast.HasFeedAlt)
            {
                foreach (var f in podcast.FeedAlt)
                {
                    f.URL = f.URL.ToLower();
                }
            }

            podcast.Subtitle = praw.ItunesSubtitle;
            podcast.Summary = praw.ItunesSummary;
            podcast.Description = praw.Description;
            podcast.Keywords = praw.ItunesKeywords;
            podcast.Categorys = praw.ItunesCategorys;

            podcast.Contributors = praw.Contributors;
            if (podcast.HasContributors)
            {
                foreach (var c in podcast.Contributors)
                {
                    if (!string.IsNullOrEmpty(c.URI))
                    {
                        c.URI = c.URI.ToLower();
                    }
                }
            }

            podcast.PaymentLinks = praw.LinkPayments;
            if (podcast.HasPaymentLinks)
            {
                foreach (var p in podcast.PaymentLinks)
                {
                    p.URL = p.URL.ToLower();
                }
            }

            return podcast;
        }
コード例 #6
0
ファイル: ParserPodcastRaw.cs プロジェクト: Keldrik/PodSharp
        private void ParsePodcastMetaAtom(XElement e, PodcastRaw podcastRaw)
        {
            if (e.Name.ToString().ToLower() == "{" + FeedNamespaceCollection.atom + "}link" && e.HasAttributes && e.Attribute("rel") != null)
            {
                switch (e.Attribute("rel").Value)
                {
                    case "alternate":
                        if (podcastRaw.LinkAlternateFeeds == null)
                        {
                            podcastRaw.LinkAlternateFeeds = new List<AlternateFeed>();
                        }
                        podcastRaw.LinkAlternateFeeds.Add(new AlternateFeed() { Title = e.Attribute("title").Value, URL = e.Attribute("href").Value });
                        break;

                    case "next":
                        podcastRaw.LinkFeedNextPageURL = e.Attribute("href").Value;
                        break;

                    case "first":
                        podcastRaw.LinkFeedFirstPageURL = e.Attribute("href").Value;
                        break;

                    case "last":
                        podcastRaw.LinkFeedLastPageURL = e.Attribute("href").Value;
                        break;

                    case "payment":
                        if (e.HasAttributes && e.Attribute("href") != null && e.Attribute("title") != null)
                        {
                            if (podcastRaw.LinkPayments == null)
                            {
                                podcastRaw.LinkPayments = new List<Payment>();
                            }
                            podcastRaw.LinkPayments.Add(new Payment() { URL = e.Attribute("href").Value, Title = e.Attribute("title").Value });
                        }
                        break;
                }
            }
            if (e.Name.ToString().ToLower() == "{" + FeedNamespaceCollection.atom + "}contributor" && e.HasElements)
            {
                Contributor c = new Contributor();
                foreach (var i in e.Elements())
                {
                    if (i.Name.ToString().ToLower() == "{" + FeedNamespaceCollection.atom + "}name")
                    {
                        c.Name = i.Value;
                    }
                    if (i.Name.ToString().ToLower() == "{" + FeedNamespaceCollection.atom + "}uri")
                    {
                        c.URI = i.Value;
                    }
                }
                if (c.Name != null && c.Name != "")
                {
                    if (podcastRaw.Contributors == null)
                    {
                        podcastRaw.Contributors = new List<Contributor>();
                    }
                    podcastRaw.Contributors.Add(c);
                }
            }
        }
コード例 #7
0
ファイル: ParserPodcastRaw.cs プロジェクト: Keldrik/PodSharp
        private void ParsePodcastMetaItunes(XElement e, PodcastRaw podcastRaw)
        {
            switch (e.Name.ToString().ToLower())
            {
                case "{" + FeedNamespaceCollection.itunes + "}subtitle":
                    podcastRaw.ItunesSubtitle = e.Value;
                    break;

                case "{" + FeedNamespaceCollection.itunes + "}author":
                    podcastRaw.ItunesAuthor = e.Value;
                    break;

                case "{" + FeedNamespaceCollection.itunes + "}summary":
                    podcastRaw.ItunesSummary = e.Value;
                    break;

                case "{" + FeedNamespaceCollection.itunes + "}keywords":
                    if (e.Value != "")
                    {
                        if (podcastRaw.ItunesKeywords == null)
                        {
                            podcastRaw.ItunesKeywords = new List<string>();
                        }
                        string k = e.Value;
                        string[] kk = k.Split(',');
                        foreach (var kkk in kk)
                        {
                            podcastRaw.ItunesKeywords.Add(kkk.Trim().ToLower());
                        }
                    }
                    break;

                case "{" + FeedNamespaceCollection.itunes + "}category":
                    if (e.HasAttributes && e.Attribute("text") != null && e.Attribute("text").Value != "")
                    {
                        ItunesCategory c = new ItunesCategory();
                        c.Name = e.Attribute("text").Value;
                        if (e.HasElements)
                        {
                            c.SubCategorys = new List<string>();
                            foreach (var cc in e.Elements())
                            {
                                if (cc.HasAttributes && cc.Attribute("text") != null && cc.Attribute("text").Value != "")
                                {
                                    c.SubCategorys.Add(cc.Attribute("text").Value);
                                }
                            }
                        }
                        if (podcastRaw.ItunesCategorys == null)
                        {
                            podcastRaw.ItunesCategorys = new List<ItunesCategory>();
                        }
                        podcastRaw.ItunesCategorys.Add(c);
                    }
                    break;

                case "{" + FeedNamespaceCollection.itunes + "}owner":
                    if (e.HasElements)
                    {
                        ItunesOwner io = new ItunesOwner();
                        foreach (var o in e.Elements())
                        {
                            if (o.Name.ToString().ToLower() == "{" + FeedNamespaceCollection.itunes + "}name")
                            {
                                io.Name = o.Value;
                            }
                            if (o.Name.ToString().ToLower() == "{" + FeedNamespaceCollection.itunes + "}email")
                            {
                                io.EMail = o.Value;
                            }
                        }
                        if (io.Name != null && io.Name != "")
                        {
                            podcastRaw.ItunesOwner = io;
                        }
                    }
                    break;

                case "{" + FeedNamespaceCollection.itunes + "}image":
                    if (e.HasAttributes && e.Attribute("href") != null && e.Attribute("href").Value != "")
                    {
                        podcastRaw.ItunesImageURL = e.Attribute("href").Value;
                    }
                    break;
            }
        }