Exemplo n.º 1
0
 public RSSChannel(string url, Regex Transform, string BaseDownload)
 {
     _itemList   = new RSSItemList();
     _url        = url;
     _transform  = Transform;
     _basedllink = BaseDownload;
 }
Exemplo n.º 2
0
 public RSSChannel(string url)
 {
     _itemList = new RSSItemList();
     _url      = url;
 }
Exemplo n.º 3
0
        static internal void Parse(ref IRSSChannel channel, Stream stream, string url, Regex ToTransform, string baseDownload)
        {
            RSSItemList rssl = new RSSItemList();
            //channel.Reset();

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(stream);

            XmlNode node = xmlDoc.SelectSingleNode("/rss/channel/title");

            channel.Title = (node != null ? node.InnerText : "");

            node         = xmlDoc.SelectSingleNode("/rss/channel/link");
            channel.Link = (node != null ? node.InnerText : "");

            node = xmlDoc.SelectSingleNode("/rss/channel/description");
            channel.Description = (node != null ? node.InnerText : "");

            node             = xmlDoc.SelectSingleNode("/rss/channel/language");
            channel.Language = (node != null ? node.InnerText : "");

            XmlNodeList nodes = xmlDoc.SelectNodes("/rss/channel/item");

            foreach (XmlNode n in nodes)
            {
                RSSItem item = new RSSItem();

                node       = n.SelectSingleNode("title");
                item.Title = (node != null ? node.InnerText : "");

                node = n.SelectSingleNode("link");
                if (node != null)
                {
                    string link  = node.InnerText;
                    Match  match = ToTransform.Match(link);
                    string ID    = match.Groups["TID"].Value;
                    if (baseDownload.EndsWith("/"))
                    {
                        item.Link = baseDownload + ID;
                    }
                    else
                    {
                        item.Link = baseDownload + "/" + ID;
                    }
                }

                node             = n.SelectSingleNode("description");
                item.Description = (node != null ? node.InnerText : "");

                node        = n.SelectSingleNode("author");
                item.Author = (node != null ? node.InnerText : "");

                node          = n.SelectSingleNode("category");
                item.Category = (node != null ? node.InnerText : "");

                node           = n.SelectSingleNode("comments");
                item.Commments = (node != null ? node.InnerText : "");

                node           = n.SelectSingleNode("enclosure");
                item.Enclosure = (node != null ? node.InnerText : "");

                node      = n.SelectSingleNode("guid");
                item.Guid = (node != null ? node.InnerText : "");

                node = n.SelectSingleNode("pubDate");
                if (node == null)
                {
                    item.PublishDate = new DateTime(0);
                }
                else
                {
                    item.PublishDate = Convert.ToDateTime(node.InnerText).ToUniversalTime() + DateTimeOffset.Now.Offset;
                    //ыtring RFC822 = "ddd, dd MMM yyyy HH:mm:ss zzz";
                    //item.PublishDate = DateTime.ParseExact(node.InnerText, RFC822,DateTimeFormatInfo.InvariantInfo,DateTimeStyles.None);
                }

                node        = n.SelectSingleNode("source");
                item.Source = (node != null ? node.InnerText : "");

                rssl.Add(item);
            }
            channel.Items = rssl;
        }
Exemplo n.º 4
0
 public void Reset()
 {
     _title    = _language = _description = _link = "";
     _updated  = new DateTime(0);
     _itemList = new RSSItemList();
 }
Exemplo n.º 5
0
        static internal void ParseAtom(ref IRSSChannel channel, Stream stream, string url)
        {
            RSSItemList rssl = new RSSItemList();
            //channel.Reset();
            XmlDocument         xmlDoc = new XmlDocument();
            XmlNamespaceManager nsmgr  = new XmlNamespaceManager(xmlDoc.NameTable);

            nsmgr.AddNamespace("atom", "http://www.w3.org/2005/Atom");
            xmlDoc.Load(stream);
            XmlNode node = xmlDoc.SelectSingleNode("/atom:feed/atom:title", nsmgr);

            channel.Title = (node != null ? node.InnerText : "");

            node         = xmlDoc.SelectSingleNode("/atom:feed/atom:link", nsmgr);
            channel.Link = (node != null ? node.InnerText : "");

            node = xmlDoc.SelectSingleNode("/atom:feed/atom:subtitle", nsmgr);
            channel.Description = (node != null ? node.InnerText : "");

            channel.Language = null;

            XmlNodeList nodes = xmlDoc.SelectNodes("/atom:feed/atom:entry", nsmgr);

            foreach (XmlNode n in nodes)
            {
                RSSItem item = new RSSItem();

                node       = n.SelectSingleNode("atom:title", nsmgr);
                item.Title = (node != null ? node.InnerText : "");

                node      = n.SelectSingleNode("atom:link", nsmgr);
                item.Link = (node != null ? node.InnerText : "");

                node             = n.SelectSingleNode("atom:summary", nsmgr);
                item.Description = (node != null ? node.InnerText : "");

                node        = n.SelectSingleNode("atom:author", nsmgr);
                item.Author = (node != null ? node.InnerText : "");

                node          = n.SelectSingleNode("atom:category", nsmgr);
                item.Category = (node != null ? node.InnerText : "");

                item.Commments = null;

                item.Enclosure = null;

                node      = n.SelectSingleNode("atom:id", nsmgr);
                item.Guid = (node != null ? node.InnerText : "");

                node = n.SelectSingleNode("atom:updated", nsmgr);
                if (node == null)
                {
                    item.PublishDate = new DateTime(0);
                }
                else
                {
                    item.PublishDate = XmlConvert.ToDateTime(node.InnerText).ToUniversalTime() + DateTimeOffset.Now.Offset;
                    //string RFC3339 = "ddd, dd MMM yyyy HH:mm:ss zzz"; "yyyy-MM-ddTHH:mm:ss+00:00"
                    //item.PublishDate = DateTime.ParseExact(node.InnerText, RFC3339,
                    //                                   DateTimeFormatInfo.InvariantInfo,
                    //                                   DateTimeStyles.None);
                }

                node        = n.SelectSingleNode("atom:source", nsmgr);
                item.Source = (node != null ? node.InnerText : "");

                rssl.Add(item);
            }
            channel.Items = rssl;
        }