Beispiel #1
0
 public void Update()
 {
     try
     {
         WebRequest req = WebRequest.Create(Url);
         using (WebResponse resp = req.GetResponse())
         {
             IRSSChannel channel = this;
             if (_transform != null)
             {
                 RSSParser.Parse(ref channel, resp.GetResponseStream(), Url, _transform, _basedllink);
             }
             else
             {
                 if (channel.Type == "rss")
                 {
                     RSSParser.Parse(ref channel, resp.GetResponseStream(), Url);
                 }
                 if (channel.Type == "atom")
                 {
                     RSSParser.ParseAtom(ref channel, resp.GetResponseStream(), Url);
                 }
             }
             _updated = DateTime.Now;
         }
     }
     catch (Exception e)
     {
         Title       = "Connection failed.";
         Description = e.Message;
     }
 }
Beispiel #2
0
 public void _RSSUpdated(IRSSChannel channel)
 {
     if (ListType == "RSS" || ListType == "SelectedRSS")
     {
         UpdateScreen();
     }
 }
Beispiel #3
0
 internal void ChannelUpdated(IRSSChannel channel)
 {
     if (RSSChannelUpdated != null)
     {
         RSSChannelUpdated(channel);
     }
 }
Beispiel #4
0
 internal void Add(IRSSChannel channel)
 {
     foreach (IRSSChannel c in _cached)
     {
         if (c.Url.CompareTo(channel.Url) == 0)
         {
             _cached.Remove(c);
         }
     }
     _cached.Add(channel);
     //new channel added
     if (RSSChannelAdded != null)
     {
         RSSChannelAdded(channel);
     }
 }
Beispiel #5
0
        void channelManager_RSSChannelUpdated(IRSSChannel channel)
        {
            foreach (WatchItem watch in _watchItemList)
            {
                watch.LastCheck = DateTime.Now;
                foreach (RSSItem rssItem in channel.Items)
                {
                    //if match
                    Regex re = new Regex(watch.SearchTerm, RegexOptions.IgnoreCase);

                    if (re.IsMatch(rssItem.Title))
                    {
                        Log.Instance().Print(String.Format("[{0}] matches to [{1}], downloading.", watch.SearchTerm, rssItem.Title));
                        DownloadTorrent(rssItem, watch.Label);
                    }
                }
            }
        }
Beispiel #6
0
        public List <GUIListItem> ShowSelectedRSS(IRSSChannel channel)
        {
            _selectedRSSChannel = channel;
            List <GUIListItem> rsslist = new List <GUIListItem>();

            rsslist.Clear();
            IconMapping iconMapping = Configuration.Instance().Settings["MyTorrents.GlobalIconMapping"] as IconMapping;

            foreach (RSSItem item in channel.Items)
            {
                GUIListItem listItem = new GUIListItem();
                listItem.PinImage     = iconMapping.GetIcon(item.Title);
                listItem.Label        = (item.Title.Length > 130 ? item.Title.Substring(0, 130) : item.Title);
                listItem.Label2       = item.PublishDate.ToShortDateString() + " " + item.PublishDate.ToShortTimeString();
                listItem.AlbumInfoTag = item;
                rsslist.Add(listItem);
            }

            return(rsslist);
        }
Beispiel #7
0
        protected override void OnShowContextMenu()
        {
            if (ListType == "Torrents")
            {
                Torrent uTorrent = torrentList.SelectedListItem.AlbumInfoTag as Torrent;
                ViewTorrents.TorrentsContextMenu(uTorrent);
            }
            if (ListType == "TorrentDetails")
            {
                lock (UpdateLocker)
                {
                    int  index        = FileList.SelectedListItemIndex;
                    File selectedfile = FileList.SelectedListItem.AlbumInfoTag as File;
                    ViewDetails.TorrentDetailsContextMenu(selectedfile, index);
                }
            }
            if (ListType == "RSS")
            {
                IRSSChannel result = ViewRSS.RSSContextMenu(torrentList.SelectedListItem.AlbumInfoTag as IRSSChannel);
                if (result != null)
                {
                    ListType = "SelectedRSS";
                    torrentList.ListItems = ViewRSS.ShowSelectedRSS(result);
                }
            }

            if (ListType == "SelectedRSS")
            {
            }
            if (ListType == "Search")
            {
                ViewSearch.SearchContextMenu();
            }
            if (ListType == "WatchList")
            {
                ViewAutoGrabber.ContextMenu(torrentList.SelectedListItem.AlbumInfoTag);
            }
        }
