示例#1
0
        public static BrowseCriteriaDTO CriterToCriteriaDTO(BrowseCriteria criteria)
        {
            var result = new BrowseCriteriaDTO()
            {
                year           = criteria.Year.ToString(),
                season         = criteria.Season?.GetDescription(),
                type           = criteria.Type?.GetDescription(),
                status         = criteria.AiringStatus?.GetDescription(),
                genres         = criteria.ExcludeGenres != null ? $"{criteria.ExcludeGenres.Select(x => x.GetDescription())}," : null,
                genres_exclude = criteria.ExcludeGenres != null ? $"{criteria.ExcludeGenres.Select(x => $"{x.GetDescription()},")}" : null,
                sort           = criteria.SortType?.GetDescription(),
                SortOrder      = criteria.IsDescending ? "desc" : null,
                airing_data    = criteria.IncludeAiringData ? "true" : null,
                full_page      = criteria.IncludeFullPage ? "true" : null,
                page           = null
            };

            if (result.genres != null)
            {
                result.genres = result.genres.Last() == ',' ? result.genres.Substring(0, result.genres.Length - 1) : result.genres;
            }

            if (result.genres_exclude != null)
            {
                result.genres_exclude = result.genres_exclude.Last() == ',' ? result.genres_exclude.Substring(0, result.genres_exclude.Length - 1) : result.genres_exclude;
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Get a list of series using more in depth search criteria.
        /// </summary>
        /// <param name="criteria">The criteria used to search on.</param>
        /// <returns>Returns a list of series.</returns>
        public async Task <List <Series> > BrowseSeriesAsync(BrowseCriteria criteria)
        {
            var url = HttpUtility.HtmlEncode(AniListApiHelper.GetUrl(AnilistTypes.BrowseAnime, null, criteria));

            try
            {
                var rawAnime = await GenericGetAsync <List <SeriesDTO> >(url);

                return(rawAnime?.Select(Series.ConstructFromDto).ToList());
            }
            catch (Exception e)
            {
                throw new Exception($"Failed to retrieve search. Error: {e}");
            }
        }
示例#3
0
        /// <summary>
        /// Gets a dictionary of series for the specified season grouped by media type.
        /// </summary>
        /// <param name="season">Season type to fetch series for (specify nothing to get current season).</param>
        /// <returns>Returns a dictionary of series group by media type.</returns>
        public async Task <Dictionary <MediaTypes, List <Series> > > BrowseSeasonsAsync(Seasons?season = null)
        {
            var criteria = new BrowseCriteria()
            {
                Year              = GetYear(season),
                Season            = season ?? GetCurrentSeason(),
                IncludeAiringData = true,
                IncludeFullPage   = true
            };

            var url = AniListApiHelper.GetUrl(AnilistTypes.BrowseAnime, null, criteria);

            try
            {
                var rawAnime = await GenericGetAsync <List <SeriesDTO> >(url);

                return(rawAnime?.GroupBy(x => x.type.GetEnumValue <MediaTypes>(), (key, series) => series.Select(Series.ConstructFromDto).ToList()).ToDictionary(x => x.FirstOrDefault().Type.Value, x => x));
            }
            catch (Exception e)
            {
                throw new Exception($"Failed to retrieve search. Error: {e}");
            }
        }