Esempio n. 1
0
        public static async Task <ForumBoardContent> GetSearchResults(string query, ForumBoards?searchScope)
        {
            var scope  = searchScope == null ? -1 : (int)searchScope;
            var output = new ForumBoardContent {
                Pages = 0
            };

            if (query.Length > 2)
            {
                try
                {
                    var client = await ResourceLocator.MalHttpContextProvider.GetHttpContextAsync();

                    var resp = await client.GetAsync($"/forum/search?q={query}&u=&uloc=1&loc={scope}");

                    var doc = new HtmlDocument();
                    doc.LoadHtml(await resp.Content.ReadAsStringAsync());
                    var s = await resp.Content.ReadAsStringAsync();

                    var topicContainer =
                        doc.DocumentNode.Descendants("table")
                        .First(
                            node => node.Attributes.Contains("id") && node.Attributes["id"].Value == "forumTopics");
                    foreach (var topicRow in topicContainer.Descendants("tr").Skip(1)) //skip forum table header
                    {
                        try
                        {
                            output.ForumTopicEntries.Add(ParseTopicRow(topicRow));
                        }
                        catch (Exception)
                        {
                            //
                        }
                    }
                }
                catch (Exception e)
                {
                    //
                }
            }
            return(output);
        }
Esempio n. 2
0
        public static async Task <ForumBoardContent> GetWatchedTopics()
        {
            var output = new ForumBoardContent {
                Pages = 0
            };

            try
            {
                var client = await ResourceLocator.MalHttpContextProvider.GetHttpContextAsync();

                var resp = await client.GetAsync("/forum/?action=viewstarred");

                var doc = new HtmlDocument();
                doc.LoadHtml(await resp.Content.ReadAsStringAsync());

                var topicContainer =
                    doc.DocumentNode.Descendants("table")
                    .First(
                        node => node.Attributes.Contains("id") && node.Attributes["id"].Value == "forumTopics");
                foreach (var topicRow in topicContainer.Descendants("tr").Skip(1))     //skip forum table header
                {
                    try
                    {
                        output.ForumTopicEntries.Add(ParseTopicRow(topicRow, 1));
                    }
                    catch (Exception)
                    {
                        //
                    }
                }
            }
            catch (Exception)
            {
                //
            }
            return(output);
        }
Esempio n. 3
0
        public async Task <ForumBoardContent> GetTopicPosts(int?lastPage, bool force = false)
        {
            if (!force)
            {
                try
                {
                    if (_animeId == 0)
                    {
                        if (_boardCache.ContainsKey(_board) && _boardCache[_board].ContainsKey(_page))
                        {
                            return(_boardCache[_board][_page]);
                        }
                    }
                    else
                    {
                        if (_animeBoardCache.ContainsKey(_animeId) && _animeBoardCache[_animeId].ContainsKey(_page))
                        {
                            return(_animeBoardCache[_animeId][_page]);
                        }
                    }
                }
                catch (Exception e)
                {
                    //
                }
            }
            else //clear all pages
            {
                if (_animeId == 0)
                {
                    if (_boardCache.ContainsKey(_board))
                    {
                        _boardCache[_board] = new Dictionary <int, ForumBoardContent>();
                    }
                }
                else
                {
                    if (_animeBoardCache.ContainsKey(_animeId))
                    {
                        _animeBoardCache[_animeId] = new Dictionary <int, ForumBoardContent>();
                    }
                }
            }



            var output = new ForumBoardContent();
            var raw    = await GetRequestResponse();

            if (string.IsNullOrEmpty(raw))
            {
                return(new ForumBoardContent());
            }
            var doc = new HtmlDocument();

            doc.LoadHtml(raw);

            try
            {
                try
                {
                    output.Pages = lastPage ??
                                   int.Parse(
                        doc.FirstOfDescendantsWithClass("span", "di-ib")
                        .Descendants("a")
                        .Last()
                        .Attributes["href"]
                        .Value.Split('=').Last()) / 50;
                }
                catch (Exception)
                {
                    output.Pages = 0;
                }


                var topicContainer =
                    doc.DocumentNode.Descendants("table")
                    .First(node => node.Attributes.Contains("id") && node.Attributes["id"].Value == "forumTopics");

                foreach (var topicRow in topicContainer.Descendants("tr").Skip(1)) //skip forum table header
                {
                    try
                    {
                        output.ForumTopicEntries.Add(ParseHtmlToTopic(topicRow));
                    }
                    catch (Exception)
                    {
                        //hatml
                    }
                }
            }
            catch (Exception)
            {
                //
            }


            if (_animeId == 0)
            {
                if (!_boardCache.ContainsKey(_board))
                {
                    _boardCache[_board] = new Dictionary <int, ForumBoardContent>();
                }
                if (!_boardCache[_board].ContainsKey(_page))
                {
                    _boardCache[_board].Add(_page, output);
                }
                else
                {
                    _boardCache[_board][_page] = output;
                }
            }
            else
            {
                if (!_animeBoardCache.ContainsKey(_animeId))
                {
                    _animeBoardCache[_animeId] = new Dictionary <int, ForumBoardContent>();
                }
                if (!_animeBoardCache[_animeId].ContainsKey(_page))
                {
                    _animeBoardCache[_animeId].Add(_page, output);
                }
                else
                {
                    _animeBoardCache[_animeId][_page] = output;
                }
            }


            return(output);
        }