Esempio n. 1
0
        private async Task EnrichWithSeriesDetailsId(List <EpisodeFile> newEpisodes)
        {
            var functionCache = new FunctionCache <string, Domain.Models.Details.Search.SeriesResult[]>(_detailsApi.SearchTvShows);

            foreach (var episodeFile in newEpisodes)
            {
                var searchResults = await functionCache.Invoke(episodeFile.Name);

                if (searchResults == null || !searchResults.Any())
                {
                    episodeFile.SeriesDetailsId = null;
                    continue;
                }

                var actual         = new Fastenshtein.Levenshtein(episodeFile.Name);
                var selectedResult = searchResults.OrderBy(sr => actual.DistanceFrom(sr.Name)).First();

                episodeFile.SeriesDetailsId = selectedResult.Id;
            }
        }
Esempio n. 2
0
        public async Task <DbFilmDetails[]> FindFilmDetails(IEnumerable <FilmFile> newFilm, Library library)
        {
            var allDetails    = new Dictionary <int, DbFilmDetails>();
            var functionCache = new FunctionCache <int, string, DbFilmDetails>(FetchFilmDetails);

            foreach (var filmFile in newFilm)
            {
                var searchResults = await _detailsApi.SearchMovies(filmFile.Title, filmFile.Year);

                if (!searchResults.Any())
                {
                    searchResults = await _detailsApi.SearchMovies(filmFile.Title, 0);
                }

                if (!searchResults.Any())
                {
                    filmFile.FilmDetailsId = null;
                    continue;
                }

                var actual         = new Fastenshtein.Levenshtein(filmFile.Title);
                var selectedResult = searchResults.OrderBy(sr => actual.DistanceFrom(sr.Title)).First();

                var details = await functionCache.Invoke(selectedResult.Id, library.Language);

                if (details == null)
                {
                    continue;
                }

                filmFile.FilmDetailsId = details.Id;
                allDetails[details.Id] = details;
            }

            return(allDetails.Values.ToArray());
        }