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);
        }
        public async Task <MetadataResult <Episode> > GetMetadata(EpisodeInfo info, CancellationToken cancellationToken)
        {
            var result = new MetadataResult <Episode>();

            cancellationToken.ThrowIfCancellationRequested();

            var anidbId = info.ProviderIds.GetOrDefault(ProviderNames.AniDb);

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

            var id = AniDbEpisodeIdentity.Parse(anidbId);

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

            var seriesFolder = await FindSeriesFolder(id.Value.SeriesId, cancellationToken);

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

            var xml = GetEpisodeXmlFile(id.Value.EpisodeNumber, id.Value.EpisodeType, seriesFolder);

            if (xml == null || !xml.Exists)
            {
                return(result);
            }

            result.Item = new Episode
            {
                IndexNumber       = info.IndexNumber,
                ParentIndexNumber = info.ParentIndexNumber
            };

            result.HasMetadata = true;

            await ParseEpisodeXml(xml, result.Item, info.MetadataLanguage).ConfigureAwait(false);

            if (id.Value.EpisodeNumberEnd != null && id.Value.EpisodeNumberEnd > id.Value.EpisodeNumber)
            {
                for (var i = id.Value.EpisodeNumber + 1; i <= id.Value.EpisodeNumberEnd; i++)
                {
                    var additionalXml = GetEpisodeXmlFile(i, id.Value.EpisodeType, seriesFolder);
                    if (additionalXml == null || !additionalXml.Exists)
                    {
                        continue;
                    }

                    await ParseAdditionalEpisodeXml(additionalXml, result.Item, info.MetadataLanguage).ConfigureAwait(false);
                }
            }

            return(result);
        }