예제 #1
0
        public async Task <IEnumerable <FeedItem> > UpdateFeedAsync(Feed feed)
        {
            var list = new List <FeedItem>();

            switch (feed.FeedType)
            {
            case FeedType.Rss:
                var rss = RssFeed.Create(new Uri(feed.Address));
                foreach (var item in rss.Channel.Items)
                {
                    list.Add(new FeedItem(item));
                }
                break;

            case FeedType.Atom:
                var atom = AtomFeed.Create(new Uri(feed.Address));
                foreach (var entry in atom.Entries)
                {
                    list.Add(new FeedItem(entry));
                }
                break;

            default:
                var unknown = GenericSyndicationFeed.Create(new Uri(feed.Address));
                foreach (var item in unknown.Items)
                {
                    list.Add(new FeedItem(item));
                }
                break;
            }

            return(list);
        }
예제 #2
0
        /// <summary>
        /// Provides example code for the FeedHistorySyndicationExtension class.
        /// </summary>
        public static void ClassExample()
        {
            // Framework auto-discovers supported extensions based on XML namespace attributes (xmlns) defined on root of resource
            RssFeed feed = RssFeed.Create(new Uri("http://www.example.com/feed.aspx?format=rss"));

            // Extensible framework entities provide properties/methods to determine if entity is extended and predicate based seaching against available extensions
            if (feed.Channel.HasExtensions)
            {
                FeedHistorySyndicationExtension channelExtension = feed.Channel.FindExtension(FeedHistorySyndicationExtension.MatchByType) as FeedHistorySyndicationExtension;
                if (channelExtension != null)
                {
                    // Process channel extension
                }
            }

            foreach (RssItem item in feed.Channel.Items)
            {
                if (item.HasExtensions)
                {
                    FeedHistorySyndicationExtension itemExtension = item.FindExtension(FeedHistorySyndicationExtension.MatchByType) as FeedHistorySyndicationExtension;
                    if (itemExtension != null)
                    {
                        // Process extension for current item
                    }
                }
            }

            // By default the framework will automatically determine what XML namespace attributes (xmlns) to write
            // on the root of the resource based on the extensions applied to extensible parent and child entities
            using (FileStream stream = new FileStream("Feed.xml", FileMode.Create, FileAccess.Write))
            {
                feed.Save(stream);
            }
        }
예제 #3
0
        /// <summary>
        /// Provides example code for the RssFeed.Create(Uri) method
        /// </summary>
        public static void CreateExample()
        {
            RssFeed feed = RssFeed.Create(new Uri("http://news.google.com/?output=rss"));

            foreach (RssItem item in feed.Channel.Items)
            {
                if (item.PublicationDate >= DateTime.Today.Subtract(new TimeSpan(7, 0, 0, 0)))
                {
                    //  Process channel items published in the last week
                }
            }
        }
예제 #4
0
        public Feed GetFeed(Feed feed)
        {
            switch (feed.FeedType)
            {
            case FeedType.Rss:
                var rss = RssFeed.Create(new Uri(feed.Address));
                return(new Feed(rss));

            case FeedType.Atom:
                var atom = AtomFeed.Create(new Uri(feed.Address));
                return(new Feed(atom));

            default:
                var unknown = GenericSyndicationFeed.Create(new Uri(feed.Address));
                return(new Feed(unknown));
            }
        }
예제 #5
0
 static void Main(string[] args)
 {
     try
     {
         RssFeed feed   = RssFeed.Create(new Uri("http://kat.ph/movies/?rss=1"));
         var     nItems = feed.Channel.Items.Count();
         foreach (RssItem item in feed.Channel.Items)
         {
             Console.WriteLine("{0} {1}", item.Title, item.Description);
         }
         Console.ReadLine();
     }
     catch (Exception ex)
     {
         throw;
     }
 }
        /// <summary>
        /// Provides example code for the SyndicationDiscoveryUtility.LocateDiscoverableSyndicationEndpoints(Uri) method
        /// </summary>
        public static void LocateDiscoverableSyndicationEndpointsExample()
        {
            Uri source = new Uri("http://www.dotnetrocks.com/");
            Collection <DiscoverableSyndicationEndpoint> endpoints;

            endpoints = SyndicationDiscoveryUtility.LocateDiscoverableSyndicationEndpoints(source);

            foreach (DiscoverableSyndicationEndpoint endpoint in endpoints)
            {
                if (endpoint.ContentFormat == SyndicationContentFormat.Rss)
                {
                    RssFeed feed = RssFeed.Create(endpoint.Source);
                    if (feed.Channel.HasExtensions)
                    {
                        // Process feed extensions
                    }
                }
            }
        }
예제 #7
0
파일: Opml.cs 프로젝트: johno4321/Podcaster
        public static IEnumerable <TitleAndUrl> BuildTitleAndUrls(Opml opml)
        {
            var titleAndUrls = new List <TitleAndUrl>();

            foreach (var opmlOutline in opml.Outlines)
            {
                var titleAndUrl = new TitleAndUrl();
                titleAndUrls.Add(titleAndUrl);

                titleAndUrl.Podcasts = new List <Podcast>();

                if (opmlOutline.Attributes.ContainsKey(TitleAttribute))
                {
                    titleAndUrl.Title = opmlOutline.Attributes[TitleAttribute];
                }

                if (!opmlOutline.Attributes.ContainsKey(XmlUrlAttribute))
                {
                    continue;
                }

                titleAndUrl.Url = new Uri(opmlOutline.Attributes[XmlUrlAttribute]);

                if (titleAndUrl.Title != null)
                {
                    continue;
                }

                var settings = new SyndicationResourceLoadSettings();
                var feed     = RssFeed.Create(titleAndUrl.Url, settings);

                foreach (var item in feed.Channel.Items)
                {
                    var podcast = new Podcast();
                    podcast.Title = item.Title;
                    podcast.Url   = item.Link;
                    titleAndUrl.Podcasts.Add(podcast);
                }
            }

            return(titleAndUrls);
        }
예제 #8
0
        private void LoadListView()
        {
            var feed = RssFeed.Create(new Uri(@"http://alt.rutor.info/rss.php?full=8"));

            foreach (RssItem post in feed.Channel.Items)
            {
                var doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(post.Description);
                var imageUrl = doc.DocumentNode.SelectNodes("//img").First().Attributes["src"].Value;

                var image = LoadImage(imageUrl);
                //image = ResizeImage(image, 64, 64, true);

                _images.Images.Add(post.Link.AbsoluteUri, image);
                var item = new ListViewItem(post.Title)
                {
                    Tag      = post,
                    ImageKey = post.Link.AbsoluteUri
                };
                listView1.Items.Add(item);
            }
        }
예제 #9
0
        private void RetrieveItems(int feedId)
        {
            using (var context = DataContext)
            {
                var item = context.Feeds.FirstOrDefault(m => m.Id == feedId);
                var feed = RssFeed.Create(new Uri(item.RssUrl));

                foreach (var feedItem in feed.Channel.Items.Where(m => m.PublicationDate > item.LastRetrievedOn))
                {
                    var newItem = new Item()
                    {
                        FeedId          = feedId,
                        Description     = feedItem.Description,
                        Author          = feedItem.Author,
                        Categories      = string.Join(";", feedItem.Categories.Select(m => m.Value).ToArray <string>()),
                        Comments        = feedItem.Comments.ToString(),
                        GuidValue       = feedItem.Guid.Value,
                        Link            = feedItem.Link.ToString(),
                        PublicationDate = feedItem.PublicationDate,
                        SourceTitle     = feedItem.Source.Title,
                        SourceUrl       = feedItem.Source.Url.ToString(),
                        Title           = feedItem.Title
                    };
                    context.Items.Add(newItem);
                }

                item.Title           = feed.Channel.Title;
                item.Format          = feed.Format.ToString();
                item.Version         = feed.Version.ToString();
                item.Webmaster       = feed.Channel.Webmaster;
                item.Description     = feed.Channel.Description;
                item.Copyright       = feed.Channel.Copyright;
                item.LastRetrievedOn = DateTime.Now;

                context.SaveChanges();
            }
        }
