コード例 #1
0
        public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(EpisodeInfo searchInfo, CancellationToken cancellationToken)
        {
            var list = new List <RemoteSearchResult>();

            var id = AnidbEpisodeIdentity.Parse(searchInfo.ProviderIds.GetOrDefault(ProviderNames.AniDb));

            if (id == null)
            {
                //var episodeIdentifier = new AnidbEpisodeIdentityProvider();
                //await episodeIdentifier.Identify(searchInfo);

                //var converter = new AnidbTvdbEpisodeConverter();
                //await converter.Convert(searchInfo);

                //id = AnidbEpisodeIdentity.Parse(searchInfo.ProviderIds.GetOrDefault(ProviderNames.AniDb));
            }

            if (id == null)
            {
                return(list);
            }

            await AniDbSeriesProvider.GetSeriesData(_configurationManager.ApplicationPaths, _httpClient, id.Value.SeriesId,
                                                    cancellationToken).ConfigureAwait(false);

            try
            {
                var metadataResult = await GetMetadata(searchInfo, cancellationToken).ConfigureAwait(false);

                if (metadataResult.HasMetadata)
                {
                    var item = metadataResult.Item;

                    list.Add(new RemoteSearchResult
                    {
                        IndexNumber        = item.IndexNumber,
                        Name               = item.Name,
                        ParentIndexNumber  = item.ParentIndexNumber,
                        PremiereDate       = item.PremiereDate,
                        ProductionYear     = item.ProductionYear,
                        ProviderIds        = item.ProviderIds,
                        SearchProviderName = Name,
                        IndexNumberEnd     = item.IndexNumberEnd
                    });
                }
            }
            catch (FileNotFoundException)
            {
                // Don't fail the provider because this will just keep on going and going.
            }
            catch (DirectoryNotFoundException)
            {
                // Don't fail the provider because this will just keep on going and going.
            }

            return(list);
        }
コード例 #2
0
        public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(EpisodeInfo searchInfo, CancellationToken cancellationToken)
        {
            var list = new List <RemoteSearchResult>();

            var anidbId = searchInfo.SeriesProviderIds.GetOrDefault(ProviderNames.AniDb);

            if (string.IsNullOrEmpty(anidbId))
            {
                return(list);
            }

            await AniDbSeriesProvider.GetSeriesData(_configurationManager.ApplicationPaths, _httpClient, anidbId, cancellationToken).ConfigureAwait(false);

            try
            {
                var metadataResult = await GetMetadata(searchInfo, cancellationToken).ConfigureAwait(false);

                if (metadataResult.HasMetadata)
                {
                    var item = metadataResult.Item;

                    list.Add(new RemoteSearchResult
                    {
                        IndexNumber        = item.IndexNumber,
                        Name               = item.Name,
                        ParentIndexNumber  = item.ParentIndexNumber,
                        PremiereDate       = item.PremiereDate,
                        ProductionYear     = item.ProductionYear,
                        ProviderIds        = item.ProviderIds,
                        SearchProviderName = Name,
                        IndexNumberEnd     = item.IndexNumberEnd
                    });
                }
            }
            catch (FileNotFoundException)
            {
                // Don't fail the provider because this will just keep on going and going.
            }
            catch (DirectoryNotFoundException)
            {
                // Don't fail the provider because this will just keep on going and going.
            }

            return(list);
        }
コード例 #3
0
        public Task <IEnumerable <RemoteImageInfo> > GetImages(IHasImages item, CancellationToken cancellationToken)
        {
            var infos = new List <RemoteImageInfo>();

            var person = AniDbSeriesProvider.GetPersonInfo(_paths.CachePath, item.Name);

            if (person != null)
            {
                infos.Add(new RemoteImageInfo
                {
                    Url          = person.Image,
                    Type         = ImageType.Primary,
                    ProviderName = Name
                });
            }

            return(Task.FromResult <IEnumerable <RemoteImageInfo> >(infos));
        }
