mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 13:23:20 -07:00
Finished the main part of #844 just need testing
This commit is contained in:
parent
b3c7d83529
commit
0811a89c86
26 changed files with 820 additions and 91 deletions
|
@ -42,6 +42,7 @@ namespace Ombi.Core
|
|||
public const string SickRageQueued = nameof(SickRageQueued);
|
||||
public const string CouchPotatoQualityProfiles = nameof(CouchPotatoQualityProfiles);
|
||||
public const string CouchPotatoQueued = nameof(CouchPotatoQueued);
|
||||
public const string WatcherQueued = nameof(WatcherQueued);
|
||||
public const string GetPlexRequestSettings = nameof(GetPlexRequestSettings);
|
||||
public const string LastestProductVersion = nameof(LastestProductVersion);
|
||||
}
|
||||
|
|
10
Ombi.Core/IMovieSender.cs
Normal file
10
Ombi.Core/IMovieSender.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using System.Threading.Tasks;
|
||||
using Ombi.Store;
|
||||
|
||||
namespace Ombi.Core
|
||||
{
|
||||
public interface IMovieSender
|
||||
{
|
||||
Task<MovieSenderResult> Send(RequestedModel model, string qualityId = "");
|
||||
}
|
||||
}
|
95
Ombi.Core/MovieSender.cs
Normal file
95
Ombi.Core/MovieSender.cs
Normal file
|
@ -0,0 +1,95 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: MovieSender.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using Ombi.Api.Interfaces;
|
||||
using Ombi.Core.SettingModels;
|
||||
using Ombi.Store;
|
||||
|
||||
namespace Ombi.Core
|
||||
{
|
||||
public class MovieSender : IMovieSender
|
||||
{
|
||||
public MovieSender(ISettingsService<CouchPotatoSettings> cp, ISettingsService<WatcherSettings> watcher,
|
||||
ICouchPotatoApi cpApi, IWatcherApi watcherApi)
|
||||
{
|
||||
CouchPotatoSettings = cp;
|
||||
WatcherSettings = watcher;
|
||||
CpApi = cpApi;
|
||||
WatcherApi = watcherApi;
|
||||
}
|
||||
|
||||
private ISettingsService<CouchPotatoSettings> CouchPotatoSettings { get; }
|
||||
private ISettingsService<WatcherSettings> WatcherSettings { get; }
|
||||
private ICouchPotatoApi CpApi { get; }
|
||||
private IWatcherApi WatcherApi { get; }
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public async Task<MovieSenderResult> Send(RequestedModel model, string qualityId = "")
|
||||
{
|
||||
var cpSettings = await CouchPotatoSettings.GetSettingsAsync();
|
||||
var watcherSettings = await WatcherSettings.GetSettingsAsync();
|
||||
|
||||
if (cpSettings.Enabled)
|
||||
{
|
||||
return SendToCp(model, cpSettings, string.IsNullOrEmpty(qualityId) ? cpSettings.ProfileId : qualityId);
|
||||
}
|
||||
|
||||
if (watcherSettings.Enabled)
|
||||
{
|
||||
return SendToWatcher(model, watcherSettings);
|
||||
}
|
||||
|
||||
return new MovieSenderResult { Result = false, MovieSendingEnabled = false };
|
||||
}
|
||||
|
||||
private MovieSenderResult SendToWatcher(RequestedModel model, WatcherSettings settings)
|
||||
{
|
||||
var result = WatcherApi.AddMovie(model.ImdbId, settings.ApiKey, settings.FullUri);
|
||||
|
||||
if (result.Error)
|
||||
{
|
||||
Log.Error(result.ErrorMessage);
|
||||
return new MovieSenderResult { Result = false };
|
||||
}
|
||||
if (result.status.Equals("success", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
return new MovieSenderResult { Result = true, MovieSendingEnabled = true };
|
||||
}
|
||||
Log.Error(result.message);
|
||||
return new MovieSenderResult { Result = false, MovieSendingEnabled = true };
|
||||
}
|
||||
|
||||
private MovieSenderResult SendToCp(RequestedModel model, CouchPotatoSettings settings, string qualityId)
|
||||
{
|
||||
var result = CpApi.AddMovie(model.ImdbId, settings.ApiKey, model.Title, settings.FullUri, qualityId);
|
||||
return new MovieSenderResult { Result = result, MovieSendingEnabled = true };
|
||||
}
|
||||
}
|
||||
}
|
40
Ombi.Core/MovieSenderResult.cs
Normal file
40
Ombi.Core/MovieSenderResult.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: MovieSenderResult.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
namespace Ombi.Core
|
||||
{
|
||||
public class MovieSenderResult
|
||||
{
|
||||
public bool Result { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether we can send to either CP or Watcher.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if [movie sending enabled]; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public bool MovieSendingEnabled { get; set; }
|
||||
}
|
||||
}
|
|
@ -95,9 +95,12 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="CacheKeys.cs" />
|
||||
<Compile Include="HeadphonesSender.cs" />
|
||||
<Compile Include="IMovieSender.cs" />
|
||||
<Compile Include="IPlexReadOnlyDatabase.cs" />
|
||||
<Compile Include="ISecurityExtensions.cs" />
|
||||
<Compile Include="IStatusChecker.cs" />
|
||||
<Compile Include="MovieSender.cs" />
|
||||
<Compile Include="MovieSenderResult.cs" />
|
||||
<Compile Include="Notification\NotificationMessage.cs" />
|
||||
<Compile Include="Notification\NotificationMessageContent.cs" />
|
||||
<Compile Include="Notification\NotificationMessageCurlys.cs" />
|
||||
|
@ -119,6 +122,7 @@
|
|||
<Compile Include="Queue\TransientFaultQueue.cs" />
|
||||
<Compile Include="SecurityExtensions.cs" />
|
||||
<Compile Include="SettingModels\AuthenticationSettings.cs" />
|
||||
<Compile Include="SettingModels\WatcherSettings.cs" />
|
||||
<Compile Include="SettingModels\ExternalSettings.cs" />
|
||||
<Compile Include="SettingModels\HeadphonesSettings.cs" />
|
||||
<Compile Include="SettingModels\LandingPageSettings.cs" />
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace Ombi.Core.SettingModels
|
|||
public int SickRageCacher { get; set; }
|
||||
public int SonarrCacher { get; set; }
|
||||
public int CouchPotatoCacher { get; set; }
|
||||
public int WatcherCacher { get; set; }
|
||||
public int StoreBackup { get; set; }
|
||||
public int StoreCleanup { get; set; }
|
||||
public int UserRequestLimitResetter { get; set; }
|
||||
|
|
34
Ombi.Core/SettingModels/WatcherSettings.cs
Normal file
34
Ombi.Core/SettingModels/WatcherSettings.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: WatcherSettings.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
namespace Ombi.Core.SettingModels
|
||||
{
|
||||
public sealed class WatcherSettings : ExternalSettings
|
||||
{
|
||||
public bool Enabled { get; set; }
|
||||
public string ApiKey { get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue