示例#1
0
        private async Task <SenderResult> SendToRadarr(MovieRequests model, RadarrSettings settings)
        {
            var qualityToUse = int.Parse(settings.DefaultQualityProfile);

            if (model.QualityOverride > 0)
            {
                qualityToUse = model.QualityOverride;
            }

            var rootFolderPath = model.RootPathOverride <= 0 ? settings.DefaultRootPath : await RadarrRootPath(model.RootPathOverride, settings);

            var result = await RadarrApi.AddMovie(model.TheMovieDbId, model.Title, model.ReleaseDate.Year, qualityToUse, rootFolderPath, settings.ApiKey, settings.FullUri, !settings.AddOnly, settings.MinimumAvailability);

            if (!string.IsNullOrEmpty(result.Error?.message))
            {
                Log.LogError(LoggingEvents.RadarrCacher, result.Error.message);
                return(new SenderResult {
                    Success = false, Message = result.Error.message, Sent = false
                });
            }
            if (!string.IsNullOrEmpty(result.title))
            {
                return(new SenderResult {
                    Success = true, Sent = false
                });
            }
            return(new SenderResult {
                Success = true, Sent = false
            });
        }
示例#2
0
        public void Queued()
        {
            var settings = RadarrSettings.GetSettings();

            if (settings.Enabled)
            {
                Job.SetRunning(true, JobNames.RadarrCacher);
                try
                {
                    var movies = RadarrApi.GetMovies(settings.ApiKey, settings.FullUri);
                    if (movies != null)
                    {
                        var movieIds = new List <int>();
                        foreach (var m in movies)
                        {
                            if (m.tmdbId > 0)
                            {
                                movieIds.Add(m.tmdbId);
                            }
                        }
                        //var movieIds = movies.Select(x => x.tmdbId).ToList();
                        Cache.Set(CacheKeys.RadarrMovies, movieIds, CacheKeys.TimeFrameMinutes.SchedulerCaching);
                    }
                }
                catch (System.Exception ex)
                {
                    Log.Error(ex, "Failed caching queued items from Radarr");
                }
                finally
                {
                    Job.Record(JobNames.RadarrCacher);
                    Job.SetRunning(false, JobNames.RadarrCacher);
                }
            }
        }
示例#3
0
        private async Task <string> GetRootPath(int pathId, RadarrSettings radarrSettings)
        {
            var rootFoldersResult = await Cache.GetOrSetAsync(CacheKeys.RadarrRootFolders, async() =>
            {
                return(await Task.Run(() => RadarrApi.GetRootFolders(radarrSettings.ApiKey, radarrSettings.FullUri)));
            });

            foreach (var r in rootFoldersResult.Where(r => r.id == pathId))
            {
                return(r.path);
            }

            int outRoot;
            var defaultPath = int.TryParse(radarrSettings.RootPath, out outRoot);

            if (defaultPath)
            {
                // Return default path
                return(rootFoldersResult.FirstOrDefault(x => x.id.Equals(outRoot))?.path ?? string.Empty);
            }
            else
            {
                return(rootFoldersResult.FirstOrDefault()?.path ?? string.Empty);
            }
        }
