public static NewzNabCapabilities ParseXmlResponse(XmlDocument xmlResponse)
        {
            NewzNabCapabilities Result = new NewzNabCapabilities();

            //Basic Capabilities
            Result.MaxResults     = Convert.ToInt32(xmlResponse.SelectSingleNode("/caps/limits").Attributes["max"].Value);
            Result.DefaultResults = Convert.ToInt32(xmlResponse.SelectSingleNode("/caps/limits").Attributes["default"].Value);
            Result.Retention      = Convert.ToInt32(xmlResponse.SelectSingleNode("/caps/retention").Attributes["days"].Value);

            //Search Capabilities
            Result.SearchAvail      = YesNoToBool(xmlResponse.SelectSingleNode("/caps/searching/search").Attributes["available"].Value);
            Result.TvSearchAvail    = YesNoToBool(xmlResponse.SelectSingleNode("/caps/searching/tv-search").Attributes["available"].Value);
            Result.MovieSearchAvail = YesNoToBool(xmlResponse.SelectSingleNode("/caps/searching/movie-search").Attributes["available"].Value);
            Result.AudioSearchAvail = YesNoToBool(xmlResponse.SelectSingleNode("/caps/searching/audio-search").Attributes["available"].Value);

            //Categories
            foreach (XmlNode cat in xmlResponse.SelectNodes("caps/categories/category"))
            {
                Result.Categories.Add(Convert.ToInt32(cat.Attributes["id"].Value), HttpUtility.HtmlDecode(cat.Attributes["name"].Value));
                foreach (XmlNode subCat in cat.ChildNodes)
                {
                    Result.Categories.Add(Convert.ToInt32(subCat.Attributes["id"].Value), HttpUtility.HtmlDecode(cat.Attributes["name"].Value + "\\" + subCat.Attributes["name"].Value));
                }
            }

            //Groups
            foreach (XmlNode group in xmlResponse.SelectNodes("caps/groups/group"))
            {
                if (group.Attributes == null)
                {
                    continue;
                }
                var currentGroup = new UsenetGroup
                {
                    ID          = Convert.ToInt32(group.Attributes["id"].Value),
                    Name        = HttpUtility.HtmlDecode(group.Attributes["name"].Value),
                    Description = group.Attributes["description"].Value
                };
                DateTime.TryParse(group.Attributes["lastupdate"].Value, out currentGroup.LastUpdate);
                Result.Groups.Add(currentGroup);
            }

            //Genres
            foreach (XmlNode genre in xmlResponse.SelectNodes("caps/genres/genres"))
            {
                if (genre.Attributes != null)
                {
                    var currentGenre = new NewzNabGenre
                    {
                        ID         = Convert.ToInt32(genre.Attributes["id"].Value),
                        CategoryID = Convert.ToInt32(genre.Attributes["categoryid"].Value)
                    };
                    currentGenre.Name = HttpUtility.HtmlDecode(Result.Categories[currentGenre.CategoryID] + "\\" + genre.Attributes["name"].Value);
                    Result.Genres.Add(currentGenre);
                }
            }

            return(Result);
        }
Example #2
0
        public bool GetCapabilities()
        {
            NewzNabQuery capsQuery = new NewzNabQuery();

            capsQuery.RequestedFunction = Functions.Caps;
            XmlDocument response = DoQuery(capsQuery);

            Capabilities = NewzNabCapabilities.ParseXmlResponse(response);
            return(true);
        }