Ejemplo n.º 1
0
        public async Task <SearchFullInfoTvShowViewModel> GetShowInformation(string tvdbid, CancellationToken token)
        {
            var langCode = await DefaultLanguageCode(null);

            var show = await Cache.GetOrAddAsync(nameof(GetShowInformation) + langCode + tvdbid,
                                                 async() => await _movieApi.GetTVInfo(tvdbid, langCode), DateTimeOffset.Now.AddHours(12));

            if (show == null || show.name == null)
            {
                // We don't have enough information
                return(null);
            }

            if (!show.Images?.Posters?.Any() ?? false && !string.Equals(langCode, "en", StringComparison.OrdinalIgnoreCase))
            {
                // There's no regional assets for this, so
                // lookup the en-us version to get them
                var enShow = await Cache.GetOrAddAsync(nameof(GetShowInformation) + "en" + tvdbid,
                                                       async() => await _movieApi.GetTVInfo(tvdbid, "en"), DateTimeOffset.Now.AddHours(12));

                // For some of the more obsecure cases
                if (!show.overview.HasValue())
                {
                    show.overview = enShow.overview;
                }

                show.Images = enShow.Images;
            }

            var mapped = _mapper.Map <SearchFullInfoTvShowViewModel>(show);


            foreach (var tvSeason in show.seasons.Where(x => x.season_number != 0)) // skip the first season
            {
                var seasonEpisodes = (await _movieApi.GetSeasonEpisodes(show.id, tvSeason.season_number, token));

                MapSeasons(mapped.SeasonRequests, tvSeason, seasonEpisodes);
            }

            return(await ProcessResult(mapped));
        }
Ejemplo n.º 2
0
        public async Task <SearchFullInfoTvShowViewModel> GetShowInformation(string tvdbid, CancellationToken token)
        {
            var show = await Cache.GetOrAdd(nameof(GetShowInformation) + tvdbid,
                                            async() => await _movieApi.GetTVInfo(tvdbid), DateTime.Now.AddHours(12));

            if (show == null || show.name == null)
            {
                // We don't have enough information
                return(null);
            }

            var mapped = _mapper.Map <SearchFullInfoTvShowViewModel>(show);


            foreach (var tvSeason in show.seasons.Where(x => x.season_number != 0)) // skip the first season
            {
                var seasonEpisodes = (await _movieApi.GetSeasonEpisodes(show.id, tvSeason.season_number, token));

                MapSeasons(mapped.SeasonRequests, tvSeason, seasonEpisodes);
            }

            return(await ProcessResult(mapped));
        }
Ejemplo n.º 3
0
        private async Task ProcessPlexTv(HashSet <PlexEpisode> plexContent, StringBuilder sb)
        {
            var series = new List <PlexServerContent>();

            foreach (var plexEpisode in plexContent)
            {
                var alreadyAdded = series.FirstOrDefault(x => x.Key == plexEpisode.Series.Key);
                if (alreadyAdded != null)
                {
                    var episodeExists = alreadyAdded.Episodes.Any(x => x.Key == plexEpisode.Key);
                    if (!episodeExists)
                    {
                        alreadyAdded.Episodes.Add(plexEpisode);
                    }
                }
                else
                {
                    plexEpisode.Series.Episodes = new List <PlexEpisode> {
                        plexEpisode
                    };
                    series.Add(plexEpisode.Series);
                }
            }

            int count     = 0;
            var orderedTv = series.OrderByDescending(x => x.AddedAt);

            foreach (var t in orderedTv)
            {
                if (!t.HasTvDb)
                {
                    // We may need to use themoviedb for the imdbid or their own id to get info
                    if (t.HasTheMovieDb)
                    {
                        int.TryParse(t.TheMovieDbId, out var movieId);
                        var externals = await _movieApi.GetTvExternals(movieId);

                        if (externals == null || externals.tvdb_id <= 0)
                        {
                            continue;
                        }
                        t.TvDbId = externals.tvdb_id.ToString();
                    }
                    // WE could check the below but we need to get the moviedb and then perform the above, let the metadata job figure this out.
                    //else if(t.HasImdb)
                    //{
                    //    // Check the imdbid
                    //    var externals = await _movieApi.Find(t.ImdbId, ExternalSource.imdb_id);
                    //    if (externals?.tv_results == null || externals.tv_results.Length <= 0)
                    //    {
                    //        continue;
                    //    }
                    //    t.TvDbId = externals.tv_results.FirstOrDefault()..ToString();
                    //}
                }

                int.TryParse(t.TvDbId, out var tvdbId);
                var info = await _tvApi.ShowLookupByTheTvDbId(tvdbId);

                if (info == null)
                {
                    continue;
                }

                try
                {
                    var banner = info.image?.original;
                    if (!string.IsNullOrEmpty(banner))
                    {
                        banner = banner.Replace("http", "https"); // Always use the Https banners
                    }

                    var tvInfo = await _movieApi.GetTVInfo(t.TheMovieDbId);

                    if (tvInfo != null && tvInfo.backdrop_path.HasValue())
                    {
                        AddBackgroundInsideTable(sb, $"https://image.tmdb.org/t/p/w500{tvInfo.backdrop_path}");
                    }
                    else
                    {
                        AddBackgroundInsideTable(sb, $"https://image.tmdb.org/t/p/w1280/");
                    }
                    AddPosterInsideTable(sb, banner);
                    AddMediaServerUrl(sb, t.Url, banner);
                    AddInfoTable(sb);

                    var title = "";
                    if (!string.IsNullOrEmpty(info.premiered) && info.premiered.Length > 4)
                    {
                        title = $"{t.Title} ({info.premiered.Remove(4)})";
                    }
                    else
                    {
                        title = $"{t.Title}";
                    }
                    AddTitle(sb, $"https://www.imdb.com/title/{info.externals.imdb}/", title);

                    // Group by the season number
                    var results = t.Episodes.GroupBy(p => p.SeasonNumber,
                                                     (key, g) => new
                    {
                        SeasonNumber = key,
                        Episodes     = g.ToList()
                    }
                                                     );

                    // Group the episodes
                    var finalsb = new StringBuilder();
                    foreach (var epInformation in results.OrderBy(x => x.SeasonNumber))
                    {
                        var orderedEpisodes = epInformation.Episodes.OrderBy(x => x.EpisodeNumber).ToList();
                        var episodeString   = StringHelper.BuildEpisodeList(orderedEpisodes.Select(x => x.EpisodeNumber));
                        finalsb.Append($"Season: {epInformation.SeasonNumber} - Episodes: {episodeString}");
                        finalsb.Append("<br />");
                    }

                    var summary = info.summary;
                    if (summary.Length > 280)
                    {
                        summary = summary.Remove(280);
                        summary = summary + "...</p>";
                    }
                    AddTvParagraph(sb, finalsb.ToString(), summary);

                    if (info.genres.Any())
                    {
                        AddGenres(sb, $"Genres: {string.Join(", ", info.genres.Select(x => x.ToString()).ToArray())}");
                    }
                }
                catch (Exception e)
                {
                    _log.LogError(e, "Error when processing Plex TV {0}", t.Title);
                }
                finally
                {
                    EndLoopHtml(sb);
                    count += 1;
                }

                if (count == 2)
                {
                    count = 0;
                    sb.Append("</tr>");
                    sb.Append("<tr>");
                }
            }
        }