示例#4
0
        private MovieSenderResult SendToRadarr(RequestedModel model, RadarrSettings settings, string qualityId)
        {
            var qualityProfile = 0;

            if (!string.IsNullOrEmpty(qualityId)) // try to parse the passed in quality, otherwise use the settings default quality
            {
                int.TryParse(qualityId, out qualityProfile);
            }

            if (qualityProfile <= 0)
            {
                int.TryParse(settings.QualityProfile, out qualityProfile);
            }

            var rootFolderPath = model.RootFolderSelected <= 0 ? settings.FullRootPath : GetRootPath(model.RootFolderSelected, settings);
            var result         = RadarrApi.AddMovie(model.ProviderId, model.Title, model.ReleaseDate.Year, qualityProfile, rootFolderPath, settings.ApiKey, settings.FullUri, true);

            if (!string.IsNullOrEmpty(result.Error?.message))
            {
                Log.Error(result.Error.message);
                return(new MovieSenderResult {
                    Result = false, Error = true, MovieSendingEnabled = true
                });
            }
            if (!string.IsNullOrEmpty(result.title))
            {
                return(new MovieSenderResult {
                    Result = true, MovieSendingEnabled = true
                });
            }
            return(new MovieSenderResult {
                Result = false, MovieSendingEnabled = true
            });
        }
        private Response RadarrTest()
        {
            var radarrSettings = this.Bind <RadarrSettings>();
            var valid          = this.Validate(radarrSettings);

            if (!valid.IsValid)
            {
                return(Response.AsJson(valid.SendJsonError()));
            }
            try
            {
                var status = RadarrApi.SystemStatus(radarrSettings.ApiKey, radarrSettings.FullUri);
                return(status?.version != null
               ? Response.AsJson(new JsonResponseModel { Result = true, Message = "Connected to Radarr successfully!" })
               : Response.AsJson(new JsonResponseModel {
                    Result = false, Message = "Could not connect to Radarr, please check your settings."
                }));
            }
            catch (Exception e) // Exceptions are expected, if we cannot connect so we will just log and swallow them.
            {
                Log.Warn("Exception thrown when attempting to get Radarr's status: ");
                Log.Warn(e);
                var message = $"Could not connect to Radarr, please check your settings. <strong>Exception Message:</strong> {e.Message}";
                if (e.InnerException != null)
                {
                    message = $"Could not connect to Radarr, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
                }
                return(Response.AsJson(new JsonResponseModel {
                    Result = false, Message = message
                }));
            }
        }
示例#6
0
        private async Task <string> RadarrRootPath(int overrideId, RadarrSettings settings)
        {
            var paths = await RadarrApi.GetRootFolders(settings.ApiKey, settings.FullUri);

            var selectedPath = paths.FirstOrDefault(x => x.id == overrideId);

            return(selectedPath?.path ?? String.Empty);
        }
示例#7
0
        private async Task <SenderResult> SendToRadarr(MovieRequests model, RadarrSettings settings)
        {
            var qualityToUse = int.Parse(settings.DefaultQualityProfile);

            if (model.QualityOverride > 0)
            {
                qualityToUse = model.QualityOverride;
            }

            var rootFolderPath = model.RootPathOverride <= 0 ? settings.DefaultRootPath : await RadarrRootPath(model.RootPathOverride, settings);

            // Check if the movie already exists? Since it could be unmonitored
            var movies = await RadarrApi.GetMovies(settings.ApiKey, settings.FullUri);

            var existingMovie = movies.FirstOrDefault(x => x.tmdbId == model.TheMovieDbId);

            if (existingMovie == null)
            {
                var result = await RadarrApi.AddMovie(model.TheMovieDbId, model.Title, model.ReleaseDate.Year,
                                                      qualityToUse, rootFolderPath, settings.ApiKey, settings.FullUri, !settings.AddOnly,
                                                      settings.MinimumAvailability);

                if (!string.IsNullOrEmpty(result.Error?.message))
                {
                    Log.LogError(LoggingEvents.RadarrCacher, result.Error.message);
                    return(new SenderResult {
                        Success = false, Message = result.Error.message, Sent = false
                    });
                }
                if (!string.IsNullOrEmpty(result.title))
                {
                    return(new SenderResult {
                        Success = true, Sent = false
                    });
                }
                return(new SenderResult {
                    Success = true, Sent = false
                });
            }
            // We have the movie, check if we can request it or change the status
            if (!existingMovie.monitored)
            {
                // let's set it to monitored and search for it
                existingMovie.monitored = true;
                await RadarrApi.UpdateMovie(existingMovie, settings.ApiKey, settings.FullUri);

                // Search for it
                await RadarrApi.MovieSearch(new[] { existingMovie.id }, settings.ApiKey, settings.FullUri);

                return(new SenderResult {
                    Success = true, Sent = true
                });
            }

            return(new SenderResult {
                Success = false, Sent = false, Message = "Movie is already monitored"
            });
        }
示例#8
0
        public async Task <IEnumerable <RadarrRootFolder> > GetRootFolders()
        {
            var settings = await RadarrSettings.GetSettingsAsync();

            if (settings.Enabled)
            {
                return(await RadarrApi.GetRootFolders(settings.ApiKey, settings.FullUri));
            }
            return(null);
        }
