示例#1
0
        private async Task <string> GetImdbId(bool hasTheMovieDb, bool hasTvDbId, string title, string theMovieDbId, string tvDbId)
        {
            _log.LogInformation("The media item {0} does not have a ImdbId, searching for ImdbId", title);
            // Looks like TV Maze does not provide the moviedb id, neither does the TV endpoint on TheMovieDb
            if (hasTheMovieDb)
            {
                _log.LogInformation("The show {0} has TheMovieDbId but not ImdbId, searching for ImdbId", title);
                if (int.TryParse(theMovieDbId, out var id))
                {
                    var result = await _movieApi.GetTvExternals(id);

                    return(result.imdb_id);
                }
            }

            if (hasTvDbId)
            {
                _log.LogInformation("The show {0} has tvdbid but not ImdbId, searching for ImdbId", title);
                if (int.TryParse(tvDbId, out var id))
                {
                    var result = await _tvApi.ShowLookupByTheTvDbId(id);

                    return(result?.externals?.imdb);
                }
            }
            return(string.Empty);
        }
示例#2
0
        private async Task <string> GetImdbId(bool hasTheMovieDb, bool hasTvDbId, string title, string theMovieDbId, string tvDbId, RequestType type)
        {
            _log.LogInformation("The media item {0} does not have a ImdbId, searching for ImdbId", title);
            // Looks like TV Maze does not provide the moviedb id, neither does the TV endpoint on TheMovieDb
            if (hasTheMovieDb)
            {
                _log.LogInformation("The show {0} has TheMovieDbId but not ImdbId, searching for ImdbId", title);
                if (int.TryParse(theMovieDbId, out var id))
                {
                    switch (type)
                    {
                    case RequestType.TvShow:
                        var result = await _movieApi.GetTvExternals(id);

                        return(result.imdb_id);

                    case RequestType.Movie:
                        var r = await _movieApi.GetMovieInformationWithExtraInfo(id);

                        return(r.ImdbId);

                    default:
                        break;
                    }
                }
            }

            if (hasTvDbId && type == RequestType.TvShow)
            {
                _log.LogInformation("The show {0} has tvdbid but not ImdbId, searching for ImdbId", title);

                var result = await _movieApi.Find(tvDbId.ToString(), ExternalSource.tvdb_id);

                var movieDbId = result.tv_results.FirstOrDefault()?.id ?? 0;
                if (movieDbId != 0)
                {
                    var externalsResult = await _movieApi.GetTvExternals(movieDbId);

                    return(externalsResult.imdb_id);
                }
            }
            return(string.Empty);
        }
示例#3
0
        private async Task ProcessPlexTv(IQueryable <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);
                }
            }

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

            sb.Append(
                "<table border=\"0\" cellpadding=\"0\"  align=\"center\" cellspacing=\"0\" style=\"border-collapse: separate; mso-table-lspace: 0pt; mso-table-rspace: 0pt; width: 100%;\" width=\"100%\">");
            foreach (var t in orderedTv)
            {
                try
                {
                    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;
                    }
                    var banner = info.image?.original;
                    if (!string.IsNullOrEmpty(banner))
                    {
                        banner = banner.Replace("http", "https"); // Always use the Https banners
                    }
                    AddImageInsideTable(sb, banner);

                    sb.Append("<tr>");
                    sb.Append(
                        "<td align=\"center\" style=\"font-family: sans-serif; font-size: 14px; vertical-align: top;\" valign=\"top\">");

                    var title = $"{t.Title} ({t.ReleaseYear})";

                    Href(sb, $"https://www.imdb.com/title/{info.externals.imdb}/");
                    Header(sb, 3, title);
                    EndTag(sb, "a");

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

                    // Group the episodes
                    foreach (var epInformation in results.OrderBy(x => x.SeasonNumber))
                    {
                        var orderedEpisodes = epInformation.Episodes.OrderBy(x => x.EpisodeNumber).ToList();
                        var epSb            = new StringBuilder();
                        for (var i = 0; i < orderedEpisodes.Count; i++)
                        {
                            var ep = orderedEpisodes[i];
                            if (i < orderedEpisodes.Count - 1)
                            {
                                epSb.Append($"{ep.EpisodeNumber},");
                            }
                            else
                            {
                                epSb.Append($"{ep.EpisodeNumber}");
                            }
                        }
                        AddParagraph(sb, $"Season: {epInformation.SeasonNumber}, Episode: {epSb}");
                    }

                    if (info.genres.Any())
                    {
                        AddParagraph(sb, $"Genre: {string.Join(", ", info.genres.Select(x => x.ToString()).ToArray())}");
                    }

                    AddParagraph(sb, info.summary);
                }
                catch (Exception e)
                {
                    //Log.Error(e);
                }
                finally
                {
                    EndLoopHtml(sb);
                }
            }
            sb.Append("</table><br /><br />");
        }
示例#4
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>");
                }
            }
        }
示例#5
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>");
                }
            }
        }