Пример #1
0
 public static Relation ConstructFromDto(RelationDTO dto)
 {
     return(new Relation()
     {
         Id = dto.id,
         TitleRomaji = dto.title_romaji,
         TitleEnglish = dto.title_english,
         TitleJapanese = dto.title_japanese,
         Type = dto.type,
         StartDate = dto.start_date,
         EndDate = dto.end_date,
         Season = dto.season,
         SeriesType = dto.series_type,
         Synonyms = dto.synonyms,
         Genres = dto.genres,
         IsAdult = dto.adult,
         AverageScore = dto.average_score,
         Popularity = dto.popularity,
         UpdatedAt = dto.updated_at,
         ImageUrlSmall = dto.image_url_sml,
         ImageUrlMedium = dto.image_url_med,
         ImageUrlLarge = dto.image_url_lge,
         ImageUrlBanner = dto.image_url_banner,
         TotalEpisodes = dto.total_episodes,
         AiringStatus = dto.airing_status,
         RelationType = AniListApiHelper.GetRelationType(dto.relation_type)
     });
 }
Пример #2
0
        /// <summary>
        /// Gets a dictionary of series pages.
        /// </summary>
        /// <param name="anilistSeriesIds">A list of AniList numeric based identifiers.</param>
        /// <returns>Returns a dictionary of series pages where the key is the numeric based AniList identifier.</returns>
        public async Task <Dictionary <long, SeriesPage> > GetListOfSeriesPagesAsync(IEnumerable <long> anilistSeriesIds)
        {
            var result    = new Dictionary <long, SeriesPage>();
            var seriesIds = anilistSeriesIds.ToList();

            if (!seriesIds.Any())
            {
                return(null);
            }

            foreach (var anilistAnimeid in seriesIds)
            {
                var url = AniListApiHelper.GetUrl(AnilistTypes.Anime, QueryType.Page, anilistAnimeid);

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

                    if (rawAnime != null)
                    {
                        result.Add(rawAnime.id, SeriesPage.ConstructFromDto(rawAnime));
                    }
                }
                catch (Exception e)
                {
                    throw new Exception($"Failed to retrieve series. Error: {e}");
                }
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// Gets a dictionary of airing times.
        /// </summary>
        /// <param name="anilistAnimeId">The AniList numeric based identifier.</param>
        /// <returns>Returns a dictionary of airing times. The key is the episode number. The value is the UNIX timestamp.</returns>
        public async Task <Dictionary <string, long> > GetAnimeAiringTimesAsync(long anilistAnimeId)
        {
            var url = AniListApiHelper.GetUrl(AnilistTypes.Anime, QueryType.Airing, anilistAnimeId);

            try
            {
                return(await GenericGetAsync <Dictionary <string, long> >(url));
            }
            catch (Exception e)
            {
                throw new Exception($"Failed to retrieve next airing times. Error: {e}");
            }
        }
Пример #4
0
        /// <summary>
        /// Gets a single series page.
        /// </summary>
        /// <param name="anilistAnimeid">The AniList numeric based identifier.</param>
        /// <returns>Returns a single AniList series page.</returns>
        public async Task <SeriesPage> GetSeriesPageAsync(long anilistAnimeid)
        {
            var url = AniListApiHelper.GetUrl(AnilistTypes.Anime, QueryType.Page, anilistAnimeid);

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

                return(rawAnime != null?SeriesPage.ConstructFromDto(rawAnime) : null);
            }
            catch (Exception e)
            {
                throw new Exception($"Failed to retrieve series. Error: {e}");
            }
        }
Пример #5
0
        /// <summary>
        /// Gets a list of series.
        /// </summary>
        /// <param name="searchPhrase">The search used to find series.</param>
        /// <returns>Returns a list of series.</returns>
        public async Task <List <Series> > SearchSeriesAsync(string searchPhrase)
        {
            var url = HttpUtility.HtmlEncode(AniListApiHelper.GetUrl(AnilistTypes.Anime, QueryType.Search, searchPhrase));

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

                return(rawSeries?.Select(Series.ConstructFromDto).ToList());
            }
            catch (Exception e)
            {
                throw new Exception($"Failed to retrieve search. Error: {e}");
            }
        }
Пример #6
0
        /// <summary>
        /// Gets a list of all genres used on anilist.
        /// </summary>
        /// <returns>A list of string based genres</returns>
        public async Task <List <string> > GetGenreListAsync()
        {
            var url = HttpUtility.HtmlEncode(AniListApiHelper.GetUrl(AnilistTypes.GenreList, QueryType.Search, null));

            try
            {
                var rawGenreList = await GenericGetAsync <List <string> >(url);

                return(rawGenreList);
            }
            catch (Exception e)
            {
                throw new Exception($"Failed to retrieve search. Error: {e}");
            }
        }
Пример #7
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}");
            }
        }