示例#9
0
        public async Task CacheContent()
        {
            await SemaphoreSlim.WaitAsync();

            try
            {
                var settings = await RadarrSettings.GetSettingsAsync();

                if (settings.Enabled)
                {
                    try
                    {
                        var movies = await RadarrApi.GetMovies(settings.ApiKey, settings.FullUri);

                        if (movies != null)
                        {
                            // Let's remove the old cached data
                            await _ctx.Database.ExecuteSqlCommandAsync("DELETE FROM RadarrCache");

                            var movieIds = new List <RadarrCache>();
                            foreach (var m in movies)
                            {
                                if (m.tmdbId > 0)
                                {
                                    movieIds.Add(new RadarrCache
                                    {
                                        TheMovieDbId = m.tmdbId,
                                        HasFile      = m.hasFile
                                    });
                                }
                                else
                                {
                                    Logger.LogError("TMDBId is not > 0 for movie {0}", m.title);
                                }
                            }
                            await _ctx.RadarrCache.AddRangeAsync(movieIds);

                            await _ctx.SaveChangesAsync();
                        }
                    }
                    catch (System.Exception ex)
                    {
                        Logger.LogError(LoggingEvents.Cacher, ex, "Failed caching queued items from Radarr");
                    }
                }
            }
            catch (Exception)
            {
                Logger.LogInformation(LoggingEvents.RadarrCacher, "Radarr is not setup, cannot cache episodes");
            }
            finally
            {
                SemaphoreSlim.Release();
            }
        }
示例#10
0
 public async Task <IEnumerable <RadarrRootFolder> > GetRootFolders()
 {
     return(await Cache.GetOrAdd(CacheKeys.RadarrRootProfiles, async() =>
     {
         var settings = await RadarrSettings.GetSettingsAsync();
         if (settings.Enabled)
         {
             return await RadarrApi.GetRootFolders(settings.ApiKey, settings.FullUri);
         }
         return null;
     }, DateTime.Now.AddHours(1)));
 }
示例#11
0
        private Response GetRadarrQualityProfiles()
        {
            var settings = this.Bind <RadarrSettings>();
            var profiles = RadarrApi.GetProfiles(settings.ApiKey, settings.FullUri);

            // set the cache
            if (profiles != null)
            {
                Cache.Set(CacheKeys.RadarrQualityProfiles, profiles);
            }

            return(Response.AsJson(profiles));
        }
示例#12
0
        private Response GetRadarrRootFolders()
        {
            var settings = this.Bind <RadarrSettings>();

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

            // set the cache
            if (rootFolders != null)
            {
                Cache.Set(CacheKeys.SonarrRootFolders, rootFolders);
            }

            return(Response.AsJson(rootFolders));
        }
示例#13
0
        public async Task <bool> Radarr([FromBody] RadarrSettings settings)
        {
            try
            {
                var result = await RadarrApi.SystemStatus(settings.ApiKey, settings.FullUri);

                return(result.version != null);
            }
            catch (Exception e)
            {
                Log.LogError(LoggingEvents.Api, e, "Could not test Radarr");
                return(false);
            }
        }
示例#14
0
        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
            }));
        }
示例#15
0
        public async Task <TesterResultModel> Radarr([FromBody] RadarrSettings settings)
        {
            try
            {
                var result = await RadarrApi.SystemStatus(settings.ApiKey, settings.FullUri);

                return(new TesterResultModel
                {
                    IsValid = result.urlBase == settings.SubDir || string.IsNullOrEmpty(result.urlBase) && string.IsNullOrEmpty(settings.SubDir),
                    ExpectedSubDir = result.urlBase
                });
            }
            catch (Exception e)
            {
                Log.LogError(LoggingEvents.Api, e, "Could not test Radarr");
                return(new TesterResultModel {
                    IsValid = false
                });
            }
        }
示例#16
0
文件: Setup.cs 项目: uzegonemad/Ombi
 private void CacheRadarrQualityProfiles(ICacheProvider cacheProvider)
 {
     try
     {
         var radarrService  = new SettingsServiceV2 <RadarrSettings>(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), cacheProvider));
         var radarrSettings = radarrService.GetSettings();
         if (radarrSettings.Enabled)
         {
             Log.Info("Begin executing GetProfiles call to Radarr for quality profiles");
             RadarrApi radarrApi = new RadarrApi();
             var       profiles  = radarrApi.GetProfiles(radarrSettings.ApiKey, radarrSettings.FullUri);
             cacheProvider.Set(CacheKeys.RadarrQualityProfiles, profiles);
             Log.Info("Finished executing GetProfiles call to Radarr for quality profiles");
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex, "Failed to cache Sonarr quality profiles!");
     }
 }