예제 #10
0
 private void GetRss()
 {
     try
     {
         var ccDal = new DataAccess.Data();
         var feeds = ccDal.GetActiveFeeds();
         foreach (var feedrow in feeds)
         {
             if (!feedrow.FeedActive)
             {
                 continue;
             }
             var feed = RssFeed.Create(new Uri(feedrow.FeedRssLink));
             if (feed.Channel.HasExtensions)
             {
                 feed.Channel.FindExtension(DublinCoreElementSetSyndicationExtension.MatchByType);
             }
             foreach (var item in feed.Channel.Items)
             {
                 if (item.HasExtensions)
                 {
                     var dcExt = item.FindExtension(DublinCoreElementSetSyndicationExtension.MatchByType) as
                                 DublinCoreElementSetSyndicationExtension;
                     if (dcExt != null)
                     {
                         ccDal.InsertRawData(dcExt.Context.Date.ToLocalTime(), item.Link.AbsoluteUri, WebUtility.HtmlDecode(item.Title), WebUtility.HtmlDecode(item.Description), feedrow.Id);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message);
     }
 }
예제 #11
0
        private static IEnumerable <ItemDownload> ProcurarEpisodiosNosFeeds()
        {
            var lstEpisodiosParaBaixar = new List <ItemDownload>();

            var feedsService             = App.Container.Resolve <FeedsService>();
            var qualidadeDownloadService = App.Container.Resolve <QualidadeDownloadService>();
            IEnumerable <Feed> lstFeeds  = feedsService.GetLista()
                                           .Where(x => !x.bIsFeedPesquisa &&
                                                  (x.nIdTipoConteudo == Enums.TipoConteudo.Série || x.nIdTipoConteudo == Enums.TipoConteudo.Anime))
                                           .OrderBy(x => x.nNrPrioridade);
            IEnumerable <QualidadeDownload> lstQualidadeDownloads = qualidadeDownloadService.GetLista().OrderBy(x => x.nPrioridade);
            var rgxQualidade = new Regex($".*?({string.Join("|", lstQualidadeDownloads.Select(x => x.sIdentificadoresQualidade))})");

            foreach (Feed item in lstFeeds)
            {
                RssFeed rss;

                try
                {
                    rss = RssFeed.Create(new Uri(item.sLkFeed));
                }
                catch (Exception ex)
                {
                    new MediaManagerException(ex).TratarException(string.Format(Mensagens.Ocorreu_um_erro_ao_abrir_o_feed_0_URL_1_, item.sDsFeed, item.sLkFeed));
                    continue;
                }

                foreach (RssItem objRssItem in rss.Channel.Items)
                {
                    try
                    {
                        var episodio = new Episodio {
                            sDsFilepath = objRssItem.Title
                        };
                        string extensao = Path.GetExtension(Helper.RetirarCaracteresInvalidos(objRssItem.Title));

                        if (!episodio.IdentificarEpisodio() ||
                            episodio.nIdTipoConteudo != item.nIdTipoConteudo ||
                            episodio.nIdEstadoEpisodio != Enums.EstadoEpisodio.Desejado ||
                            episodio.oSerie.bIsParado ||
                            (!string.IsNullOrWhiteSpace(extensao) && !Settings.Default.ExtensoesRenomeioPermitidas.Contains(extensao)))
                        {
                            continue;
                        }

                        string strIdentificador = rgxQualidade.Match(objRssItem.Title).Groups[1].Value;

                        // Verifica se é vazio/null para atribuir a qualidade "Desconhecido".
                        QualidadeDownload objQualidadeDownload = !string.IsNullOrWhiteSpace(strIdentificador)
                                                                     ? lstQualidadeDownloads.FirstOrDefault(x => x.sIdentificadoresQualidade.Split('|').Any(y => y == strIdentificador))
                                                                     : lstQualidadeDownloads.First(x => x.nCdQualidadeDownload == 1);

                        if (lstEpisodiosParaBaixar.Any(x => x.ObjEpisodio.nCdEpisodioAPI == episodio.nCdEpisodioAPI))
                        {
                            lstEpisodiosParaBaixar.First(x => x.ObjEpisodio.nCdEpisodioAPI == episodio.nCdEpisodioAPI).LstObjRssItem.Add(objRssItem, objQualidadeDownload);
                        }
                        else
                        {
                            lstEpisodiosParaBaixar.Add(new ItemDownload {
                                ObjEpisodio = episodio, LstObjRssItem = new Dictionary <RssItem, QualidadeDownload> {
                                    { objRssItem, objQualidadeDownload }
                                }
                            });
                        }
                    }
                    catch (Exception e)
                    {
                        new MediaManagerException(e).TratarException(string.Format(Mensagens.Ocorreu_um_erro_ao_procurar_o_item_0_do_feed_RSS_1_, objRssItem.Title, item.sDsFeed));
                    }
                }
            }

            return(lstEpisodiosParaBaixar);
        }