Ejemplo n.º 1
0
        public async Task <List <MultiSearchResult> > MultiSearch(string searchTerm, MultiSearchFilter filter, CancellationToken cancellationToken)
        {
            var lang = await DefaultLanguageCode(null);

            var model = new List <MultiSearchResult>();

            var movieDbData = (await _movieDbApi.MultiSearch(searchTerm, lang, cancellationToken)).results;

            var lidarrSettings = await _lidarrSettings.GetSettingsAsync();

            if (lidarrSettings.Enabled && filter.Music)
            {
                var artistResult = await _musicApi.SearchArtist(searchTerm);

                foreach (var artist in artistResult)
                {
                    model.Add(new MultiSearchResult
                    {
                        MediaType = "Artist",
                        Title     = artist.Name,
                        Id        = artist.Id
                    });
                }
            }

            foreach (var multiSearch in movieDbData)
            {
                if (DemoCheck(multiSearch.title) || DemoCheck(multiSearch.name))
                {
                    continue;
                }

                var result = new MultiSearchResult
                {
                    MediaType = multiSearch.media_type,
                    Poster    = multiSearch.poster_path,
                    Overview  = multiSearch.overview
                };

                if (multiSearch.media_type.Equals("movie", StringComparison.InvariantCultureIgnoreCase) && filter.Movies)
                {
                    if (multiSearch.release_date.HasValue() && DateTime.TryParse(multiSearch.release_date, out var releaseDate))
                    {
                        result.Title = $"{multiSearch.title} ({releaseDate.Year})";
                    }
                    else
                    {
                        result.Title = multiSearch.title;
                    }
                }

                else if (multiSearch.media_type.Equals("tv", StringComparison.InvariantCultureIgnoreCase) && filter.TvShows)
                {
                    if (multiSearch.release_date.HasValue() && DateTime.TryParse(multiSearch.release_date, out var releaseDate))
                    {
                        result.Title = $"{multiSearch.name} ({releaseDate.Year})";
                    }
                    else
                    {
                        result.Title = multiSearch.name;
                    }
                }
                else if (multiSearch.media_type.Equals("person", StringComparison.InvariantCultureIgnoreCase) && filter.People)
                {
                    result.Title = multiSearch.name;
                }
                else
                {
                    continue;
                }

                result.Id = multiSearch.id.ToString();
                model.Add(result);
            }

            return(model);
        }
Ejemplo n.º 2
0
 public async Task <List <MultiSearchResult> > MultiSearch(string searchTerm, [FromBody] MultiSearchFilter filter)
 {
     return(await _multiSearchEngine.MultiSearch(Uri.UnescapeDataString(searchTerm), filter, Request.HttpContext.RequestAborted));
 }