示例#17
0
        private MovieSenderResult SendToRadarr(RequestedModel model, RadarrSettings settings)
        {
            var qualityProfile = 0;

            int.TryParse(settings.QualityProfile, out qualityProfile);
            var result = RadarrApi.AddMovie(model.ProviderId, model.Title, model.ReleaseDate.Year, qualityProfile, settings.RootPath, settings.ApiKey, settings.FullUri, true);

            if (!string.IsNullOrEmpty(result.Error?.message))
            {
                Log.Error(result.Error.message);
                return(new MovieSenderResult {
                    Result = false, Error = true
                });
            }
            if (!string.IsNullOrEmpty(result.title))
            {
                return(new MovieSenderResult {
                    Result = true, MovieSendingEnabled = true
                });
            }
            return(new MovieSenderResult {
                Result = false, MovieSendingEnabled = true
            });
        }
示例#18
0
        public async Task Execute(IJobExecutionContext job)
        {
            await SemaphoreSlim.WaitAsync();

            try
            {
                var settings = await RadarrSettings.GetSettingsAsync();

                if (settings.Enabled)
                {
                    try
                    {
                        var movies = await RadarrApi.GetMovies(settings.ApiKey, settings.FullUri);

                        if (movies != null)
                        {
                            var strat = _ctx.Database.CreateExecutionStrategy();
                            await strat.ExecuteAsync(async() =>
                            {
                                // Let's remove the old cached data
                                using (var tran = await _ctx.Database.BeginTransactionAsync())
                                {
                                    await _ctx.Database.ExecuteSqlRawAsync("DELETE FROM RadarrCache");
                                    tran.Commit();
                                }
                            });

                            var movieIds = new List <RadarrCache>();
                            foreach (var m in movies)
                            {
                                if (m.monitored || m.hasFile)
                                {
                                    if (m.tmdbId > 0)
                                    {
                                        movieIds.Add(new RadarrCache
                                        {
                                            TheMovieDbId = m.tmdbId,
                                            HasFile      = m.hasFile
                                        });
                                    }
                                    else
                                    {
                                        Logger.LogError("TMDBId is not > 0 for movie {0}", m.title);
                                    }
                                }
                            }
                            strat = _ctx.Database.CreateExecutionStrategy();
                            await strat.ExecuteAsync(async() =>
                            {
                                using (var tran = await _ctx.Database.BeginTransactionAsync())
                                {
                                    await _ctx.RadarrCache.AddRangeAsync(movieIds);

                                    await _ctx.SaveChangesAsync();
                                    tran.Commit();
                                }
                            });
                        }

                        await OmbiQuartz.TriggerJob(nameof(IArrAvailabilityChecker), "DVR");
                    }
                    catch (System.Exception ex)
                    {
                        Logger.LogError(LoggingEvents.Cacher, ex, "Failed caching queued items from Radarr");
                    }
                }
            }
            catch (Exception)
            {
                Logger.LogInformation(LoggingEvents.RadarrCacher, "Radarr is not setup, cannot cache episodes");
            }
            finally
            {
                SemaphoreSlim.Release();
            }
        }
示例#19
0
        private string GetRootPath(int pathId, RadarrSettings sonarrSettings)
        {
            var rootFoldersResult = Cache.GetOrSet(CacheKeys.RadarrRootFolders, () => RadarrApi.GetRootFolders(sonarrSettings.ApiKey, sonarrSettings.FullUri));

            foreach (var r in rootFoldersResult.Where(r => r.id == pathId))
            {
                return(r.path);
            }
            return(string.Empty);
        }
示例#20
0
        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));
        }
示例#21
0
 public async Task <IEnumerable <RadarrRootFolder> > GetRootFolders([FromBody] RadarrSettings settings)
 {
     return(await RadarrApi.GetRootFolders(settings.ApiKey, settings.FullUri));
 }
示例#22
0
 public async Task <IEnumerable <RadarrProfile> > GetProfiles([FromBody] RadarrSettings settings)
 {
     return(await RadarrApi.GetProfiles(settings.ApiKey, settings.FullUri));
 }