Пример #8
0
        /// <summary>
        /// Gets a single studio.
        /// </summary>
        /// <param name="anilistStudioId">The AniList numeric based identifier.</param>
        /// <returns>Returns a single studio.</returns>
        public async Task <Studio> GetStudioAsync(long anilistStudioId)
        {
            var url = HttpUtility.HtmlEncode(AniListApiHelper.GetUrl(AnilistTypes.Studio, QueryType.Single, anilistStudioId));

            try
            {
                var rawStudio = await GenericGetAsync <StudioDTO>(url);

                return(Studio.ConstructFromDto(rawStudio));
            }
            catch (Exception e)
            {
                throw new Exception($"Failed to retrieve search. Error: {e}");
            }
        }
Пример #9
0
        /// <summary>
        /// Gets a single actor.
        /// </summary>
        /// <param name="anilistActorId">The AniList numeric based identifier.</param>
        /// <returns>Returns a single actor.</returns>
        public async Task <Actor> GetActorAsync(long anilistActorId)
        {
            var url = HttpUtility.HtmlEncode(AniListApiHelper.GetUrl(AnilistTypes.Actor, QueryType.Single, anilistActorId));

            try
            {
                var rawActor = await GenericGetAsync <ActorDTO>(url);

                return(Actor.ConstructFromDto(rawActor));
            }
            catch (Exception e)
            {
                throw new Exception($"Failed to retrieve search. Error: {e}");
            }
        }
Пример #10
0
        public static SeriesPage ConstructFromDto(SeriesPageDTO dto)
        {
            var seasonAndYear = dto.season != null?AniListApiHelper.GetSeasonType($"{dto.season}") : null;

            return(new SeriesPage()
            {
                Id = dto.id,
                TitleRomaji = dto.title_romaji,
                TitleEnglish = dto.title_english,
                TitleJapanese = dto.title_japanese,
                Type = dto.type?.GetEnumValue <MediaTypes>() ?? MediaTypes.NotFound,
                SeriesType = dto.series_type?.GetEnumValue <SeriesType>() ?? Types.SeriesType.NotFound,
                StartDate = dto.start_date,
                EndDate = dto.end_date,
                Season = seasonAndYear?.First().Value ?? Seasons.NotFound,
                Year = seasonAndYear?.First().Key,
                Description = dto.description,
                IsAdult = dto.adult,
                AverageScore = dto.average_score,
                Popularity = dto.popularity,
                IsFavourite = dto.favourite,
                ImageUrlSmall = dto.image_url_sml,
                ImageUrlMedium = dto.image_url_med,
                ImageUrlLarge = dto.image_url_lge,
                ImageUrlBanner = dto.image_url_banner,
                Genres = dto.genres?.Select(x => x.GetEnumValue <Genres>()).ToList(),
                Synonyms = dto.synonyms,
                YoutubeId = dto.youtube_id,
                Hashtag = dto.hashtag,
                UpdatedAt = dto.updated_at,
                ScoreDistribution = dto.score_distribution,
                ListStats = dto.list_stats,
                TotalEpisodes = dto.total_episodes,
                Duration = dto.duration,
                AiringStatus = dto.airing_status?.GetEnumValue <AiringStatus>() ?? Types.AiringStatus.NotFound,
                Source = dto.source?.GetEnumValue <AnimeSourceTypes>() ?? AnimeSourceTypes.Other,
                Classification = dto.classification,
                AiringStats = dto.airing_stats != null?ConvertAiringStatsDtoDictionaryToDictionary(dto.airing_stats) : null,
                                  Characters = dto.characters?.Select(BasicCharacter.ConstructFromDto).ToList(),
                                  Staff = dto.staff?.Select(BasicStaff.ConstructFromDto).ToList(),
                                  Studio = dto.studio?.Select(Models.Studio.ConstructFromDto).ToList(),
                                  ExternalLinks = dto.external_links?.Select(ExternalLink.ConstructFromDto).ToList(),
                                  Rankings = dto.rankings?.Select(Ranking.ConstructFromDto).ToList(),
                                  Relations = dto.relations?.Select(Relation.ConstructFromDto).ToList(),
                                  Tags = dto.tags?.Select(Tag.ConstructFromDto).ToList(),
                                  Airing = dto.airing != null?Models.Airing.ConstructFromDto(dto.airing) : null
            });
        }
Пример #11
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}");
            }
        }
Пример #12
0
        private async Task <bool> LoginAsync()
        {
            var paramaters = new List <KeyValuePair <string, string> >()
            {
                { "grant_type", _authGrantType },
                { "client_id", _authClientId },
                { "client_secret", _authClientSecret }
            };

            var url = AniListApiHelper.GetAuthUrl(paramaters);

            try
            {
                _authTicket = await GenericPostAsync <Authentication>(url, null);

                UpdateAuthHeader();
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }
Пример #13
0
 private void UpdateAuthHeader()
 {
     _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(AniListApiHelper.FirstCharToUpper(_authTicket.token_type), _authTicket.access_token);
 }
Пример #14
0
 private AniListApi()
 {
     _client = new HttpClient {
         BaseAddress = new Uri(AniListApiHelper.GetBaseUrl())
     };
 }