mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 05:43:19 -07:00
Small changes
This commit is contained in:
parent
0dd273607b
commit
3935dcb811
10 changed files with 157 additions and 103 deletions
16
Ombi/Ombi.Core.Tests/MovieEngineTests.cs
Normal file
16
Ombi/Ombi.Core.Tests/MovieEngineTests.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Ombi.Core.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class MovieEngineTests
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void Test()
|
||||
{
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
21
Ombi/Ombi.Core.Tests/Ombi.Core.Tests.csproj
Normal file
21
Ombi/Ombi.Core.Tests/Ombi.Core.Tests.csproj
Normal file
|
@ -0,0 +1,21 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<OutputType>Library</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard1.6</TargetFramework>
|
||||
<ApplicationIcon />
|
||||
<OutputType>Exe</OutputType>
|
||||
<OutputTypeEx>library</OutputTypeEx>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="15.0.0" />
|
||||
<PackageReference Include="NUnit" Version="3.6.1" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="3.7.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
40
Ombi/Ombi.Core/Engine/BaseMediaEngine.cs
Normal file
40
Ombi/Ombi.Core/Engine/BaseMediaEngine.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Ombi.Core.Engine.Interfaces;
|
||||
using Ombi.Core.IdentityResolver;
|
||||
using Ombi.Core.Models.Requests;
|
||||
using Ombi.Core.Requests.Models;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Store.Entities;
|
||||
|
||||
namespace Ombi.Core.Engine
|
||||
{
|
||||
public abstract class BaseMediaEngine : BaseEngine
|
||||
{
|
||||
protected BaseMediaEngine(IUserIdentityManager identity, IRequestService service) : base(identity)
|
||||
{
|
||||
RequestService = service;
|
||||
}
|
||||
|
||||
protected IRequestService RequestService { get; }
|
||||
|
||||
private long _dbMovieCacheTime = 0;
|
||||
private Dictionary<int, RequestModel> _dbMovies;
|
||||
protected async Task<Dictionary<int, RequestModel>> GetRequests(RequestType type)
|
||||
{
|
||||
long now = DateTime.Now.Ticks;
|
||||
if (_dbMovies == null || (now - _dbMovieCacheTime) > 10000)
|
||||
{
|
||||
var allResults = await RequestService.GetAllAsync();
|
||||
allResults = allResults.Where(x => x.Type == type);
|
||||
|
||||
var distinctResults = allResults.DistinctBy(x => x.ProviderId);
|
||||
_dbMovies = distinctResults.ToDictionary(x => x.ProviderId);
|
||||
_dbMovieCacheTime = now;
|
||||
}
|
||||
return _dbMovies;
|
||||
}
|
||||
}
|
||||
}
|
22
Ombi/Ombi.Core/Engine/Interfaces/BaseEngine.cs
Normal file
22
Ombi/Ombi.Core/Engine/Interfaces/BaseEngine.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System.Threading.Tasks;
|
||||
using Ombi.Core.IdentityResolver;
|
||||
using Ombi.Core.Models;
|
||||
|
||||
namespace Ombi.Core.Engine.Interfaces
|
||||
{
|
||||
public abstract class BaseEngine
|
||||
{
|
||||
protected BaseEngine(IUserIdentityManager identity)
|
||||
{
|
||||
UserIdentity = identity;
|
||||
}
|
||||
|
||||
protected IUserIdentityManager UserIdentity { get; }
|
||||
|
||||
protected async Task<UserDto> GetUser(string username)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,61 +1,45 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using Ombi.Api.TheMovieDb;
|
||||
using Ombi.Api.TheMovieDb.Models;
|
||||
using Ombi.Core.IdentityResolver;
|
||||
using Ombi.Core.Models.Requests;
|
||||
using Ombi.Core.Models.Search;
|
||||
using Ombi.Core.Requests.Models;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Core.Settings;
|
||||
using Ombi.Core.Settings.Models.External;
|
||||
using Ombi.Store.Entities;
|
||||
using Ombi.TheMovieDbApi;
|
||||
using Ombi.TheMovieDbApi.Models;
|
||||
|
||||
namespace Ombi.Core.Engine
|
||||
{
|
||||
public class MovieEngine : IMovieEngine
|
||||
public class MovieEngine : BaseMediaEngine, IMovieEngine
|
||||
{
|
||||
|
||||
public MovieEngine(IRequestService service, IMovieDbApi movApi, IMapper mapper)
|
||||
public MovieEngine(IUserIdentityManager identity, IRequestService service, IMovieDbApi movApi, IMapper mapper, ISettingsService<PlexSettings> plexSettings, ISettingsService<EmbySettings> embySettings)
|
||||
: base(identity, service)
|
||||
{
|
||||
RequestService = service;
|
||||
MovieApi = movApi;
|
||||
Mapper = mapper;
|
||||
PlexSettings = plexSettings;
|
||||
EmbySettings = embySettings;
|
||||
}
|
||||
private IRequestService RequestService { get; }
|
||||
|
||||
private IMovieDbApi MovieApi { get; }
|
||||
private IMapper Mapper { get; }
|
||||
private ISettingsService<PlexSettings> PlexSettings { get; }
|
||||
private ISettingsService<EmbySettings> EmbySettings { get; }
|
||||
|
||||
public async Task<IEnumerable<SearchMovieViewModel>> LookupImdbInformation(IEnumerable<SearchMovieViewModel> movies)
|
||||
{
|
||||
var retVal = new List<SearchMovieViewModel>();
|
||||
Dictionary<int, RequestModel> dbMovies = await RequestedMovies();
|
||||
Dictionary<int, RequestModel> dbMovies = await GetRequests(RequestType.Movie);
|
||||
foreach (var m in movies)
|
||||
{
|
||||
|
||||
var movieInfo = await MovieApi.GetMovieInformationWithVideo(m.Id);
|
||||
var viewMovie = Mapper.Map<SearchMovieViewModel>(movieInfo);
|
||||
|
||||
retVal.Add(viewMovie);
|
||||
// TODO needs to be careful about this, it's adding extra time to search...
|
||||
// https://www.themoviedb.org/talk/5807f4cdc3a36812160041f2
|
||||
//var videoId = movieInfo?.video ?? false
|
||||
// ? movieInfo?.videos?.results?.FirstOrDefault()?.key
|
||||
// : string.Empty;
|
||||
|
||||
//viewMovie.Trailer = string.IsNullOrEmpty(videoId)
|
||||
// ? string.Empty
|
||||
// : $"https://www.youtube.com/watch?v={videoId}";
|
||||
if (dbMovies.ContainsKey(movieInfo.Id) /*&& canSee*/) // compare to the requests db
|
||||
{
|
||||
var dbm = dbMovies[movieInfo.Id];
|
||||
|
||||
viewMovie.Requested = true;
|
||||
viewMovie.Approved = dbm.Approved;
|
||||
viewMovie.Available = dbm.Available;
|
||||
}
|
||||
retVal.Add(await ProcessSingleMovie(viewMovie, dbMovies));
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
@ -111,24 +95,25 @@ namespace Ombi.Core.Engine
|
|||
|
||||
private async Task<List<SearchMovieViewModel>> TransformMovieResultsToResponse(IEnumerable<MovieSearchResult> movies)
|
||||
{
|
||||
await Task.Yield();
|
||||
var viewMovies = new List<SearchMovieViewModel>();
|
||||
//var counter = 0;
|
||||
Dictionary<int, RequestModel> dbMovies = await RequestedMovies();
|
||||
Dictionary<int, RequestModel> dbMovies = await GetRequests(RequestType.Movie);
|
||||
foreach (var movie in movies)
|
||||
{
|
||||
var viewMovie = Mapper.Map<SearchMovieViewModel>(movie);
|
||||
|
||||
viewMovies.Add(viewMovie);
|
||||
viewMovies.Add(await ProcessSingleMovie(movie, dbMovies));
|
||||
|
||||
}
|
||||
return viewMovies;
|
||||
}
|
||||
|
||||
private async Task<SearchMovieViewModel> ProcessSingleMovie(SearchMovieViewModel viewMovie,
|
||||
Dictionary<int, RequestModel> existingRequests)
|
||||
{
|
||||
|
||||
// var canSee = CanUserSeeThisRequest(viewMovie.Id, Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests), dbMovies);
|
||||
|
||||
// var plexSettings = await PlexService.GetSettingsAsync();
|
||||
// var embySettings = await EmbySettings.GetSettingsAsync();
|
||||
// if (plexSettings.Enable)
|
||||
// {
|
||||
var plexSettings = await PlexSettings.GetSettingsAsync();
|
||||
var embySettings = await EmbySettings.GetSettingsAsync();
|
||||
if (plexSettings.Enable)
|
||||
{
|
||||
// var content = PlexContentRepository.GetAll();
|
||||
// var plexMovies = PlexChecker.GetPlexMovies(content);
|
||||
|
||||
|
@ -140,9 +125,9 @@ namespace Ombi.Core.Engine
|
|||
// viewMovie.Available = true;
|
||||
// viewMovie.PlexUrl = plexMovie.Url;
|
||||
// }
|
||||
// }
|
||||
// if (embySettings.Enable)
|
||||
// {
|
||||
}
|
||||
if (embySettings.Enable)
|
||||
{
|
||||
// var embyContent = EmbyContentRepository.GetAll();
|
||||
// var embyMovies = EmbyChecker.GetEmbyMovies(embyContent);
|
||||
|
||||
|
@ -152,45 +137,25 @@ namespace Ombi.Core.Engine
|
|||
// {
|
||||
// viewMovie.Available = true;
|
||||
// }
|
||||
// }
|
||||
if (dbMovies.ContainsKey(movie.Id) /*&& canSee*/) // compare to the requests db
|
||||
}
|
||||
|
||||
if (existingRequests.ContainsKey(viewMovie.Id)) // Do we already have a request for this?
|
||||
{
|
||||
var dbm = dbMovies[movie.Id];
|
||||
var requestedMovie = existingRequests[viewMovie.Id];
|
||||
|
||||
viewMovie.Requested = true;
|
||||
viewMovie.Approved = dbm.Approved;
|
||||
viewMovie.Available = dbm.Available;
|
||||
}
|
||||
// else if (canSee)
|
||||
// {
|
||||
// bool exists = IsMovieInCache(movie, viewMovie.ImdbId);
|
||||
// viewMovie.Approved = exists;
|
||||
// viewMovie.Requested = exists;
|
||||
// }
|
||||
// viewMovies.Add(viewMovie);
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
return viewMovies;
|
||||
viewMovie.Approved = requestedMovie.Approved;
|
||||
viewMovie.Available = requestedMovie.Available;
|
||||
}
|
||||
|
||||
|
||||
private long _dbMovieCacheTime = 0;
|
||||
private Dictionary<int, RequestModel> _dbMovies;
|
||||
private async Task<Dictionary<int, RequestModel>> RequestedMovies()
|
||||
return viewMovie;
|
||||
}
|
||||
|
||||
private async Task<SearchMovieViewModel> ProcessSingleMovie(MovieSearchResult movie, Dictionary<int, RequestModel> existingRequests)
|
||||
{
|
||||
long now = DateTime.Now.Ticks;
|
||||
if (_dbMovies == null || (now - _dbMovieCacheTime) > 10000)
|
||||
{
|
||||
var allResults = await RequestService.GetAllAsync();
|
||||
allResults = allResults.Where(x => x.Type == RequestType.Movie);
|
||||
|
||||
var distinctResults = allResults.DistinctBy(x => x.ProviderId);
|
||||
_dbMovies = distinctResults.ToDictionary(x => x.ProviderId);
|
||||
_dbMovieCacheTime = now;
|
||||
}
|
||||
return _dbMovies;
|
||||
var viewMovie = Mapper.Map<SearchMovieViewModel>(movie);
|
||||
return await ProcessSingleMovie(viewMovie, existingRequests);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,11 +32,6 @@ namespace Ombi.Core.Engine
|
|||
RequestAdded = false,
|
||||
Message = "There was an issue adding this movie!"
|
||||
};
|
||||
//Response.AsJson(new JsonResponseModel
|
||||
//{
|
||||
// Result = false,
|
||||
// Message = "There was an issue adding this movie!"
|
||||
//});
|
||||
}
|
||||
var fullMovieName =
|
||||
$"{movieInfo.Title}{(!string.IsNullOrEmpty(movieInfo.ReleaseDate) ? $" ({DateTime.Parse(movieInfo.ReleaseDate).Year})" : string.Empty)}";
|
||||
|
@ -44,26 +39,11 @@ namespace Ombi.Core.Engine
|
|||
var existingRequest = await RequestService.CheckRequestAsync(model.Id);
|
||||
if (existingRequest != null)
|
||||
{
|
||||
// check if the current user is already marked as a requester for this movie, if not, add them
|
||||
//if (!existingRequest.UserHasRequested(Username))
|
||||
//{
|
||||
// existingRequest.RequestedUsers.Add(Username);
|
||||
// await RequestService.UpdateRequestAsync(existingRequest);
|
||||
//}
|
||||
|
||||
return new RequestEngineResult
|
||||
{
|
||||
RequestAdded = true,
|
||||
|
||||
RequestAdded = false,
|
||||
Message = "This has already been requested"
|
||||
};
|
||||
//Response.AsJson(new JsonResponseModel
|
||||
//{
|
||||
// Result = true,
|
||||
// Message =
|
||||
// Security.HasPermissions(User, Permissions.UsersCanViewOnlyOwnRequests)
|
||||
// ? $"{fullMovieName} {Ombi.UI.Resources.UI.Search_SuccessfullyAdded}"
|
||||
// : $"{fullMovieName} {Resources.UI.Search_AlreadyRequested}"
|
||||
//});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ namespace Ombi.Mapping
|
|||
}
|
||||
var config = new AutoMapper.MapperConfiguration(cfg =>
|
||||
{
|
||||
//cfg.AddProfile(new OmbiProfile());
|
||||
cfg.AddProfiles(assemblies);
|
||||
});
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ombi.Api\Ombi.Api.csproj" />
|
||||
<ProjectReference Include="..\Ombi.Helpers\Ombi.Helpers.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -3,6 +3,7 @@ using System.Net.Http;
|
|||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using Ombi.Api.TheMovieDb.Models;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.TheMovieDbApi.Models;
|
||||
|
||||
namespace Ombi.Api.TheMovieDb
|
||||
|
@ -16,7 +17,7 @@ namespace Ombi.Api.TheMovieDb
|
|||
}
|
||||
|
||||
private IMapper Mapper { get; }
|
||||
private const string ApiToken = "b8eabaf5608b88d0298aa189dd90bf00";
|
||||
private readonly string ApiToken = StringCipher.DecryptString("bqCrDAQABAC/mJT6JXNdlQ1boOjsHeQgyk7gcNv7tUFtwxoVEnYvqS+UdgfgoyXnBz2F6LJnKX8xGtXbzLsf6pbxDkxna6zvunivxAcAHewo2zTPjoUB5igeMB8d93fx0WO9IhGtq8oGXv++xfaXfTY3aN5NV7JmF6ziAAAAAD1e5VjRPSLOYTyJ3Hbw9bDsE/4FGxYIrvxVkqDMl1vAosOeTi+0kKPFloF6k2ptTw==", "Ombiv3SettingsEncryptionPassword");
|
||||
private static readonly string BaseUri ="http://api.themoviedb.org/3/";
|
||||
private Ombi.Api.Api Api { get; }
|
||||
|
||||
|
|
|
@ -40,6 +40,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Api.Emby", "Ombi.Api.E
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Api.Sonarr", "Ombi.Api.Sonarr\Ombi.Api.Sonarr.csproj", "{CFB5E008-D0D0-43C0-AA06-89E49D17F384}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{6F42AB98-9196-44C4-B888-D5E409F415A1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.Core.Tests", "Ombi.Core.Tests\Ombi.Core.Tests.csproj", "{2836861C-1185-4E56-A0C2-F4EB541C74AE}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -94,6 +98,10 @@ Global
|
|||
{CFB5E008-D0D0-43C0-AA06-89E49D17F384}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CFB5E008-D0D0-43C0-AA06-89E49D17F384}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CFB5E008-D0D0-43C0-AA06-89E49D17F384}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2836861C-1185-4E56-A0C2-F4EB541C74AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2836861C-1185-4E56-A0C2-F4EB541C74AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2836861C-1185-4E56-A0C2-F4EB541C74AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2836861C-1185-4E56-A0C2-F4EB541C74AE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -106,5 +114,6 @@ Global
|
|||
{2E1A7B91-F29B-42BC-8F1E-1CF2DCC389BA} = {9293CA11-360A-4C20-A674-B9E794431BF5}
|
||||
{08FF107D-31E1-470D-AF86-E09B015CEE06} = {9293CA11-360A-4C20-A674-B9E794431BF5}
|
||||
{CFB5E008-D0D0-43C0-AA06-89E49D17F384} = {9293CA11-360A-4C20-A674-B9E794431BF5}
|
||||
{2836861C-1185-4E56-A0C2-F4EB541C74AE} = {6F42AB98-9196-44C4-B888-D5E409F415A1}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue