Ejemplo n.º 1
0
        public async Task <TvShowRequestBuilder> GetShowInfo(int id)
        {
            ShowInfo = await TvApi.ShowLookupByTheTvDbId(id);

            Results = await MovieDbApi.SearchTv(ShowInfo.name);

            foreach (TvSearchResult result in Results)
            {
                if (result.Name == ShowInfo.name)
                {
                    var showIds = await MovieDbApi.GetTvExternals(result.Id);

                    ShowInfo.externals.imdb = showIds.imdb_id;
                    BackdropPath            = result.BackdropPath;
                    break;
                }
            }

            DateTime.TryParse(ShowInfo.premiered, out var dt);

            FirstAir = dt;

            // For some reason the poster path is always http
            PosterPath = ShowInfo.image?.medium.Replace("http:", "https:");

            return(this);
        }
Ejemplo n.º 2
0
        public async Task <TvShowRequestBuilder> GetShowInfo(int id)
        {
            ShowInfo = await TvApi.ShowLookupByTheTvDbId(id);

            Results = await MovieDbApi.SearchTv(ShowInfo.name);

            foreach (TvSearchResult result in Results)
            {
                if (result.Name.Equals(ShowInfo.name, StringComparison.InvariantCultureIgnoreCase))
                {
                    TheMovieDbRecord = result;
                    var showIds = await MovieDbApi.GetTvExternals(result.Id);

                    ShowInfo.externals.imdb = showIds.imdb_id;
                    BackdropPath            = result.BackdropPath;
                    break;
                }
            }

            DateTime.TryParse(ShowInfo.premiered, out var dt);

            FirstAir = dt;

            // For some reason the poster path is always http
            PosterPath = ShowInfo.image?.medium.ToHttpsUrl();

            return(this);
        }
Ejemplo n.º 3
0
        public async Task <TvShowRequestBuilder> GetShowInfo(int id)
        {
            ShowInfo = await TvApi.ShowLookupByTheTvDbId(id);

            DateTime.TryParse(ShowInfo.premiered, out DateTime dt);

            FirstAir = dt;

            // For some reason the poster path is always http
            PosterPath = ShowInfo.image?.medium.Replace("http:", "https:");

            return(this);
        }
Ejemplo n.º 4
0
        public async Task <TvShowRequestBuilder> BuildEpisodes(TvRequestViewModel tv)
        {
            if (tv.RequestAll)
            {
                var episodes = await TvApi.EpisodeLookup(ShowInfo.id);

                foreach (var ep in episodes)
                {
                    var season = ChildRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == ep.season);
                    if (season == null)
                    {
                        ChildRequest.SeasonRequests.Add(new SeasonRequests
                        {
                            Episodes = new List <EpisodeRequests> {
                                new EpisodeRequests
                                {
                                    EpisodeNumber = ep.number,
                                    AirDate       = FormatDate(ep.airdate),
                                    Title         = ep.name,
                                    Url           = ep.url.ToHttpsUrl()
                                }
                            },
                            SeasonNumber = ep.season,
                        });
                    }
                    else
                    {
                        season.Episodes.Add(new EpisodeRequests
                        {
                            EpisodeNumber = ep.number,
                            AirDate       = FormatDate(ep.airdate),
                            Title         = ep.name,
                            Url           = ep.url.ToHttpsUrl()
                        });
                    }
                }
            }
            else if (tv.LatestSeason)
            {
                var episodes = await TvApi.EpisodeLookup(ShowInfo.id);

                var latest           = episodes.OrderByDescending(x => x.season).FirstOrDefault();
                var episodesRequests = new List <EpisodeRequests>();
                foreach (var ep in episodes)
                {
                    if (ep.season == latest.season)
                    {
                        episodesRequests.Add(new EpisodeRequests
                        {
                            EpisodeNumber = ep.number,
                            AirDate       = FormatDate(ep.airdate),
                            Title         = ep.name,
                            Url           = ep.url.ToHttpsUrl()
                        });
                    }
                }
                ChildRequest.SeasonRequests.Add(new SeasonRequests
                {
                    Episodes     = episodesRequests,
                    SeasonNumber = latest.season,
                });
            }
            else if (tv.FirstSeason)
            {
                var episodes = await TvApi.EpisodeLookup(ShowInfo.id);

                var first            = episodes.OrderBy(x => x.season).FirstOrDefault();
                var episodesRequests = new List <EpisodeRequests>();
                foreach (var ep in episodes)
                {
                    if (ep.season == first.season)
                    {
                        episodesRequests.Add(new EpisodeRequests
                        {
                            EpisodeNumber = ep.number,
                            AirDate       = FormatDate(ep.airdate),
                            Title         = ep.name,
                            Url           = ep.url.ToHttpsUrl()
                        });
                    }
                }
                ChildRequest.SeasonRequests.Add(new SeasonRequests
                {
                    Episodes     = episodesRequests,
                    SeasonNumber = first.season,
                });
            }
            else
            {
                // It's a custom request
                var seasonRequests = new List <SeasonRequests>();
                var episodes       = await TvApi.EpisodeLookup(ShowInfo.id);

                foreach (var ep in episodes)
                {
                    var existingSeasonRequest = seasonRequests.FirstOrDefault(x => x.SeasonNumber == ep.season);
                    if (existingSeasonRequest != null)
                    {
                        var requestedSeason  = tv.Seasons.FirstOrDefault(x => x.SeasonNumber == ep.season);
                        var requestedEpisode = requestedSeason?.Episodes?.Any(x => x.EpisodeNumber == ep.number) ?? false;
                        if (requestedSeason != null && requestedEpisode)
                        {
                            // We already have this, let's just add the episodes to it
                            existingSeasonRequest.Episodes.Add(new EpisodeRequests
                            {
                                EpisodeNumber = ep.number,
                                AirDate       = FormatDate(ep.airdate),
                                Title         = ep.name,
                                Url           = ep.url.ToHttpsUrl()
                            });
                        }
                    }
                    else
                    {
                        var newRequest = new SeasonRequests {
                            SeasonNumber = ep.season
                        };
                        var requestedSeason  = tv.Seasons.FirstOrDefault(x => x.SeasonNumber == ep.season);
                        var requestedEpisode = requestedSeason?.Episodes?.Any(x => x.EpisodeNumber == ep.number) ?? false;
                        if (requestedSeason != null && requestedEpisode)
                        {
                            newRequest.Episodes.Add(new EpisodeRequests
                            {
                                EpisodeNumber = ep.number,
                                AirDate       = FormatDate(ep.airdate),
                                Title         = ep.name,
                                Url           = ep.url.ToHttpsUrl()
                            });
                            seasonRequests.Add(newRequest);
                        }
                    }
                }

                foreach (var s in seasonRequests)
                {
                    ChildRequest.SeasonRequests.Add(s);
                }
            }
            return(this);
        }
