Example #1
0
        [SetUp] public void SetUp()
        {
            _core    = new TestCore();
            _storage = _core.ResourceStore;

            Props.Register(null);

            _feed   = _storage.NewResource("RSSFeed");
            _parser = new RSSParser(_feed);
        }
Example #2
0
        private void UpdateNews()
        {
            var receivedNews = RSSParser.GetNews("https://dev.by/rss");
            var currentNews  = db.NewsSet.ToList();

            var updatedNews = receivedNews.ExceptBy(currentNews, func => func.Date);

            if (updatedNews.Count() != 0)
            {
                db.NewsSet.AddRange(updatedNews);
                db.SaveChanges();
            }
            ;
        }
Example #3
0
        //private string GetDescription(XElement element)
        //{
        //    if (element == null)
        //    {
        //        return null;
        //    }

        //    string title = element.Value;
        //    if (title == null)
        //    {
        //        return null;
        //    }
        //}

        protected override void OnFill(Parser parser, ICollection <ItemViewModel> collection)
        {
            RSSParser rssParser = parser as RSSParser;

            if (rssParser == null)
            {
                return;
            }

            if (collection == null)
            {
                return;
            }

            //TODO: fill out data
            var items = rssParser.Items;

            if (items != null)
            {
                this._Dispatcher.BeginInvoke(() =>
                {
                    collection.Clear();

                    int index = 0;
                    foreach (var item in items)
                    {
                        if (this._VisibleCount <= index)
                        {
                            break;
                        }

                        string thumbnail   = item.Element(XName.Get("thumbnail", "http://search.yahoo.com/mrss/")).FirstAttribute.Value;
                        string title       = this.GetTitle(item.Element(XName.Get("subtitle", "http://www.itunes.com/dtds/podcast-1.0.dtd")));
                        string description = item.Element(XName.Get("author", "http://www.itunes.com/dtds/podcast-1.0.dtd")).Value;

                        var itemVM = new ItemViewModel()
                        {
                            Thumbnail = thumbnail,
                            LineOne   = title,
                            LineTwo   = string.Format("by {0}", description)
                        };

                        collection.Add(itemVM);

                        ++index;
                    }
                });
            }
        }
Example #4
0
 private void Process(object sender, ElapsedEventArgs e)
 {
     lock (_source)
     {
         System.Console.WriteLine($"Process source: '{_source.Name}'");
         var topics      = RSSParser.GetTopics(_source);
         var savedTopics = 0;
         foreach (var topic in topics)
         {
             if (ModelOperation.SaveTopic(topic, _source))
             {
                 savedTopics++;
             }
         }
         System.Console.WriteLine($"Source '{_source.Name}' are completed. Topics total count: {topics.Count()}. Saved count: {savedTopics}");
     }
 }
Example #5
0
        /// <summary>
        ///		Interpreta un archivo RSS
        /// </summary>
        private AtomChannel ParseRSS(MLFile fileML)
        {
            // Carga el archivo RSS
            try
            {
                RSSChannel rss = new RSSParser().Parse(fileML);

                if (rss != null)
                {
                    // Obtiene el contenido codificado
                    ConvertEntriesRSS(rss);
                    // Convierte el archivo RSS en un archivo Atom
                    return(new RSSToAtom().Convert(rss));
                }
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception.Message);
            }
            // Si ha llegado hasta aquí es porque no ha podido leerlo
            return(null);
        }