Beispiel #8
0
        public void OnRSSAction(MediaPortal.GUI.Library.Action action)
        {
            if (action.wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_PREVIOUS_MENU)
            {
                if (_selectedRSSChannel != null)
                {
                    _selectedRSSChannel = null;
                    //UpdateListItems();
                    return;
                }
                else
                {
                    return;
                }
            }
            else if ((action.wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_MOVE_DOWN) ||
                     (action.wID == MediaPortal.GUI.Library.Action.ActionType.ACTION_MOVE_UP))
            {
                RSSItem item = rss.AlbumInfoTag as RSSItem;

                if (item != null)
                {
                    string description = Regex.Replace(item.Description, "<(.|\n)*?>", "");
                    GUIPropertyManager.SetProperty("#MyTorrents.RSS.Source", item.Source);
                    GUIPropertyManager.SetProperty("#MyTorrents.RSS.PublishDate", item.PublishDate.ToShortDateString() + " " + item.PublishDate.ToShortTimeString());
                    GUIPropertyManager.SetProperty("#MyTorrents.RSS.Guid", item.Guid);
                    GUIPropertyManager.SetProperty("#MyTorrents.RSS.Enclosure", item.Enclosure);
                    GUIPropertyManager.SetProperty("#MyTorrents.RSS.Commments", item.Commments);
                    GUIPropertyManager.SetProperty("#MyTorrents.RSS.Category", item.Category);
                    GUIPropertyManager.SetProperty("#MyTorrents.RSS.Author", item.Author);
                    GUIPropertyManager.SetProperty("#MyTorrents.RSS.Description", description);
                    GUIPropertyManager.SetProperty("#MyTorrents.RSS.Link", item.Link);
                    GUIPropertyManager.SetProperty("#MyTorrents.RSS.Title", item.Title);
                }
            }
        }
        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;
        }
Beispiel #10
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;
        }
Beispiel #11
0
        public bool LoadRssChannels(ConfigData _config)
        {
            XmlDocument       xmlDoc         = _config.MyTorrentsConfiguration;
            RSSChannelManager channelManager = RSSChannelManager.Instance();
            XmlNodeList       nodes          = xmlDoc.SelectSingleNode("config/feed").ChildNodes;

            foreach (XmlNode node in nodes)
            {
                IRSSChannel rssChannel = null;
                string      type       = "";
                if (node.Name == "rss")
                {
                    type = "rss";
                }
                if (node.Name == "atom")
                {
                    type = "atom";
                }
                XmlNodeList nUrls = node.SelectNodes("url");
                if (nUrls.Count >= 2)
                {
                    //combined!
                    XmlNode nTitle = node.SelectSingleNode("title");
                    XmlNode nDesc  = node.SelectSingleNode("description");

                    if (nTitle == null || nDesc == null)
                    {
                        continue;
                    }
                    RSSCombined combined = new RSSCombined(nTitle.InnerText, nDesc.InnerText);

                    foreach (XmlNode nUrl in node.SelectNodes("url"))
                    {
                        RSSChannel channel = new RSSChannel(nUrl.InnerText);

                        combined.Channels.Add(channel);
                    }
                    rssChannel = combined;
                }
                else
                {
                    if (node.SelectSingleNode("transform") != null)
                    {
                        XmlNode nurl         = node.SelectSingleNode("url");
                        XmlNode trans        = node.SelectSingleNode("transform/origin");
                        XmlNode basedownload = node.SelectSingleNode("transform/basedownload");
                        rssChannel = new RSSChannel(nurl.InnerText, new Regex(trans.InnerText, RegexOptions.IgnoreCase), basedownload.InnerText);
                    }
                    else
                    {
                        XmlNode nUrl = node.SelectSingleNode("url");
                        rssChannel = new RSSChannel(nUrl.InnerText);
                    }
                }
                XmlNode expireTime = node.SelectSingleNode("expires");

                if (expireTime == null)
                {
                    //5minutes
                    rssChannel.ExpireTime = new TimeSpan(0, 5, 0);
                }
                else
                {
                    rssChannel.ExpireTime = new TimeSpan(0, 0, Convert.ToInt32(expireTime.InnerText));
                }
                rssChannel.Type = type;
                channelManager.Channels.Add(rssChannel);
            }

            Log.Instance().Print("Started RssChanel");


            return(true);
        }