Ejemplo n.º 5
0
        private void GenerateTvHtml(IEnumerable <PlexRecentlyAddedModel> recenetlyAddedTv, StringBuilder sb)
        {
            var tv = recenetlyAddedTv?.ToList() ?? new List <PlexRecentlyAddedModel>();

            if (!tv.Any())
            {
                return;
            }
            var orderedTv = tv.OrderByDescending(x => x.Content.AddedAt).ToList();

            // TV
            sb.Append("<h1>New Episodes:</h1><br /><br />");
            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)
            {
                var relatedEpisodes = t.EpisodeMetadata ?? new List <PlexEpisodeMetadata>();

                try
                {
                    var info = TvApi.ShowLookupByTheTvDbId(int.Parse(PlexHelper.GetProviderIdFromPlexGuid(t.Metadata.Directory.Guid)));

                    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.Content.Title} {t.Content.ReleaseYear}";

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

                    // Group by the ParentIndex (season number)
                    var results = relatedEpisodes.GroupBy(p => p.Video.FirstOrDefault()?.ParentIndex,
                                                          (key, g) => new
                    {
                        ParentIndexNumber = key,
                        IndexNumber       = g.ToList()
                    }
                                                          );
                    // Group the episodes
                    foreach (var epInformation in results.OrderBy(x => x.ParentIndexNumber))
                    {
                        var orderedEpisodes = epInformation.IndexNumber.OrderBy(x => Convert.ToInt32(x.Video.FirstOrDefault().Index)).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.Video.FirstOrDefault().Index},");
                            }
                            else
                            {
                                epSb.Append($"{ep.Video.FirstOrDefault().Index}");
                            }
                        }
                        AddParagraph(sb, $"Season: {epInformation.ParentIndexNumber}, Episode: {epSb}");
                    }

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

                    AddParagraph(sb, string.IsNullOrEmpty(t.Metadata.Directory.Summary) ? t.Metadata.Directory.Summary : info.summary);
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
                finally
                {
                    EndLoopHtml(sb);
                }
            }
            sb.Append("</table><br /><br />");
        }