Example #6
0
        private void RSSParseDelegate()
        {
            if (_feed.IsDeleted)
            {
                OnParseDone(RSSWorkStatus.FeedDeleted);
                return;
            }

            Stream feedStream = _httpReader.ReadStream;

            _feed.BeginUpdate();
            try
            {
                if (HttpStatus == HttpStatusCode.Moved && _httpReader.RedirectUrl != null)
                {
                    _feed.SetProp(Props.URL, _httpReader.RedirectUrl);
                }

                byte[] streamStartBytes = new byte[256];
                int    cBytes           = feedStream.Read(streamStartBytes, 0, 256);
                string streamStart      = Encoding.Default.GetString(streamStartBytes, 0, cBytes);
                feedStream.Position = 0;

                Encoding encoding = null;
                string   charset  = _httpReader.CharacterSet;
                if (charset != null)
                {
                    try
                    {
                        encoding = Encoding.GetEncoding(charset);
                    }
                    catch (Exception)
                    {
                        Trace.WriteLine("Unknown encoding in HTTP for RSS feed: " + charset);
                        encoding = null;
                    }
                }

                TraceUrlsUnderSpy(_feed, feedStream, encoding);

                RSSParser parser = new RSSParser(_feed);
                try
                {
                    parser.Parse(feedStream, encoding, _parseItems);
                }
                catch (XmlException e)
                {
                    feedStream.Position = 0;
                    if (_acceptHtmlIfXmlError &&
                        ((_httpReader.WebResponse != null && _httpReader.WebResponse.ContentType.StartsWith("text/html")) ||
                         HtmlTools.IsHTML(streamStart)))
                    {
                        OnParseDone(RSSWorkStatus.FoundHTML);
                    }
                    else
                    {
                        _lastException = e;
                        OnParseDone(RSSWorkStatus.XMLError);
                    }
                    return;
                }

                if (parser.FoundChannel)
                {
                    if (_parseItems && _httpReader.ETag != null && _httpReader.ETag.Length > 0)
                    {
                        _feed.SetProp(Props.ETag, _httpReader.ETag);
                    }
                    else
                    {
                        _feed.DeleteProp(Props.ETag);
                    }
                    OnParseDone(RSSWorkStatus.Success);
                }
                else if (HtmlTools.IsHTML(streamStart))
                {
                    OnParseDone(RSSWorkStatus.FoundHTML);
                }
                else
                {
                    OnParseDone(RSSWorkStatus.FoundXML);
                }
            }
            finally
            {
                _feed.EndUpdate();
                if (RSSParser._nextItem != null)
                {
                    RSSParser._nextItem.ClearProperties();
                }
            }
            Core.NetworkAP.QueueJob(_cleanJob);
        }
