Example #1
0
        public async Task <string> GetRandomPoster()
        {
            var key = await _cache.GetOrAdd(CacheKeys.FanartTv, async() => await Config.GetAsync(Store.Entities.ConfigurationTypes.FanartTv), DateTime.Now.AddDays(1));

            var rand = new Random();
            var val  = rand.Next(1, 3);

            if (val == 1)
            {
                var movies             = (await _movieEngineV2.PopularMovies(0, 10, HttpContext.RequestAborted, "en")).ToArray();
                var selectedMovieIndex = rand.Next(movies.Count());
                var movie = movies[selectedMovieIndex];

                var images = await _cache.GetOrAdd($"{CacheKeys.FanartTv}movie{movie.Id}", async() => await FanartTvApi.GetMovieImages(movie.Id.ToString(), key.Value), DateTime.Now.AddDays(1));

                if (images == null)
                {
                    return(string.Empty);
                }

                if (images.movieposter?.Any() ?? false)
                {
                    var enImage = images.movieposter.Where(x => x.lang == "en").OrderByDescending(x => x.likes).Select(x => x.url).FirstOrDefault();
                    if (enImage == null)
                    {
                        return(images.movieposter.OrderByDescending(x => x.likes).Select(x => x.url).FirstOrDefault());
                    }
                    return(enImage);
                }

                if (images.moviethumb?.Any() ?? false)
                {
                    return(images.moviethumb.OrderBy(x => x.likes).Select(x => x.url).FirstOrDefault());
                }
            }
            else
            {
                var tv = (await _tvSearchEngineV2.Popular(0, 10, "en")).ToArray();
                var selectedMovieIndex = rand.Next(tv.Count());
                var selected           = tv[selectedMovieIndex];

                return($"https://image.tmdb.org/t/p/original{selected.BackdropPath}");
            }
            return("");
        }
Example #2
0
 public Task <IEnumerable <SearchTvShowViewModel> > PopularTv(int currentPosition, int amountToLoad)
 {
     return(_mediaCacheService.GetOrAddAsync(nameof(PopularTv) + currentPosition + amountToLoad,
                                             () => _tvEngineV2.Popular(currentPosition, amountToLoad),
                                             DateTimeOffset.Now.AddHours(12)));
 }
Example #3
0
 public async Task <IEnumerable <SearchTvShowViewModel> > PopularTv(int currentPosition, int amountToLoad)
 {
     return(await _tvEngineV2.Popular(currentPosition, amountToLoad));
 }