Ejemplo n.º 6
0
        private void GenerateTvHtml(IEnumerable <EmbyRecentlyAddedModel> recenetlyAddedTv, StringBuilder sb)
        {
            var tv = recenetlyAddedTv?.ToList() ?? new List <EmbyRecentlyAddedModel>();

            if (!tv.Any())
            {
                return;
            }
            var orderedTv = tv.OrderByDescending(x => x.EmbyContent.AddedAt).ToList();

            // TV
            sb.Append("<h1>New Episodes:</h1><br /><br />");
            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)
            {
                var seriesItem      = t.EmbyInformation.SeriesInformation;
                var relatedEpisodes = t.EpisodeInformation;


                try
                {
                    var info = TvApi.ShowLookupByTheTvDbId(int.Parse(seriesItem.ProviderIds.Tvdb));

                    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 = $"{seriesItem.Name} {seriesItem.PremiereDate.Year}";

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

                    var results = relatedEpisodes.GroupBy(p => p.ParentIndexNumber,
                                                          (key, g) => new
                    {
                        ParentIndexNumber = key,
                        IndexNumber       = g.ToList()
                    }
                                                          );
                    // Group the episodes
                    foreach (var embyEpisodeInformation in results.OrderBy(x => x.ParentIndexNumber))
                    {
                        var epSb = new StringBuilder();
                        for (var i = 0; i < embyEpisodeInformation.IndexNumber.Count; i++)
                        {
                            var ep = embyEpisodeInformation.IndexNumber[i];
                            if (i < embyEpisodeInformation.IndexNumber.Count)
                            {
                                epSb.Append($"{ep.IndexNumber},");
                            }
                            else
                            {
                                epSb.Append(ep);
                            }
                        }
                        AddParagraph(sb, $"Season: {embyEpisodeInformation.ParentIndexNumber}, Episode: {epSb}");
                    }

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

                    AddParagraph(sb, string.IsNullOrEmpty(seriesItem.Overview) ? info.summary : seriesItem.Overview);
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
                finally
                {
                    EndLoopHtml(sb);
                }
            }
            sb.Append("</table><br /><br />");
        }
Ejemplo n.º 7
0
        public async Task <TvShowRequestBuilder> BuildEpisodes(SearchTvShowViewModel tv)
        {
            if (tv.RequestAll)
            {
                var episodes = await TvApi.EpisodeLookup(ShowInfo.id);

                foreach (var ep in episodes)
                {
                    var season = ChildRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == ep.season);
                    if (season == null)
                    {
                        ChildRequest.SeasonRequests.Add(new SeasonRequests
                        {
                            Episodes = new List <EpisodeRequests> {
                                new EpisodeRequests
                                {
                                    EpisodeNumber = ep.number,
                                    AirDate       = FormatDate(ep.airdate),
                                    Title         = ep.name,
                                    Url           = ep.url
                                }
                            },
                            SeasonNumber = ep.season,
                        });
                    }
                    else
                    {
                        season.Episodes.Add(new EpisodeRequests
                        {
                            EpisodeNumber = ep.number,
                            AirDate       = FormatDate(ep.airdate),
                            Title         = ep.name,
                            Url           = ep.url
                        });
                    }
                }
            }
            else if (tv.LatestSeason)
            {
                var episodes = await TvApi.EpisodeLookup(ShowInfo.id);

                var latest           = episodes.OrderByDescending(x => x.season).FirstOrDefault();
                var episodesRequests = new List <EpisodeRequests>();
                foreach (var ep in episodes)
                {
                    if (ep.season == latest.season)
                    {
                        episodesRequests.Add(new EpisodeRequests
                        {
                            EpisodeNumber = ep.number,
                            AirDate       = FormatDate(ep.airdate),
                            Title         = ep.name,
                            Url           = ep.url
                        });
                    }
                }
                ChildRequest.SeasonRequests.Add(new SeasonRequests
                {
                    Episodes     = episodesRequests,
                    SeasonNumber = latest.season,
                });
            }
            else if (tv.FirstSeason)
            {
                var episodes = await TvApi.EpisodeLookup(ShowInfo.id);

                var first            = episodes.OrderBy(x => x.season).FirstOrDefault();
                var episodesRequests = new List <EpisodeRequests>();
                foreach (var ep in episodes)
                {
                    if (ep.season == first.season)
                    {
                        episodesRequests.Add(new EpisodeRequests
                        {
                            EpisodeNumber = ep.number,
                            AirDate       = FormatDate(ep.airdate),
                            Title         = ep.name,
                            Url           = ep.url
                        });
                    }
                }
                ChildRequest.SeasonRequests.Add(new SeasonRequests
                {
                    Episodes     = episodesRequests,
                    SeasonNumber = first.season,
                });
            }
            else
            {
                // It's a custom request
                ChildRequest.SeasonRequests = TvRequests;
            }
            return(this);
        }