コード例 #4
0
        public Task <MetadataResult <Person> > GetMetadata(PersonLookupInfo info, CancellationToken cancellationToken)
        {
            var result = new MetadataResult <Person>();

            if (!string.IsNullOrEmpty(info.ProviderIds.GetOrDefault(ProviderNames.AniDb)))
            {
                return(Task.FromResult(result));
            }

            var person = AniDbSeriesProvider.GetPersonInfo(_paths.CachePath, info.Name);

            if (!string.IsNullOrEmpty(person?.Id))
            {
                result.Item        = new Person();
                result.HasMetadata = true;

                result.Item.SetProviderId(ProviderNames.AniDb, person.Id);
            }

            return(Task.FromResult(result));
        }
コード例 #5
0
        public async Task <IEnumerable <RemoteImageInfo> > GetImages(string aniDbId, CancellationToken cancellationToken)
        {
            var list = new List <RemoteImageInfo>();

            if (!string.IsNullOrEmpty(aniDbId))
            {
                var seriesDataPath = await AniDbSeriesProvider.GetSeriesData(_appPaths, _httpClient, aniDbId, cancellationToken);

                var imageUrl = FindImageUrl(seriesDataPath);

                if (!string.IsNullOrEmpty(imageUrl))
                {
                    list.Add(new RemoteImageInfo
                    {
                        ProviderName = Name,
                        Url          = imageUrl
                    });
                }
            }

            return(list);
        }
コード例 #6
0
 public AniDbSeasonProvider(IHttpClient httpClient, IApplicationPaths appPaths)
 {
     _seriesProvider = new AniDbSeriesProvider(appPaths, httpClient);
 }
コード例 #7
0
        private async Task <string> FindSeriesFolder(string seriesId, CancellationToken cancellationToken)
        {
            var seriesDataPath = await AniDbSeriesProvider.GetSeriesData(_configurationManager.ApplicationPaths, _httpClient, seriesId, cancellationToken).ConfigureAwait(false);

            return(Path.GetDirectoryName(seriesDataPath));
        }
コード例 #8
0
        private void ParseEpisodeXml(FileInfo xml, Episode episode, string preferredMetadataLanguage)
        {
            var settings = new XmlReaderSettings
            {
                CheckCharacters = false,
                IgnoreProcessingInstructions = true,
                IgnoreComments = true,
                ValidationType = ValidationType.None
            };

            using (var streamReader = xml.OpenText())
                using (var reader = XmlReader.Create(streamReader, settings))
                {
                    reader.MoveToContent();

                    var titles = new List <Title>();

                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            switch (reader.Name)
                            {
                            case "length":
                                var length = reader.ReadElementContentAsString();
                                if (!string.IsNullOrEmpty(length))
                                {
                                    long duration;
                                    if (long.TryParse(length, out duration))
                                    {
                                        episode.RunTimeTicks = TimeSpan.FromMinutes(duration).Ticks;
                                    }
                                }

                                break;

                            case "airdate":
                                var airdate = reader.ReadElementContentAsString();
                                if (!string.IsNullOrEmpty(airdate))
                                {
                                    DateTime date;
                                    if (DateTime.TryParse(airdate, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out date))
                                    {
                                        episode.PremiereDate   = date;
                                        episode.ProductionYear = date.Year;
                                    }
                                }

                                break;

                            case "rating":
                                int   count;
                                float rating;
                                if (int.TryParse(reader.GetAttribute("votes"), NumberStyles.Any, CultureInfo.InvariantCulture, out count) &&
                                    float.TryParse(reader.ReadElementContentAsString(), NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out rating))
                                {
                                    episode.CommunityRating = (float)Math.Round(rating, 1);
                                }

                                break;

                            case "title":
                                var language = reader.GetAttribute("xml:lang");
                                var name     = reader.ReadElementContentAsString();

                                titles.Add(new Title
                                {
                                    Language = language,
                                    Type     = "main",
                                    Name     = name
                                });

                                break;

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

                                break;
                            }
                        }
                    }

                    var title = titles.Localize(Plugin.Instance.Configuration.TitlePreference, preferredMetadataLanguage).Name;
                    if (!string.IsNullOrEmpty(title))
                    {
                        episode.Name = title;
                    }
                }
        }