public async Task <MetadataResult <Series> > GetMetadata(SeriesInfo info, CancellationToken cancellationToken)
        {
            var result = new MetadataResult <Series>();

            var aid = info.ProviderIds.GetOrDefault(ProviderNames.AniList);

            if (string.IsNullOrEmpty(aid))
            {
                return(result);
            }

            if (!string.IsNullOrEmpty(aid))
            {
                result.Item        = new Series();
                result.HasMetadata = true;

                result.Item.ProviderIds.Add(ProviderNames.AniList, aid);

                var anime = await _api.GetAnime(aid);

                result.Item.Name     = SelectName(anime, PluginConfiguration.Instance().TitlePreference, info.MetadataLanguage ?? "en");
                result.Item.Overview = anime.description;

                DateTime start;
                if (DateTime.TryParse(anime.start_date, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out start))
                {
                    result.Item.PremiereDate = start;
                }

                DateTime end;
                if (DateTime.TryParse(anime.end_date, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out end))
                {
                    result.Item.EndDate = end;
                }

                if (anime.genres != null)
                {
                    foreach (var genre in anime.genres)
                    {
                        result.Item.AddGenre(genre);
                    }

                    GenreHelper.CleanupGenres(result.Item);
                    GenreHelper.RemoveDuplicateTags(result.Item);
                }

                if (!string.IsNullOrEmpty(anime.image_url_lge))
                {
                    StoreImageUrl(aid, anime.image_url_lge, "image");
                }

                if (!string.IsNullOrEmpty(anime.image_url_banner))
                {
                    StoreImageUrl(aid, anime.image_url_banner, "banner");
                }
            }

            return(result);
        }
        public async Task <MetadataResult <Series> > GetMetadata(SeriesInfo info, CancellationToken cancellationToken)
        {
            var result = new MetadataResult <Series>();

            var aid = info.GetProviderId(provider_name);

            if (string.IsNullOrEmpty(aid))
            {
                _log.Info("Start MyAnimeList... Searching(" + info.Name + ")");
                aid = await _api.FindSeries(info.Name, cancellationToken);
            }

            if (!string.IsNullOrEmpty(aid))
            {
                string WebContent = await _api.WebRequestAPI(_api.anime_link + aid, cancellationToken);

                result.Item        = new Series();
                result.HasMetadata = true;

                result.Item.SetProviderId(provider_name, aid);
                result.Item.Name = await _api.SelectName(WebContent, Plugin.Instance.Configuration.TitlePreference, "en", cancellationToken);

                result.Item.Overview = await _api.Get_OverviewAsync(WebContent);

                result.ResultLanguage = "eng";
                try
                {
                    result.Item.CommunityRating = float.Parse(await _api.Get_RatingAsync(WebContent), System.Globalization.CultureInfo.InvariantCulture);
                }
                catch (Exception) { }
                foreach (var genre in await _api.Get_GenreAsync(WebContent))
                {
                    if (!string.IsNullOrEmpty(genre))
                    {
                        result.Item.AddGenre(genre);
                    }
                }
                GenreHelper.CleanupGenres(result.Item);
                StoreImageUrl(aid, await _api.Get_ImageUrlAsync(WebContent), "image");
            }
            return(result);
        }
        public async Task <MetadataResult <MediaBrowser.Controller.Entities.TV.Series> > GetMetadata(SeriesInfo info, CancellationToken cancellationToken)
        {
            var result = new MetadataResult <MediaBrowser.Controller.Entities.TV.Series>();

            var kitsuId = info.ProviderIds.GetOrDefault(ProviderNames.KitsuIo);

            if (string.IsNullOrEmpty(kitsuId))
            {
                _log.LogInformation("Start KitsuIo... Searching({Name})", info.Name);
                var filters     = GetFiltersFromSeriesInfo(info);
                var apiResponse = await KitsuIoApi.Search_Series(filters);

                kitsuId = apiResponse.Data.FirstOrDefault(x => x.Attributes.Titles.Equal(info.Name))?.Id.ToString();
            }

            if (!string.IsNullOrEmpty(kitsuId))
            {
                var seriesInfo = await KitsuIoApi.Get_Series(kitsuId);

                result.HasMetadata = true;
                result.Item        = new MediaBrowser.Controller.Entities.TV.Series
                {
                    Overview = seriesInfo.Data.Attributes.Synopsis,
                    // KitsuIO has a max rating of 100
                    CommunityRating = string.IsNullOrWhiteSpace(seriesInfo.Data.Attributes.AverageRating)
                        ? null
                        : (float?)float.Parse(seriesInfo.Data.Attributes.AverageRating, System.Globalization.CultureInfo.InvariantCulture) / 10,
                    ProviderIds = new Dictionary <string, string>()
                    {
                        { ProviderNames.KitsuIo, kitsuId }
                    },
                    Genres = seriesInfo.Included?.Select(x => x.Attributes.Name).ToArray()
                             ?? Array.Empty <string>()
                };
                GenreHelper.CleanupGenres(result.Item);
                StoreImageUrl(kitsuId, seriesInfo.Data.Attributes.PosterImage.Original.ToString(), "image");
            }

            return(result);
        }
