コード例 #1
0
ファイル: SonarrClientV3.cs プロジェクト: kinderoth/requestrr
        private TvShow Convert(JSONTvShow jsonTvShow, IReadOnlyList <JSONSeason> seasons, IDictionary <int, JSONEpisode[]> episodesToSeason)
        {
            var downloadClientId  = jsonTvShow.id?.ToString();
            var isTvShowMonitored = (string.IsNullOrWhiteSpace(downloadClientId) || SonarrSettings.MonitorNewRequests) ? jsonTvShow.monitored : true;

            var tvSeasons = seasons.Where(x => x.seasonNumber > 0).Select(x =>
            {
                var episodes   = episodesToSeason.ContainsKey(x.seasonNumber) ? episodesToSeason[x.seasonNumber] : Array.Empty <JSONEpisode>();
                var tvEpisodes = ConvertToTvEpisodes(x, episodes).OrderBy(x => x.EpisodeNumber).ToArray();

                if (tvEpisodes.Any())
                {
                    var allEpisodesDownloaded = isTvShowMonitored ? tvEpisodes.All(x => x.IsRequested || x.IsAvailable) : tvEpisodes.All(x => x.IsAvailable);
                    var partiallyDownloaded   = isTvShowMonitored ? tvEpisodes.Any(x => x.IsRequested || x.IsAvailable) : tvEpisodes.Any(x => x.IsAvailable);

                    return(new NormalTvSeason
                    {
                        SeasonNumber = x.seasonNumber,
                        IsAvailable = tvEpisodes.First().IsAvailable,
                        IsRequested = allEpisodesDownloaded ? RequestedState.Full : partiallyDownloaded ? RequestedState.Partial : RequestedState.None,
                    });
                }
                else if (jsonTvShow.ExistsInSonarr())
                {
                    return(new NormalTvSeason
                    {
                        SeasonNumber = x.seasonNumber,
                        IsAvailable = false,
                        IsRequested = isTvShowMonitored ? RequestedState.Full : RequestedState.None,
                    });
                }
                else
                {
                    return(new NormalTvSeason
                    {
                        SeasonNumber = x.seasonNumber,
                        IsAvailable = false,
                        IsRequested = RequestedState.None
                    });
                }
            }).ToArray();

            return(new TvShow
            {
                TheTvDbId = jsonTvShow.tvdbId.Value,
                DownloadClientId = downloadClientId,
                Title = jsonTvShow.title,
                Overview = jsonTvShow.overview,
                Quality = "",
                IsRequested = isTvShowMonitored,
                PlexUrl = "",
                EmbyUrl = "",
                Banner = GetPosterImageUrl(jsonTvShow.images),
                Seasons = tvSeasons.OrderBy(x => x.SeasonNumber).ToArray(),
                FirstAired = ((int)jsonTvShow.year).ToString(),
                HasEnded = ((string)jsonTvShow.status).Equals("ended", StringComparison.InvariantCultureIgnoreCase)
            });
        }
コード例 #2
0
ファイル: Sonarr.cs プロジェクト: mikeporterdev/requestrr
        private TvShow Convert(JSONTvShow jsonTvShow, IReadOnlyList <JSONSeason> seasons, IDictionary <int, JSONEpisode[]> episodesToSeason)
        {
            var tvSeasons = seasons.Where(x => x.seasonNumber > 0).Select(x =>
            {
                var episodes   = episodesToSeason.ContainsKey(x.seasonNumber) ? episodesToSeason[x.seasonNumber] : Array.Empty <JSONEpisode>();
                var tvEpisodes = ConvertToTvEpisodes(x, episodes).OrderBy(x => x.EpisodeNumber).ToArray();

                if (tvEpisodes.Any())
                {
                    return(new NormalTvSeason
                    {
                        SeasonNumber = x.seasonNumber,
                        IsAvailable = tvEpisodes.First().IsAvailable,
                        IsRequested = jsonTvShow.monitored ? tvEpisodes.All(x => x.IsRequested || x.IsAvailable) : tvEpisodes.All(x => x.IsAvailable),
                    });
                }
                else if (jsonTvShow.ExistsInSonarr())
                {
                    return(new NormalTvSeason
                    {
                        SeasonNumber = x.seasonNumber,
                        IsAvailable = false,
                        IsRequested = jsonTvShow.monitored ? x.monitored : false,
                    });
                }
                else
                {
                    return(new NormalTvSeason
                    {
                        SeasonNumber = x.seasonNumber,
                        IsAvailable = false,
                        IsRequested = false
                    });
                }
            }).ToArray();

            return(new TvShow
            {
                TheTvDbId = jsonTvShow.tvdbId.Value,
                DownloadClientId = jsonTvShow.id?.ToString(),
                Title = jsonTvShow.title,
                Overview = jsonTvShow.overview,
                Quality = "",
                IsRequested = jsonTvShow.monitored,
                PlexUrl = "",
                EmbyUrl = "",
                Seasons = tvSeasons.OrderBy(x => x.SeasonNumber).ToArray(),
                Banner = jsonTvShow.images.Where(x => ((string)x.coverType).Equals("poster", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault()?.url ?? string.Empty,
                FirstAired = ((int)jsonTvShow.year).ToString(),
                HasEnded = ((string)jsonTvShow.status).Equals("ended", StringComparison.InvariantCultureIgnoreCase)
            });
        }