Ejemplo n.º 4
0
        private async Task ProcessTv(IEnumerable <IMediaServerEpisode> episodes, string languageCode)
        {
            var series = new List <IMediaServerContent>();

            foreach (var episode in episodes)
            {
                var existingSeries = episode.SeriesIsIn(series);
                if (existingSeries != null)
                {
                    if (!episode.IsIn(existingSeries))
                    {
                        existingSeries.Episodes.Add(episode);
                    }
                }
                else
                {
                    episode.Series.Episodes = new List <IMediaServerEpisode> {
                        episode
                    };
                    series.Add(episode.Series);
                }
            }

            int count     = 0;
            var orderedTv = series.OrderByDescending(x => x.AddedAt);

            foreach (var t in orderedTv)
            {
                if (!t.HasTvDb)
                {
                    // We may need to use themoviedb for the imdbid or their own id to get info
                    if (t.HasTheMovieDb)
                    {
                        int.TryParse(t.TheMovieDbId, out var movieId);
                        var externals = await _movieApi.GetTvExternals(movieId);

                        if (externals == null || externals.tvdb_id <= 0)
                        {
                            // needed later for recently added log
                            _log.LogWarning($"{t.Title} has no TVDB ID, it won't be published.");
                            continue;
                        }
                        t.TvDbId = externals.tvdb_id.ToString();
                    }
                    // WE could check the below but we need to get the moviedb and then perform the above, let the metadata job figure this out.
                    //else if(t.HasImdb)
                    //{
                    //    // Check the imdbid
                    //    var externals = await _movieApi.Find(t.ImdbId, ExternalSource.imdb_id);
                    //    if (externals?.tv_results == null || externals.tv_results.Length <= 0)
                    //    {
                    //        continue;
                    //    }
                    //    t.TvDbId = externals.tv_results.FirstOrDefault()..ToString();
                    //}
                }

                try
                {
                    var tvInfo = await _movieApi.GetTVInfo(t.TheMovieDbId, languageCode);

                    if (tvInfo == null)
                    {
                        _log.LogWarning($"TMDB does not know series {t.Title}, it won't be published.");
                        continue;
                    }


                    if (tvInfo.backdrop_path.HasValue())
                    {
                        AddBackgroundInsideTable($"https://image.tmdb.org/t/p/w500{tvInfo.backdrop_path}");
                    }
                    else
                    {
                        AddBackgroundInsideTable($"https://image.tmdb.org/t/p/w1280/");
                    }

                    var banner = tvInfo.poster_path;
                    if (!string.IsNullOrEmpty(banner))
                    {
                        banner = $"https://image.tmdb.org/t/p/w300/{banner?.TrimStart('/') ?? string.Empty}";
                    }
                    ;
                    AddPosterInsideTable(banner);
                    AddMediaServerUrl(t.Url, banner);

                    AddInfoTable();

                    AddTvTitle(tvInfo);

                    var tvEpisodesString = GetTvEpisodesString(tvInfo, t.Episodes);
                    AddTvEpisodesSummaryGenres(tvEpisodesString, tvInfo);
                }
                catch (Exception e)
                {
                    _log.LogError(e, "Error when processing Plex TV {0}", t.Title);
                }
                finally
                {
                    EndLoopHtml();
                    count += 1;
                }

                if (count == 2)
                {
                    count = 0;
                    sb.Append("</tr>");
                    sb.Append("<tr>");
                }
            }
        }