Beispiel #1
0
        static async Task Main(string[] args)
        {
            MovieService ms   = new MovieService();
            var          test = await ms.GetPopularMoviesPagenationAsync();

            var movieDetail = await ms.GetMovieDetailAsync(516486);

            ActorService actorS = new ActorService();
            var          testAs = await actorS.GetMovieActorDetail(85);

            MultiSearchService msServ = new MultiSearchService();
            var testMser = await msServ.MultiSearch("The Flash");

            TvShowsService tvSer = new TvShowsService();
            var            tvPop = await tvSer.GetPopularTVShowsPagenationAsync();

            var test123 = await tvSer.GetTVShowDetailsAsync(1668);

            Console.WriteLine();
        }
        public object Get(GetTvView request)
        {
            var romanceGenres = request.RomanceGenre.Split(',').ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
            var comedyGenres  = request.ComedyGenre.Split(',').ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);

            var user = _userManager.GetUserById(request.UserId);

            var series = user.RootFolder.GetRecursiveChildren(user)
                         .OfType <Series>()
                         .ToList();

            var seriesWithBackdrops = series.Where(i => i.BackdropImagePaths.Count > 0).ToList();

            var view = new TvView();

            SetFavoriteGenres(view, series, user);
            SetFavoriteStudios(view, series, user);

            var fields = new List <ItemFields>();

            var seriesWithBestBackdrops = FilterItemsForBackdropDisplay(seriesWithBackdrops).ToList();

            view.BackdropItems = seriesWithBestBackdrops
                                 .OrderBy(i => Guid.NewGuid())
                                 .Take(10)
                                 .AsParallel()
                                 .Select(i => _dtoService.GetBaseItemDto(i, fields, user))
                                 .ToList();

            view.ShowsItems = series
                              .Where(i => i.BackdropImagePaths.Count > 0)
                              .OrderBy(i => Guid.NewGuid())
                              .Select(i => GetItemStub(i, ImageType.Backdrop))
                              .Where(i => i != null)
                              .Take(1)
                              .ToList();

            view.RomanceItems = seriesWithBackdrops
                                .Where(i => i.Genres.Any(romanceGenres.ContainsKey))
                                .OrderBy(i => Guid.NewGuid())
                                .Select(i => GetItemStub(i, ImageType.Backdrop))
                                .Where(i => i != null)
                                .Take(1)
                                .ToList();

            view.ComedyItems = seriesWithBackdrops
                               .Where(i => i.Genres.Any(comedyGenres.ContainsKey))
                               .OrderBy(i => Guid.NewGuid())
                               .Select(i => GetItemStub(i, ImageType.Backdrop))
                               .Where(i => i != null)
                               .Take(1)
                               .ToList();

            view.ActorItems = GetActors(series, user.Id);

            var spotlightSeries = seriesWithBestBackdrops
                                  .Where(i => i.CommunityRating.HasValue && i.CommunityRating >= 8.5)
                                  .ToList();

            if (spotlightSeries.Count < 20)
            {
                spotlightSeries = seriesWithBestBackdrops;
            }

            spotlightSeries = spotlightSeries
                              .OrderBy(i => Guid.NewGuid())
                              .Take(10)
                              .ToList();

            view.SpotlightItems = spotlightSeries
                                  .AsParallel()
                                  .Select(i => _dtoService.GetBaseItemDto(i, fields, user))
                                  .ToList();

            var miniSpotlightItems = seriesWithBackdrops
                                     .Except(spotlightSeries.OfType <Series>())
                                     .Where(i => i.CommunityRating.HasValue && i.CommunityRating >= 8)
                                     .ToList();

            if (miniSpotlightItems.Count < 15)
            {
                miniSpotlightItems = seriesWithBackdrops;
            }

            view.MiniSpotlights = miniSpotlightItems
                                  .OrderBy(i => Guid.NewGuid())
                                  .Take(5)
                                  .Select(i => _dtoService.GetBaseItemDto(i, fields, user))
                                  .ToList();

            var nextUpEpisodes = new TvShowsService(_userManager, _userDataManager, _libraryManager, _itemRepo, _dtoService)
                                 .GetNextUpEpisodes(new GetNextUpEpisodes {
                UserId = user.Id
            }, series)
                                 .ToList();

            fields.Add(ItemFields.PrimaryImageAspectRatio);

            view.NextUpEpisodes = nextUpEpisodes
                                  .Take(request.NextUpEpisodeLimit)
                                  .Select(i => _dtoService.GetBaseItemDto(i, fields, user))
                                  .ToList();

            view.SeriesIdsInProgress = nextUpEpisodes.Select(i => i.Series.Id.ToString("N")).ToList();

            var ownedEpisodes = series
                                .SelectMany(i => i.GetRecursiveChildren(user, j => j.LocationType != LocationType.Virtual))
                                .OfType <Episode>()
                                .ToList();

            // Avoid implicitly captured closure
            var currentUser = user;

            view.LatestEpisodes = ownedEpisodes
                                  .OrderByDescending(i => i.DateCreated)
                                  .Where(i => !_userDataManager.GetUserData(currentUser.Id, i.GetUserDataKey()).Played)
                                  .Take(request.LatestEpisodeLimit)
                                  .Select(i => _dtoService.GetBaseItemDto(i, fields, user))
                                  .ToList();

            view.ResumableEpisodes = ownedEpisodes
                                     .Where(i => _userDataManager.GetUserData(currentUser.Id, i.GetUserDataKey()).PlaybackPositionTicks > 0)
                                     .OrderByDescending(i => _userDataManager.GetUserData(currentUser.Id, i.GetUserDataKey()).LastPlayedDate ?? DateTime.MinValue)
                                     .Take(request.ResumableEpisodeLimit)
                                     .Select(i => _dtoService.GetBaseItemDto(i, fields, user))
                                     .ToList();

            return(ToOptimizedResult(view));
        }
Beispiel #3
0
 public ShowsController(TvShowsService tvShowsService)
 {
     _tvShowsService = tvShowsService;
 }