Example #1
0
        public async Task <List <AnimeGeneralDetailsData> > GetSearchResults()
        {
            var output = new List <AnimeGeneralDetailsData>();

            var raw = await GetRequestResponse();

            if (string.IsNullOrEmpty(raw))
            {
                return(output);
            }
            raw = WebUtility.HtmlDecode(raw);
            switch (CurrentApiType)
            {
            case ApiType.Mal:
                try
                {
                    var parsed = XElement.Parse(raw.Replace("&", ""));     //due to unparasable stuff returned by mal
                    foreach (var element in parsed.Elements("entry"))
                    {
                        var item = new AnimeGeneralDetailsData();
                        item.ParseXElement(element, true, Settings.PreferEnglishTitles);
                        output.Add(item);
                    }
                }
                catch (Exception)
                {
                    //mal can throw html in synopisis and xml cannot do much
                }

                break;

            case ApiType.Hummingbird:
                dynamic jsonObj = JsonConvert.DeserializeObject(raw);
                foreach (var entry in jsonObj)
                {
                    try
                    {
                        var allEps = 0;
                        if (entry.episode_count != null)
                        {
                            allEps = Convert.ToInt32(entry.episode_count.ToString());
                        }
                        output.Add(new AnimeGeneralDetailsData
                        {
                            Title       = entry.title.ToString(),
                            ImgUrl      = entry.cover_image.ToString(),
                            Type        = entry.show_type.ToString(),
                            Id          = Convert.ToInt32(entry.id.ToString()),
                            MalId       = Convert.ToInt32(entry.mal_id.ToString()),
                            AllEpisodes = allEps,
                            StartDate   = "0000-00-00",   //TODO : Do sth
                            EndDate     = "0000-00-00",
                            Status      = entry.status.ToString(),
                            Synopsis    = entry.synopsis.ToString(),
                            GlobalScore = float.Parse(entry.community_rating.ToString()),
                            Synonyms    = new List <string>()
                        });
                    }
                    catch (Exception e)
                    {
                    }
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(output);
        }
        public async void SubmitQuery(string query)
        {
            if (query == PrevQuery)
            {
                return;
            }
            PrevQuery             = query;
            Loading               = Visibility.Visible;
            EmptyNoticeVisibility = Visibility.Collapsed;
            AnimeSearchItems.Clear();
            var data = new List <AnimeGeneralDetailsData>();

            _filters.Clear();
            _allAnimeSearchItems = new List <AnimeSearchItem>();
            if (_animeSearch)
            {
                await
                Task.Run(
                    async() =>
                    data = await new AnimeSearchQuery(Utils.CleanAnimeTitle(query)).GetSearchResults());

                try
                {
                    foreach (var item in data)
                    {
                        var type = item.Type;
                        _allAnimeSearchItems.Add(new AnimeSearchItem(item));
                        if (!_filters.Contains(type))
                        {
                            _filters.Add(type);
                        }
                    }
                }
                catch (Exception) //if MAL returns nothing it returns unparsable xml ...
                {
                    EmptyNoticeVisibility = Visibility.Visible;
                }
            }
            else // manga search
            {
                var response = "";
                await
                Task.Run(
                    async() =>
                    response = await new MangaSearchQuery(Utils.CleanAnimeTitle(query)).GetRequestResponse());

                try
                {
                    var parsedData = XDocument.Parse(response);
                    foreach (var item in parsedData.Element("manga").Elements("entry"))
                    {
                        var type      = item.Element("type").Value;
                        var mangaData = new AnimeGeneralDetailsData();
                        mangaData.ParseXElement(item, false);
                        _allAnimeSearchItems.Add(new AnimeSearchItem(mangaData, false));
                        if (!_filters.Contains(type))
                        {
                            _filters.Add(type);
                        }
                    }
                }
                catch (Exception) //if MAL returns nothing it returns unparsable xml ...
                {
                    EmptyNoticeVisibility = Visibility.Visible;
                }
            }
            ViewModelLocator.Main.PopulateSearchFilters(_filters);
            PopulateItems();
            Loading = Visibility.Collapsed;
        }
Example #3
0
        public async Task <AnimeGeneralDetailsData> GetAnimeDetails(bool force, string id, string title, bool animeMode,
                                                                    ApiType?apiOverride = null)
        {
            var output = force ? null : await DataCache.RetrieveAnimeSearchResultsData(id, animeMode);

            if (output != null)
            {
                return(output);
            }

            var requestedApiType = apiOverride ?? CurrentApiType;

            try
            {
                switch (requestedApiType)
                {
                case ApiType.Mal:
                    string data = null;
                    if (!string.IsNullOrEmpty(title))
                    {
                        data = animeMode
                            ? await new AnimeSearchQuery(Utils.Utilities.CleanAnimeTitle(title), requestedApiType)
                               .GetRequestResponse()
                            : await new MangaSearchQuery(Utils.Utilities.CleanAnimeTitle(title)).GetRequestResponse();
                    }

                    if (string.IsNullOrEmpty(data) || !data.Contains(id))
                    {
                        //we are loading title from website because request came from mal url
                        var correctTitle = await AnimeTitleQuery.GetTitle(int.Parse(id), animeMode);

                        data = animeMode
                            ? await new AnimeSearchQuery(Utils.Utilities.CleanAnimeTitle(correctTitle), requestedApiType)
                               .GetRequestResponse()
                            : await new MangaSearchQuery(Utils.Utilities.CleanAnimeTitle(correctTitle)).GetRequestResponse();
                    }

                    data = WebUtility.HtmlDecode(data);

                    data = data.Replace("&", "");     //unparsable stuff ahaead :(
                    var parsedData = XDocument.Parse(data);

                    var elements = parsedData.Element(animeMode ? "anime" : "manga").Elements("entry");
                    var xmlObj   = elements.First(element => element.Element("id").Value == id);

                    output = new AnimeGeneralDetailsData();
                    output.ParseXElement(xmlObj, animeMode, Settings.PreferEnglishTitles);

                    DataCache.SaveAnimeSearchResultsData(id, output, animeMode);
                    break;

                case ApiType.Hummingbird:
                    Request =
                        WebRequest.Create(
                            Uri.EscapeUriString($"https://hummingbird.me/api/v1/anime/{id}"));
                    Request.ContentType = "application/x-www-form-urlencoded";
                    Request.Method      = "GET";

                    var raw = await GetRequestResponse();

                    if (string.IsNullOrEmpty(raw))
                    {
                        break;
                    }

                    dynamic jsonObj = JsonConvert.DeserializeObject(raw);
                    var     allEps  = 0;
                    if (jsonObj.episode_count != null)
                    {
                        allEps = Convert.ToInt32(jsonObj.episode_count.ToString());
                    }
                    output = new AnimeGeneralDetailsData
                    {
                        Title       = jsonObj.title.ToString(),
                        ImgUrl      = jsonObj.cover_image.ToString(),
                        Type        = jsonObj.show_type.ToString(),
                        Id          = Convert.ToInt32(jsonObj.id.ToString()),
                        MalId       = Convert.ToInt32(jsonObj.mal_id.ToString()),
                        AllEpisodes = allEps,
                        StartDate   = jsonObj.started_airing.ToString(),
                        EndDate     = jsonObj.finished_airing.ToString(),
                        Status      = jsonObj.status,
                        Synopsis    = jsonObj.synopsis,
                        GlobalScore = jsonObj.community_rating,
                        Synonyms    = new List <string> {
                            jsonObj.alternate_title.ToString()
                        }
                    };
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception e)
            {
                // todo android notification nav bug
                // probably MAl garbled response
            }

            return(output);
        }
        public async Task <List <AnimeGeneralDetailsData> > GetSearchResults()
        {
            var output = new List <AnimeGeneralDetailsData>();

            var raw = await GetRequestResponse();

            if (string.IsNullOrEmpty(raw))
            {
                return(output);
            }

            switch (CurrentApiType)
            {
            case ApiType.Mal:
                var parsed = XElement.Parse(raw);
                foreach (var element in parsed.Elements("entry"))
                {
                    var item = new AnimeGeneralDetailsData();
                    item.ParseXElement(element, true);
                    output.Add(item);
                }
                break;

            case ApiType.Hummingbird:
                dynamic jsonObj = JsonConvert.DeserializeObject(raw);
                foreach (var entry in jsonObj)
                {
                    try
                    {
                        var allEps = 0;
                        if (entry.episode_count != null)
                        {
                            allEps = Convert.ToInt32(entry.episode_count.ToString());
                        }
                        output.Add(new AnimeGeneralDetailsData
                        {
                            Title       = entry.title.ToString(),
                            ImgUrl      = entry.cover_image.ToString(),
                            Type        = entry.show_type.ToString(),
                            Id          = Convert.ToInt32(entry.id.ToString()),
                            MalId       = Convert.ToInt32(entry.mal_id.ToString()),
                            AllEpisodes = allEps,
                            StartDate   = AnimeItemViewModel.InvalidStartEndDate,   //TODO : Do sth
                            EndDate     = AnimeItemViewModel.InvalidStartEndDate,
                            Status      = entry.status.ToString(),
                            Synopsis    = entry.synopsis.ToString(),
                            GlobalScore = float.Parse(entry.community_rating.ToString()),
                            Synonyms    = new List <string>()
                        });
                    }
                    catch (Exception e)
                    {
                    }
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(output);
        }
Example #5
0
        public async Task <AnimeGeneralDetailsData> GetAnimeDetails(bool force, string id, string title, bool animeMode,
                                                                    ApiType?apiOverride = null)
        {
            var output = force ? null : await DataCache.RetrieveAnimeSearchResultsData(id, animeMode);

            if (output != null)
            {
                return(output);
            }

            var requestedApiType = apiOverride ?? CurrentApiType;

            switch (requestedApiType)
            {
            case ApiType.Mal:
                var data = animeMode
                        ? await new AnimeSearchQuery(Utils.CleanAnimeTitle(title)).GetRequestResponse(false)
                        : await new MangaSearchQuery(Utils.CleanAnimeTitle(title)).GetRequestResponse(false);
                data = WebUtility.HtmlDecode(data);
                data = data.Replace("&mdash", "").Replace("&rsquo", "").Replace("&", "");

                var parsedData = XDocument.Parse(data);

                var elements = parsedData.Element(animeMode ? "anime" : "manga").Elements("entry");
                var xmlObj   = elements.First(element => element.Element("id").Value == id);

                output = new AnimeGeneralDetailsData();
                output.ParseXElement(xmlObj, animeMode);

                DataCache.SaveAnimeSearchResultsData(id, output, animeMode);
                break;

            case ApiType.Hummingbird:
                Request =
                    WebRequest.Create(
                        Uri.EscapeUriString($"https://hummingbird.me/api/v1/anime/{id}"));
                Request.ContentType = "application/x-www-form-urlencoded";
                Request.Method      = "GET";

                var raw = await GetRequestResponse();

                if (string.IsNullOrEmpty(raw))
                {
                    break;
                }

                dynamic jsonObj = JsonConvert.DeserializeObject(raw);
                var     allEps  = 0;
                if (jsonObj.episode_count != null)
                {
                    allEps = Convert.ToInt32(jsonObj.episode_count.ToString());
                }
                output = new AnimeGeneralDetailsData
                {
                    Title       = jsonObj.title.ToString(),
                    ImgUrl      = jsonObj.cover_image.ToString(),
                    Type        = jsonObj.show_type.ToString(),
                    Id          = Convert.ToInt32(jsonObj.id.ToString()),
                    MalId       = Convert.ToInt32(jsonObj.mal_id.ToString()),
                    AllEpisodes = allEps,
                    StartDate   = jsonObj.started_airing.ToString(),
                    EndDate     = jsonObj.finished_airing.ToString(),
                    Status      = jsonObj.status,
                    Synopsis    = jsonObj.synopsis,
                    GlobalScore = jsonObj.community_rating,
                    Synonyms    = new List <string> {
                        jsonObj.alternate_title.ToString()
                    }
                };
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }


            return(output);
        }
        public async void SubmitQuery(string query)
        {
            if (string.IsNullOrEmpty(query) || query == PrevQuery || query.Length < 2)
            {
                IsFirstVisitGridVisible = false;
                EmptyNoticeVisibility   = false;
                return;
            }

            IsFirstVisitGridVisible = false;
            PrevQuery             = query;
            Loading               = true;
            EmptyNoticeVisibility = false;
            AnimeSearchItemViewModels.Clear();
            var data = new List <AnimeGeneralDetailsData>();

            _filters.Clear();
            _allAnimeSearchItemViewModels = new List <AnimeSearchItemViewModel>();
            if (_animeSearch)
            {
                await
                Task.Run(
                    async() =>
                    data = await new AnimeSearchQuery(Utils.Utilities.CleanAnimeTitle(query)).GetSearchResults());

                try
                {
                    foreach (var item in data)
                    {
                        var type = item.Type;
                        _allAnimeSearchItemViewModels.Add(new AnimeSearchItemViewModel(item));
                        if (!_filters.Contains(type))
                        {
                            _filters.Add(type);
                        }
                    }
                }
                catch (Exception) //if MAL returns nothing it returns unparsable xml ...
                {
                    //will display empty notice
                }
            }
            else // manga search
            {
                var response = "";
                await
                Task.Run(
                    async() =>
                    response = await new MangaSearchQuery(Utils.Utilities.CleanAnimeTitle(query)).GetRequestResponse());

                try
                {
                    response = WebUtility.HtmlDecode(response);
                    var parsedData = XDocument.Parse(response.Replace("&", "")); //due to unparasable stuff returned by mal);
                    foreach (var item in parsedData.Element("manga").Elements("entry"))
                    {
                        var type      = item.Element("type").Value;
                        var mangaData = new AnimeGeneralDetailsData();
                        mangaData.ParseXElement(item, false, Settings.PreferEnglishTitles);
                        _allAnimeSearchItemViewModels.Add(new AnimeSearchItemViewModel(mangaData, false));
                        if (!_filters.Contains(type))
                        {
                            _filters.Add(type);
                        }
                    }
                }
                catch (Exception) //if MAL returns nothing it returns unparsable xml ...
                {
                    //will display empty notice
                }
            }
            ViewModelLocator.GeneralMain.PopulateSearchFilters(_filters);
            PopulateItems();
            Loading = false;
        }