Exemple #4
0
        public async Task <MetadataResult <Series> > GetMetadata(SeriesInfo info, CancellationToken cancellationToken)
        {
            var result = new MetadataResult <Series>();

            var aid = info.ProviderIds.GetOrDefault(ProviderNames.AniList);

            if (string.IsNullOrEmpty(aid))
            {
                _log.LogInformation("Start AniList... Searching({Name})", info.Name);
                aid = await _aniListApi.FindSeries(info.Name, cancellationToken);
            }

            if (!string.IsNullOrEmpty(aid))
            {
                RootObject WebContent = await _aniListApi.WebRequestAPI(_aniListApi.AniList_anime_link.Replace("{0}", aid));

                result.Item        = new Series();
                result.HasMetadata = true;

                result.People = await _aniListApi.GetPersonInfo(WebContent.data.Media.id, cancellationToken);

                result.Item.ProviderIds.Add(ProviderNames.AniList, aid);
                result.Item.Overview = WebContent.data.Media.description;
                try
                {
                    //AniList has a max rating of 5
                    result.Item.CommunityRating = WebContent.data.Media.averageScore / 10;
                }
                catch (Exception) { }
                foreach (var genre in _aniListApi.Get_Genre(WebContent))
                {
                    result.Item.AddGenre(genre);
                }
                GenreHelper.CleanupGenres(result.Item);
                StoreImageUrl(aid, WebContent.data.Media.coverImage.large, "image");
            }

            return(result);
        }
        public async Task <MetadataResult <Series> > GetMetadata(SeriesInfo info, CancellationToken cancellationToken)
        {
            var result = new MetadataResult <Series>();

            var aid = info.ProviderIds.GetOrDefault(ProviderNames.AniSearch);

            if (string.IsNullOrEmpty(aid))
            {
                _log.LogInformation("Start AniSearch... Searching({Name})", info.Name);
                aid = await AniSearchApi.FindSeries(info.Name, cancellationToken);
            }

            if (!string.IsNullOrEmpty(aid))
            {
                string WebContent = await AniSearchApi.WebRequestAPI(AniSearchApi.AniSearch_anime_link + aid);

                result.Item        = new Series();
                result.HasMetadata = true;

                result.Item.ProviderIds.Add(ProviderNames.AniSearch, aid);
                result.Item.Overview = await AniSearchApi.Get_Overview(WebContent);

                try
                {
                    //AniSearch has a max rating of 5
                    result.Item.CommunityRating = (float.Parse(await AniSearchApi.Get_Rating(WebContent), System.Globalization.CultureInfo.InvariantCulture) * 2);
                }
                catch (Exception) { }
                foreach (var genre in await AniSearchApi.Get_Genre(WebContent))
                {
                    result.Item.AddGenre(genre);
                }
                GenreHelper.CleanupGenres(result.Item);
                StoreImageUrl(aid, await AniSearchApi.Get_ImageUrl(WebContent), "image");
            }
            return(result);
        }
Exemple #6
0
        public async Task <MetadataResult <Series> > GetMetadata(SeriesInfo info, CancellationToken cancellationToken)
        {
            var result = new MetadataResult <Series>();

            var aid = info.ProviderIds.GetOrDefault(provider_name);

            if (string.IsNullOrEmpty(aid))
            {
                _log.Info("Start Proxer... Searching(" + info.Name + ")");
                aid = await Api.FindSeries(info.Name, cancellationToken);
            }

            if (!string.IsNullOrEmpty(aid))
            {
                string WebContent = await Api.WebRequestAPI(Api.Proxer_anime_link + aid);

                result.Item        = new Series();
                result.HasMetadata = true;

                result.Item.ProviderIds.Add(provider_name, aid);
                result.Item.Overview = await Api.Get_Overview(WebContent);

                result.ResultLanguage = "ger";
                try
                {
                    result.Item.CommunityRating = float.Parse(await Api.Get_Rating(WebContent), System.Globalization.CultureInfo.InvariantCulture);
                }
                catch (Exception) { }
                foreach (var genre in await Api.Get_Genre(WebContent))
                {
                    result.Item.AddGenre(genre);
                }
                GenreHelper.CleanupGenres(result.Item);
                StoreImageUrl(aid, await Api.Get_ImageUrl(WebContent), "image");
            }
            return(result);
        }
        private void FetchSeriesInfo(MetadataResult <Series> result, string seriesDataPath, string preferredMetadataLangauge)
        {
            var series   = result.Item;
            var settings = new XmlReaderSettings
            {
                CheckCharacters = false,
                IgnoreProcessingInstructions = true,
                IgnoreComments = true,
                ValidationType = ValidationType.None
            };

            using (var streamReader = File.Open(seriesDataPath, FileMode.Open, FileAccess.Read))
                using (var reader = XmlReader.Create(streamReader, settings))
                {
                    reader.MoveToContent();

                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            switch (reader.Name)
                            {
                            case "startdate":
                                var val = reader.ReadElementContentAsString();

                                if (!string.IsNullOrWhiteSpace(val))
                                {
                                    if (DateTime.TryParse(val, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out DateTime date))
                                    {
                                        date = date.ToUniversalTime();
                                        series.PremiereDate   = date;
                                        series.ProductionYear = date.Year;
                                    }
                                }

                                break;

                            case "enddate":
                                var endDate = reader.ReadElementContentAsString();

                                if (!string.IsNullOrWhiteSpace(endDate))
                                {
                                    if (DateTime.TryParse(endDate, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out DateTime date))
                                    {
                                        date           = date.ToUniversalTime();
                                        series.EndDate = date;
                                        if (DateTime.Now.Date < date.Date)
                                        {
                                            series.Status = SeriesStatus.Continuing;
                                        }
                                        else
                                        {
                                            series.Status = SeriesStatus.Ended;
                                        }
                                    }
                                }

                                break;

                            case "titles":
                                using (var subtree = reader.ReadSubtree())
                                {
                                    var title = ParseTitle(subtree, preferredMetadataLangauge);
                                    if (!string.IsNullOrEmpty(title))
                                    {
                                        series.Name = title;
                                    }
                                }

                                break;

                            case "creators":
                                using (var subtree = reader.ReadSubtree())
                                {
                                    ParseCreators(result, subtree);
                                }

                                break;

                            case "description":
                                series.Overview = ReplaceLineFeedWithNewLine(StripAniDbLinks(reader.ReadElementContentAsString()).Split(new[] { "Source:", "Note:" }, StringSplitOptions.None)[0]);

                                break;

                            case "ratings":
                                using (var subtree = reader.ReadSubtree())
                                {
                                    ParseRatings(series, subtree);
                                }

                                break;

                            case "resources":
                                using (var subtree = reader.ReadSubtree())
                                {
                                    ParseResources(series, subtree);
                                }

                                break;

                            case "characters":
                                using (var subtree = reader.ReadSubtree())
                                {
                                    ParseActors(result, subtree);
                                }

                                break;

                            case "tags":
                                using (var subtree = reader.ReadSubtree())
                                {
                                    ParseTags(series, subtree);
                                }

                                break;

                            case "categories":
                                using (var subtree = reader.ReadSubtree())
                                {
                                }

                                break;

                            case "episodes":
                                using (var subtree = reader.ReadSubtree())
                                {
                                    ParseEpisodes(series, subtree);
                                }

                                break;
                            }
                        }
                    }
                }
            if (series.EndDate == null)
            {
                series.Status = SeriesStatus.Continuing;
            }

            GenreHelper.CleanupGenres(series);
        }
        private async Task FetchSeriesInfo(MetadataResult <Series> result, string seriesDataPath, string preferredMetadataLangauge)
        {
            var series   = result.Item;
            var settings = new XmlReaderSettings
            {
                Async           = true,
                CheckCharacters = false,
                IgnoreProcessingInstructions = true,
                IgnoreComments = true,
                ValidationType = ValidationType.None
            };

            using (var streamReader = File.Open(seriesDataPath, FileMode.Open, FileAccess.Read))
                using (var reader = XmlReader.Create(streamReader, settings))
                {
                    await reader.MoveToContentAsync().ConfigureAwait(false);

                    while (await reader.ReadAsync().ConfigureAwait(false))
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            switch (reader.Name)
                            {
                            case "startdate":
                                var val = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false);

                                if (!string.IsNullOrWhiteSpace(val))
                                {
                                    if (DateTime.TryParse(val, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out DateTime date))
                                    {
                                        date = date.ToUniversalTime();
                                        series.PremiereDate = date;
                                    }
                                }

                                break;

                            case "enddate":
                                var endDate = await reader.ReadElementContentAsStringAsync().ConfigureAwait(false);

                                if (!string.IsNullOrWhiteSpace(endDate))
                                {
                                    if (DateTime.TryParse(endDate, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out DateTime date))
                                    {
                                        date           = date.ToUniversalTime();
                                        series.EndDate = date;
                                    }
                                }

                                break;

                            case "titles":
                                using (var subtree = reader.ReadSubtree())
                                {
                                    var title = await ParseTitle(subtree, preferredMetadataLangauge).ConfigureAwait(false);

                                    if (!string.IsNullOrEmpty(title))
                                    {
                                        series.Name = title;
                                    }
                                }

                                break;

                            case "creators":
                                using (var subtree = reader.ReadSubtree())
                                {
                                    await ParseCreators(result, subtree).ConfigureAwait(false);
                                }

                                break;

                            case "description":
                                series.Overview = ReplaceLineFeedWithNewLine(
                                    StripAniDbLinks(
                                        await reader.ReadElementContentAsStringAsync().ConfigureAwait(false)));

                                break;

                            case "ratings":
                                using (var subtree = reader.ReadSubtree())
                                {
                                    ParseRatings(series, subtree);
                                }

                                break;

                            case "resources":
                                using (var subtree = reader.ReadSubtree())
                                {
                                    await ParseResources(series, subtree).ConfigureAwait(false);
                                }

                                break;

                            case "characters":
                                using (var subtree = reader.ReadSubtree())
                                {
                                    await ParseActors(result, subtree).ConfigureAwait(false);
                                }

                                break;

                            case "tags":
                                using (var subtree = reader.ReadSubtree())
                                {
                                    await ParseTags(series, subtree).ConfigureAwait(false);
                                }

                                break;

                            case "episodes":
                                using (var subtree = reader.ReadSubtree())
                                {
                                    await ParseEpisodes(series, subtree).ConfigureAwait(false);
                                }

                                break;
                            }
                        }
                    }
                }

            GenreHelper.CleanupGenres(series);
        }