Example #7
0
 private void SetArgument(string Value)
 {
     parser = new RSSParser(Value);
 }
        public void SerializerShouldSerialize()
        {
            var       rss      = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<rss version=""0.91"">
<channel>
<title>LostFilm.TV</title>
<description>Новинки от LostFilm.TV</description>
<link>https://www.lostfilm.tv/</link>
<lastBuildDate>Thu, 20 Feb 2020 20:07:12 +0000</lastBuildDate>
<language>ru</language><item>
	<title>Блудный сын (Prodigal Son). На пороге смерти(S01E15) [MP4]</title>
	<category>[MP4]</category>
	<pubDate>Thu, 20 Feb 2020 20:07:08 +0000</pubDate>
	<link>http://n.tracktor.site/rssdownloader.php?id=38034</link>
</item>
<item>
	<title>Блудный сын(Prodigal Son). На пороге смерти(S01E15) [1080p]</title>
	<category>[1080p]</category>
	<pubDate>Thu, 20 Feb 2020 20:07:08 +0000</pubDate>
	<link>http://n.tracktor.site/rssdownloader.php?id=38033</link>
</item>
<item>
	<title>Блудный сын(Prodigal Son). На пороге смерти(S01E15) [SD]</title>
	<category>[SD]</category>
	<pubDate>Thu, 20 Feb 2020 20:07:08 +0000</pubDate>
	<link>http://n.tracktor.site/rssdownloader.php?id=38032</link>
</item>
<item>
	<title>Ключи Локков(Locke & Key). Игры разума(S01E03) [MP4]</title>
	<category>[MP4]</category>
	<pubDate>Thu, 20 Feb 2020 18:51:35 +0000</pubDate>
	<link>http://n.tracktor.site/rssdownloader.php?id=38031</link>
</item>
<item>
	<title>Ключи Локков(Locke & Key). Игры разума(S01E03) [1080p]</title>
	<category>[1080p]</category>
	<pubDate>Thu, 20 Feb 2020 18:51:35 +0000</pubDate>
	<link>http://n.tracktor.site/rssdownloader.php?id=38030</link>
</item>
<item>
	<title>Ключи Локков(Locke & Key). Игры разума(S01E03) [SD]</title>
	<category>[SD]</category>
	<pubDate>Thu, 20 Feb 2020 18:51:35 +0000</pubDate>
	<link>http://n.tracktor.site/rssdownloader.php?id=38029</link>
</item>
<item>
	<title>Легенды завтрашнего дня(Legends of Tomorrow). Всему голова(S05E05) [MP4]</title>
	<category>[MP4]</category>
	<pubDate>Thu, 20 Feb 2020 17:37:02 +0000</pubDate>
	<link>http://n.tracktor.site/rssdownloader.php?id=38028</link>
</item>
<item>
	<title>Легенды завтрашнего дня(Legends of Tomorrow). Всему голова(S05E05) [1080p]</title>
	<category>[1080p]</category>
	<pubDate>Thu, 20 Feb 2020 17:37:02 +0000</pubDate>
	<link>http://n.tracktor.site/rssdownloader.php?id=38027</link>
</item>
<item>
	<title>Легенды завтрашнего дня(Legends of Tomorrow). Всему голова(S05E05) [SD]</title>
	<category>[SD]</category>
	<pubDate>Thu, 20 Feb 2020 17:37:02 +0000</pubDate>
	<link>http://n.tracktor.site/rssdownloader.php?id=38026</link>
</item>
<item>
	<title>Флэш(The Flash). Девушка по имени Сью(S06E12) [MP4]</title>
	<category>[MP4]</category>
	<pubDate>Thu, 20 Feb 2020 17:07:46 +0000</pubDate>
	<link>http://n.tracktor.site/rssdownloader.php?id=38025</link>
</item>
<item>
	<title>Флэш(The Flash). Девушка по имени Сью(S06E12) [1080p]</title>
	<category>[1080p]</category>
	<pubDate>Thu, 20 Feb 2020 17:07:46 +0000</pubDate>
	<link>http://n.tracktor.site/rssdownloader.php?id=38024</link>
</item>
<item>
	<title>Флэш(The Flash). Девушка по имени Сью(S06E12) [SD]</title>
	<category>[SD]</category>
	<pubDate>Thu, 20 Feb 2020 17:07:46 +0000</pubDate>
	<link>http://n.tracktor.site/rssdownloader.php?id=38023</link>
</item>
<item>
	<title>Хороший доктор(The Good Doctor). Невысказанное(S03E15) [MP4]</title>
	<category>[MP4]</category>
	<pubDate>Wed, 19 Feb 2020 20:11:00 +0000</pubDate>
	<link>http://n.tracktor.site/rssdownloader.php?id=38022</link>
</item>
<item>
	<title>Хороший доктор(The Good Doctor). Невысказанное(S03E15) [1080p]</title>
	<category>[1080p]</category>
	<pubDate>Wed, 19 Feb 2020 20:11:00 +0000</pubDate>
	<link>http://n.tracktor.site/rssdownloader.php?id=38021</link>
</item>
<item>
	<title>Хороший доктор(The Good Doctor). Невысказанное(S03E15) [SD]</title>
	<category>[SD]</category>
	<pubDate>Wed, 19 Feb 2020 20:11:00 +0000</pubDate>
	<link>http://n.tracktor.site/rssdownloader.php?id=38020</link>
</item>
</channel>
</rss>";
            Exception exThrown = null;

            try
            {
                var doc = RSSParser.Parse(rss);
            }
            catch (Exception ex)
            {
                exThrown = ex;
            }

            Assert.Null(exThrown);
        }
Example #9
0
        /// <summary>
        /// Import cached items, flags, etc.
        /// </summary>
        public void DoImportCache()
        {
            Stream    stream = null;
            RSSParser parser = null;

            // Register our item processor
            _plugin.RegisterItemElementParser(FeedType.Rss, _rbNS, "flag-status", this);
            _plugin.RegisterItemElementParser(FeedType.Atom, _rbNS, "flag-status", this);

            ImportUtils.UpdateProgress(0, _progressMessageCache);
            int totalFeeds     = Math.Max(_importedFeeds.Count, 1);
            int processedFeeds = 0;

            // Ok, all feeds are created. Try to import all caches and mark read items
            _parseCache = true;
            foreach (FeedInfo fi in _importedFeeds)
            {
                ImportUtils.UpdateProgress(processedFeeds / totalFeeds, _progressMessageCache);
                processedFeeds += 100;
                if (fi.feed.IsDeleted)
                {
                    continue;
                }
                if (null == fi.cacheFile)
                {
                    continue;
                }

                string path = Path.Combine(_cachePath, fi.cacheFile);
                if (!File.Exists(path))
                {
                    continue;
                }
                try
                {
                    // Load feed!
                    parser = new RSSParser(fi.feed);
                    using (stream = new FileStream(path, FileMode.Open, FileAccess.Read))
                    {
                        parser.Parse(stream, Encoding.UTF8, true);
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("RSS Bandit cache '" + path + "' load failed: '" + ex.Message + "'");
                }

                if (fi.readItems != null)
                {
                    // And mark as read
                    IResourceList allItems = fi.feed.GetLinksTo("RSSItem", "From");
                    foreach (string readOne in fi.readItems)
                    {
                        IResourceList markAsRead = Core.ResourceStore.FindResources("RSSItem", "GUID", readOne).Intersect(allItems, true);
                        foreach (IResource item in markAsRead)
                        {
                            item.DeleteProp(Core.Props.IsUnread);
                        }
                    }
                }
            }
            ImportUtils.UpdateProgress(processedFeeds / totalFeeds, _progressMessageCache);

            // And here we should import flags from flags stream
            if (_flaggedPath == null)
            {
                return;
            }

            // Register two additional elements
            _plugin.RegisterItemElementParser(FeedType.Rss, _rbNS, "feed-url", this);
            _plugin.RegisterItemElementParser(FeedType.Atom, _rbNS, "feed-url", this);
            _parseCache = false;

            IResource pseudoFeed = Core.ResourceStore.NewResourceTransient("RSSFeed");

            try
            {
                parser             = new RSSParser(pseudoFeed);
                parser.ItemParsed += this.FlaggedItemParsed;
                using (stream = new FileStream(_flaggedPath, FileMode.Open, FileAccess.Read))
                {
                    parser.Parse(stream, Encoding.UTF8, true);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("RssBandit flags load failed: '" + ex.Message + "'");
            }
            pseudoFeed.Delete();
        }
Example #10
0
 internal RSSFeedActionProvider(RSSParser rssParser) => this.rssParser = rssParser;
Example #11
0
        /// <summary>
        /// Import cached items, flags, etc.
        /// </summary>
        public void DoImportCache()
        {
            RSSPlugin plugin = RSSPlugin.GetInstance();

            _readItems = new ArrayList();
            // Register us for special tags
            plugin.RegisterItemElementParser(FeedType.Rss, _fdNS, "state", this);
            plugin.RegisterItemElementParser(FeedType.Atom, _fdNS, "state", this);

            string[] allFiles = Directory.GetFiles(_channelsPath, "*.rss");

            int totalFiles     = Math.Max(allFiles.Length, 1);
            int processedFiles = 0;

            foreach (string file in allFiles)
            {
                ImportUtils.UpdateProgress(processedFiles / totalFiles, _progressMessageCache);
                processedFiles += 100;

                IResource feed = null;
                string    name = HtmlTools.SafeHtmlDecode(Path.GetFileNameWithoutExtension(file));
                if (_name2url.ContainsKey(name))
                {
                    IResourceList feeds = Core.ResourceStore.FindResources("RSSFeed", Props.URL, _name2url[name]);
                    if (feeds.Count > 0)
                    {
                        feed = feeds[0];
                    }
                }
                if (feed == null)
                {
                    IResourceList feeds = Core.ResourceStore.FindResources("RSSFeed", Core.Props.Name, name);
                    if (feeds.Count > 0)
                    {
                        feed = feeds[0];
                    }
                }
                // Not found (import of this feed was canceled?)
                if (feed == null)
                {
                    continue;
                }
                _readItems.Clear();
                using (Stream rss = new FileStream(file, FileMode.Open))
                {
                    try
                    {
                        RSSParser parser = new RSSParser(feed);
                        parser.Parse(rss, Encoding.UTF8, true);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine("FeedDemon cache '" + file + "' load failed: '" + ex.Message + "'");
                    }
                }
                foreach (IResource r in _readItems)
                {
                    if (!r.IsDeleted)
                    {
                        r.DeleteProp(Core.Props.IsUnread);
                    }
                }
            }
            ImportUtils.UpdateProgress(processedFiles / totalFiles, _progressMessageCache);
        }