コード例 #1
0
 public RequestrrBot(IServiceProvider serviceProvider, ILogger <RequestrrBot> logger, DiscordSettingsProvider discordSettingsProvider)
 {
     _logger                  = logger;
     _serviceProvider         = serviceProvider;
     _discordSettingsProvider = discordSettingsProvider;
     _ombiDownloadClient      = new Ombi(serviceProvider.Get <IHttpClientFactory>(), serviceProvider.Get <ILogger <Ombi> >(), serviceProvider.Get <OmbiSettingsProvider>());
     _radarrDownloadClient    = new Radarr(serviceProvider.Get <IHttpClientFactory>(), serviceProvider.Get <ILogger <Radarr> >(), serviceProvider.Get <RadarrSettingsProvider>());
     _sonarrDownloadClient    = new Sonarr(serviceProvider.Get <IHttpClientFactory>(), serviceProvider.Get <ILogger <Sonarr> >(), serviceProvider.Get <SonarrSettingsProvider>());
 }
コード例 #2
0
        public async Task <IActionResult> TestRadarrSettings([FromBody] TestRadarrSettingsModel model)
        {
            try
            {
                await Radarr.TestConnectionAsync(_httpClientFactory.CreateClient(), _logger, ConvertToRadarrSettings(model));

                return(Ok(new { ok = true }));
            }
            catch (System.Exception)
            {
                return(BadRequest($"The specified settings are invalid"));
            }
        }
コード例 #3
0
        public async Task <IActionResult> GetRadarrTags([FromBody] TestRadarrSettingsModel model)
        {
            try
            {
                var tags = await Radarr.GetTags(_httpClientFactory.CreateClient(), _logger, ConvertToRadarrSettings(model));

                return(Ok(tags.Select(x => new RadarrTag
                {
                    Id = x.id,
                    Name = x.label
                })));
            }
            catch (System.Exception)
            {
                return(BadRequest($"Could not load the tags from Radarr, check your settings."));
            }
        }
コード例 #4
0
        public async Task <IActionResult> GetRadarrRootPaths([FromBody] TestRadarrSettingsModel model)
        {
            try
            {
                var paths = await Radarr.GetRootPaths(_httpClientFactory.CreateClient(), _logger, ConvertToRadarrSettings(model));

                return(Ok(paths.Select(x => new RadarrPath
                {
                    Id = x.id,
                    Path = x.path
                })));
            }
            catch (System.Exception)
            {
                return(BadRequest($"Could not load the paths from Radarr, check your settings."));
            }
        }
コード例 #5
0
ファイル: RequestsModule.cs プロジェクト: uzegonemad/Ombi
        private async Task <Response> ChangeRootFolder(RequestType type, int id, int rootFolderId)
        {
            var rootFolders = new List <SonarrRootFolder>();

            if (type == RequestType.TvShow)
            {
                // Get all root folders
                var settings = await SonarrSettings.GetSettingsAsync();

                rootFolders = SonarrApi.GetRootFolders(settings.ApiKey, settings.FullUri);
            }
            else
            {
                var settings = await Radarr.GetSettingsAsync();

                rootFolders = RadarrApi.GetRootFolders(settings.ApiKey, settings.FullUri);
            }

            // Get Request
            var allRequests = await Service.GetAllAsync();

            var request = allRequests.FirstOrDefault(x => x.Id == id);

            if (request == null)
            {
                return(Response.AsJson(new JsonResponseModel {
                    Result = false
                }));
            }

            foreach (var folder in rootFolders)
            {
                if (folder.id.Equals(rootFolderId))
                {
                    request.RootFolderSelected = folder.id;
                    break;
                }
            }

            await Service.UpdateRequestAsync(request);

            return(Response.AsJson(new JsonResponseModel {
                Result = true
            }));
        }