Exemple #9
0
        public async Task <MetadataResult <Series> > GetMetadata(SeriesInfo info, CancellationToken cancellationToken)
        {
            var result = new MetadataResult <Series>();

            var aid = info.ProviderIds.GetOrDefault(ProviderNames.AniList);

            if (string.IsNullOrEmpty(aid) && !string.IsNullOrEmpty(info.Name))
            {
                var search = await _api.Search(info.Name);

                foreach (var a in search)
                {
                    if (string.IsNullOrEmpty(aid))
                    {
                        if (Equals_check.Compare_strings(a.title_english, info.Name))
                        {
                            aid = a.id.ToString();
                        }

                        if (Equals_check.Compare_strings(a.title_japanese, info.Name))
                        {
                            aid = a.id.ToString();
                        }

                        if (Equals_check.Compare_strings(a.title_romaji, info.Name))
                        {
                            aid = a.id.ToString();
                        }
                        _log.Log(LogSeverity.Info, a.title_romaji + "vs" + info.Name);
                    }
                }
                if (string.IsNullOrEmpty(aid))
                {
                    var cleaned = AniDbTitleMatcher.GetComparableName(Equals_check.clear_name(info.Name));
                    if (String.Compare(cleaned, info.Name, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        search = await _api.Search(cleaned);

                        foreach (var b in search)
                        {
                            if (Equals_check.Compare_strings(b.title_english, info.Name))
                            {
                                aid = b.id.ToString();
                            }

                            if (Equals_check.Compare_strings(b.title_japanese, info.Name))
                            {
                                aid = b.id.ToString();
                            }

                            if (Equals_check.Compare_strings(b.title_romaji, info.Name))
                            {
                                aid = b.id.ToString();
                            }
                        }
                    }
                }
                if (string.IsNullOrEmpty(aid))
                {
                    search = await _api.Search(Equals_check.clear_name(info.Name));

                    foreach (var b in search)
                    {
                        if (Equals_check.Compare_strings(b.title_english, info.Name))
                        {
                            aid = b.id.ToString();
                        }

                        if (Equals_check.Compare_strings(b.title_japanese, info.Name))
                        {
                            aid = b.id.ToString();
                        }

                        if (Equals_check.Compare_strings(b.title_romaji, info.Name))
                        {
                            aid = b.id.ToString();
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(aid))
            {
                result.Item        = new Series();
                result.HasMetadata = true;

                result.Item.ProviderIds.Add(ProviderNames.AniList, aid);

                var anime = await _api.GetAnime(aid);

                result.Item.Name     = SelectName(anime, Plugin.Instance.Configuration.TitlePreference, info.MetadataLanguage ?? "en");
                result.Item.Overview = anime.description;

                DateTime start;
                if (DateTime.TryParse(anime.start_date, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out start))
                {
                    result.Item.PremiereDate = start;
                }

                DateTime end;
                if (DateTime.TryParse(anime.end_date, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out end))
                {
                    result.Item.EndDate = end;
                }

                if (anime.genres != null)
                {
                    foreach (var genre in anime.genres)
                    {
                        if (!string.IsNullOrEmpty(genre))
                        {
                            result.Item.AddGenre(genre);
                        }
                    }

                    GenreHelper.CleanupGenres(result.Item);
                }

                if (!string.IsNullOrEmpty(anime.image_url_lge))
                {
                    StoreImageUrl(aid, anime.image_url_lge, "image");
                }

                if (!string.IsNullOrEmpty(anime.image_url_banner))
                {
                    StoreImageUrl(aid, anime.image_url_banner, "banner");
                }

                if (string.IsNullOrEmpty(result.Item.Name))
                {
                    if (!string.IsNullOrEmpty(anime.title_romaji))
                    {
                        result.Item.Name = anime.title_romaji;
                    }
                }
            }

            return(result);
        }