Beispiel #12
0
        protected void OnRSSClicked(int controlId, GUIControl control,
                                    MediaPortal.GUI.Library.Action.ActionType actionType)
        {
            if (control.GetID == 4)
            {
                OnButtonBack();
            }
            if (control.GetID == 208)
            {
                if (actionType == MediaPortal.GUI.Library.Action.ActionType.ACTION_SELECT_ITEM)
                {
                    //    if (rss.AlbumInfoTag.GetType() == typeof(RSSUTorrentFeeds))
                    //    {
                    //        RSSUTorrentFeeds currentfeed = rss.AlbumInfoTag as RSSUTorrentFeeds;
                    //        List<RSSNextUpdate> nextupd = currentfeed.nextUpd;
                    //        _selectedChannel = currentfeed;
                    //        rss.Clear();
                    //        foreach (RSSNextUpdate it in nextupd)
                    //        {
                    //            GUIListItem listItem = new GUIListItem();
                    //            listItem.Label = it.NameFull;
                    //            DateTime updatedate = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(it.Timestamp).ToLocalTime();
                    //            listItem.Label2 = updatedate.ToShortDateString() + " " + updatedate.ToShortTimeString();
                    //            listItem.AlbumInfoTag = it;

                    //            rssList.Add(listItem);
                    //        }

                    //        if (nextupd.Count == 0)
                    //        {
                    //            GUIListItem listItem = new GUIListItem();
                    //            listItem.Label = "No items.";
                    //            rssList.Add(listItem);
                    //        }
                    //    }

                    //if (rss.Label == "UTorrent Inbuit RSS Feeds")
                    //{
                    //    List<RSSUTorrentFeeds> ufeeds = rssList.SelectedListItem.AlbumInfoTag as List<RSSUTorrentFeeds>;
                    //    rssList.Clear();
                    //    _selectedChannel = ufeeds[0];
                    //    foreach (RSSUTorrentFeeds elem in ufeeds)
                    //    {

                    //        GUIListItem listIt = new GUIListItem();
                    //        listIt.Label = elem.Url.Split(new char[] { '|' }).First() + "\n" + elem.Url.Split(new char[] { '/' })[2];
                    //        DateTime updatedate = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(elem.Timestamp).ToLocalTime();
                    //        listIt.Label2 = updatedate.ToShortDateString() + " " + updatedate.ToShortTimeString();
                    //        listIt.AlbumInfoTag = elem;
                    //        RSSChannel uchannel = new RSSChannel(elem.Url);
                    //        rssList.Add(listIt);
                    //    }

                    //    if (ufeeds.Count == 0)
                    //    {
                    //        GUIListItem listItem = new GUIListItem();
                    //        listItem.Label = "No items.";
                    //        rssList.Add(listItem);
                    //    }
                    //}



                    IRSSChannel channel = rss.AlbumInfoTag as IRSSChannel;
                    RSSItem     item    = rss.AlbumInfoTag as RSSItem;

                    if (channel != null)
                    {
                        _selectedRSSChannel = channel;
                    }
                    else if (item != null)
                    {
                    }
                }
            }
            else if (control.GetID != 0)
            {
            }
        }
Beispiel #13
0
        public IRSSChannel RSSContextMenu(IRSSChannel channel)
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return(null);
            }

            dlg.Reset();
            dlg.SetHeading("RSS Feeds");
            dlg.Add("Search");
            dlg.Add("Update selected");
            dlg.Add("Update all");
            dlg.DoModal(GUIWindowManager.ActiveWindow);

            switch (dlg.SelectedLabelText)
            {
            case "Update selected":
            {
                if (channel == null)
                {
                    return(null);
                }
                if (channel != null)
                {
                    channel.Update();
                }
                return(null);
            }

            case "Update all":
            {
                RSSChannelManager.Instance().UpdateChannels(true);
                return(null);
            }

            case "Search":
            {
                VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD);
                keyboard.Reset();
                keyboard.Text = "";
                keyboard.DoModal(GUIWindowManager.ActiveWindow);

                if (!keyboard.IsConfirmed)
                {
                    return(null);
                }

                Regex re = new Regex(keyboard.Text, RegexOptions.IgnoreCase);

                RSSChannel search = new RSSChannel("MediaPortal");
                if (channel != null && channel.Url != "MediaPortal")
                {
                    foreach (RSSItem item in channel.Items)
                    {
                        if (re.IsMatch(item.Title))
                        {
                            search.Items.Add(item);
                        }
                    }
                }
                //this.ShowSelectedRSS() = search;
                //UpdateListItems();
                return(search);
            }
            }
            return(null);
        }
Beispiel #14
0
 void View_TorrentRSS_RSSChannelUpdated(IRSSChannel channel)
 {
     //UpdateListItems();
 }