コード例 #6
0
ファイル: RequestsModule.cs プロジェクト: uzegonemad/Ombi
        private async Task <Response> GetMovies()
        {
            var allRequests = await Service.GetAllAsync();

            allRequests = allRequests.Where(x => x.Type == RequestType.Movie);

            var dbMovies = allRequests.ToList();

            if (Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests) && !IsAdmin)
            {
                dbMovies = dbMovies.Where(x => x.UserHasRequested(Username)).ToList();
            }

            List <QualityModel> qualities = new List <QualityModel>();
            var rootFolders = new List <RootFolderModel>();

            var radarr = await Radarr.GetSettingsAsync();

            if (IsAdmin)
            {
                try
                {
                    var cpSettings = await CpSettings.GetSettingsAsync();

                    if (cpSettings.Enabled)
                    {
                        try
                        {
                            var result = await Cache.GetOrSetAsync(CacheKeys.CouchPotatoQualityProfiles, async() =>
                            {
                                return
                                (await Task.Run(() => CpApi.GetProfiles(cpSettings.FullUri, cpSettings.ApiKey))
                                 .ConfigureAwait(false));
                            });

                            if (result != null)
                            {
                                qualities =
                                    result.list.Select(x => new QualityModel {
                                    Id = x._id, Name = x.label
                                }).ToList();
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Info(e);
                        }
                    }
                    if (radarr.Enabled)
                    {
                        var rootFoldersResult = await Cache.GetOrSetAsync(CacheKeys.RadarrRootFolders, async() =>
                        {
                            return(await Task.Run(() => RadarrApi.GetRootFolders(radarr.ApiKey, radarr.FullUri)));
                        });

                        rootFolders =
                            rootFoldersResult.Select(
                                x => new RootFolderModel {
                            Id = x.id.ToString(), Path = x.path, FreeSpace = x.freespace
                        })
                            .ToList();

                        var result = await Cache.GetOrSetAsync(CacheKeys.RadarrQualityProfiles, async() =>
                        {
                            return(await Task.Run(() => RadarrApi.GetProfiles(radarr.ApiKey, radarr.FullUri)));
                        });

                        qualities = result.Select(x => new QualityModel {
                            Id = x.id.ToString(), Name = x.name
                        }).ToList();
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
            }


            var canManageRequest = Security.HasAnyPermissions(User, Permissions.Administrator, Permissions.ManageRequests);
            var allowViewUsers   = Security.HasAnyPermissions(User, Permissions.Administrator, Permissions.ViewUsers);

            var viewModel = dbMovies.Select(movie => new RequestViewModel
            {
                ProviderId         = movie.ProviderId,
                Type               = movie.Type,
                Status             = movie.Status,
                ImdbId             = movie.ImdbId,
                Id                 = movie.Id,
                PosterPath         = movie.PosterPath,
                ReleaseDate        = movie.ReleaseDate,
                ReleaseDateTicks   = movie.ReleaseDate.Ticks,
                RequestedDate      = movie.RequestedDate,
                Released           = DateTime.Now > movie.ReleaseDate,
                RequestedDateTicks = DateTimeHelper.OffsetUTCDateTime(movie.RequestedDate, DateTimeOffset).Ticks,
                Approved           = movie.Available || movie.Approved,
                Title              = movie.Title,
                Overview           = movie.Overview,
                RequestedUsers     = canManageRequest || allowViewUsers ? movie.AllUsers.ToArray() : new string[] { },
                ReleaseYear        = movie.ReleaseDate.Year.ToString(),
                Available          = movie.Available,
                Admin              = canManageRequest,
                IssueId            = movie.IssueId,
                Denied             = movie.Denied,
                DeniedReason       = movie.DeniedReason,
                Qualities          = qualities.ToArray(),
                HasRootFolders     = rootFolders.Any(),
                RootFolders        = rootFolders.ToArray(),
                CurrentRootPath    = radarr.Enabled ? GetRootPath(movie.RootFolderSelected, radarr).Result : null
            }).ToList();

            return(Response.AsJson(viewModel));
        }