Updated projects, updated entities to use a string as the primary keys. migrations need doing

pull/4576/head
tidusjar 3 years ago
parent 890d74037a
commit b5a268510d

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -17,9 +17,9 @@ namespace Ombi.Api.Plex
Task<PlexServer> GetServer(string authToken);
Task<PlexContainer> GetLibrarySections(string authToken, string plexFullHost);
Task<PlexContainer> GetLibrary(string authToken, string plexFullHost, string libraryId);
Task<PlexMetadata> GetEpisodeMetaData(string authToken, string host, int ratingKey);
Task<PlexMetadata> GetMetadata(string authToken, string plexFullHost, int itemId);
Task<PlexMetadata> GetSeasons(string authToken, string plexFullHost, int ratingKey);
Task<PlexMetadata> GetEpisodeMetaData(string authToken, string host, string ratingKey);
Task<PlexMetadata> GetMetadata(string authToken, string plexFullHost, string itemId);
Task<PlexMetadata> GetSeasons(string authToken, string plexFullHost, string ratingKey);
Task<PlexContainer> GetAllEpisodes(string authToken, string host, string section, int start, int retCount);
Task<PlexFriends> GetUsers(string authToken);
Task<PlexAccount> GetAccount(string authToken);
@ -27,6 +27,6 @@ namespace Ombi.Api.Plex
Task<OAuthContainer> GetPin(int pinId);
Task<Uri> GetOAuthUrl(string code, string applicationUrl);
Task<PlexAddWrapper> AddUser(string emailAddress, string serverId, string authToken, int[] libs);
Task<PlexMetadata> GetWatchlist(string plexToken, CancellationToken cancellationToken);
Task<PlexWatchlist> GetWatchlist(string plexToken, CancellationToken cancellationToken);
}
}

@ -4,7 +4,7 @@ namespace Ombi.Api.Plex.Models
{
public class Metadata
{
public int ratingKey { get; set; }
public string ratingKey { get; set; }
public string key { get; set; }
public string studio { get; set; }
public string type { get; set; }
@ -22,8 +22,8 @@ namespace Ombi.Api.Plex.Models
public int childCount { get; set; }
public Genre[] Genre { get; set; }
public string primaryExtraKey { get; set; }
public int parentRatingKey { get; set; }
public int grandparentRatingKey { get; set; }
public string parentRatingKey { get; set; }
public string grandparentRatingKey { get; set; }
public string guid { get; set; }
public int librarySectionID { get; set; }
public string librarySectionKey { get; set; }

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -147,21 +147,21 @@ namespace Ombi.Api.Plex
/// <param name="authToken"></param>
/// <param name="plexFullHost"></param>
/// <param name="ratingKey"></param>
public async Task<PlexMetadata> GetEpisodeMetaData(string authToken, string plexFullHost, int ratingKey)
public async Task<PlexMetadata> GetEpisodeMetaData(string authToken, string plexFullHost, string ratingKey)
{
var request = new Request($"/library/metadata/{ratingKey}", plexFullHost, HttpMethod.Get);
await AddHeaders(request, authToken);
return await Api.Request<PlexMetadata>(request);
}
public async Task<PlexMetadata> GetMetadata(string authToken, string plexFullHost, int itemId)
public async Task<PlexMetadata> GetMetadata(string authToken, string plexFullHost, string itemId)
{
var request = new Request($"library/metadata/{itemId}", plexFullHost, HttpMethod.Get);
await AddHeaders(request, authToken);
return await Api.Request<PlexMetadata>(request);
}
public async Task<PlexMetadata> GetSeasons(string authToken, string plexFullHost, int ratingKey)
public async Task<PlexMetadata> GetSeasons(string authToken, string plexFullHost, string ratingKey)
{
var request = new Request($"library/metadata/{ratingKey}/children", plexFullHost, HttpMethod.Get);
await AddHeaders(request, authToken);
@ -290,12 +290,12 @@ namespace Ombi.Api.Plex
}
}
public async Task<PlexMetadata> GetWatchlist(string plexToken, CancellationToken cancellationToken)
public async Task<PlexWatchlist> GetWatchlist(string plexToken, CancellationToken cancellationToken)
{
var request = new Request(string.Empty, WatchlistUri, HttpMethod.Get);
await AddHeaders(request, plexToken);
var result = await Api.Request<PlexMetadata>(request, cancellationToken);
var result = await Api.Request<PlexWatchlist>(request, cancellationToken);
return result;
}

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -8,7 +8,7 @@
<PackageVersion></PackageVersion>
<AssemblyName>Ombi.Api.Service</AssemblyName>
<RootNamespace>Ombi.Api.Service</RootNamespace>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -104,7 +104,7 @@ namespace Ombi.Helpers
return new ProviderId();
}
public static string GetPlexMediaUrl(string machineId, int mediaId, string plexHost)
public static string GetPlexMediaUrl(string machineId, string mediaId, string plexHost)
{
var url =
$"web/#!/server/{machineId}/details?key=%2flibrary%2Fmetadata%2F{mediaId}";

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>
<ItemGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -19,6 +19,7 @@
<ItemGroup>
<ProjectReference Include="..\Ombi.Schedule\Ombi.Schedule.csproj" />
<ProjectReference Include="..\Ombi.Test.Common\Ombi.Test.Common.csproj" />
</ItemGroup>
</Project>

@ -47,7 +47,7 @@ namespace Ombi.Schedule.Tests
}
};
var contentToAdd = new HashSet<PlexServerContent>();
var contentProcessed = new Dictionary<int, int>();
var contentProcessed = new Dictionary<int, string>();
_mocker.Setup<IPlexContentRepository>(x =>
x.GetFirstContentByCustom(It.IsAny<Expression<Func<PlexServerContent, bool>>>()))
.Returns(Task.FromResult(new PlexServerContent()));
@ -76,18 +76,18 @@ namespace Ombi.Schedule.Tests
Id = "imdb://tt0322259"
}
},
ratingKey = 1
ratingKey = "1"
},
}
};
var contentToAdd = new HashSet<PlexServerContent>();
var contentProcessed = new Dictionary<int, int>();
var contentProcessed = new Dictionary<int, string>();
await _subject.MovieLoop(new PlexServers(), content, contentToAdd, contentProcessed);
var first = contentToAdd.First();
Assert.That(first.ImdbId, Is.EqualTo("tt0322259"));
_mocker.Verify<IPlexApi>(x => x.GetMetadata(It.IsAny<string>(), It.IsAny<string>(),It.IsAny<int>()), Times.Never);
_mocker.Verify<IPlexApi>(x => x.GetMetadata(It.IsAny<string>(), It.IsAny<string>(),It.IsAny<string>()), Times.Never);
}
[Test]
@ -99,7 +99,7 @@ namespace Ombi.Schedule.Tests
{
new Metadata
{
ratingKey = 11,
ratingKey = "11",
title = "test1",
year = 2021,
type = "movie",
@ -107,8 +107,8 @@ namespace Ombi.Schedule.Tests
}
};
var contentToAdd = new HashSet<PlexServerContent>();
var contentProcessed = new Dictionary<int, int>();
_mocker.Setup<IPlexApi>(x => x.GetMetadata(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()))
var contentProcessed = new Dictionary<int, string>();
_mocker.Setup<IPlexApi>(x => x.GetMetadata(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns(Task.FromResult(new PlexMetadata
{
MediaContainer = new Mediacontainer
@ -117,7 +117,7 @@ namespace Ombi.Schedule.Tests
{
new Metadata
{
ratingKey = 11,
ratingKey = "11",
title = "test1",
year = 2021,
type = "movie",
@ -138,7 +138,7 @@ namespace Ombi.Schedule.Tests
var first = contentToAdd.First();
Assert.That(first.ImdbId, Is.EqualTo("tt0322259"));
_mocker.Verify<IPlexApi>(x => x.GetMetadata(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>()), Times.Once);
_mocker.Verify<IPlexApi>(x => x.GetMetadata(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}
[Test]
@ -150,7 +150,7 @@ namespace Ombi.Schedule.Tests
{
new Metadata
{
ratingKey = 11,
ratingKey = "11",
title = "test1",
year = 2021,
type = "movie",
@ -165,7 +165,7 @@ namespace Ombi.Schedule.Tests
}
};
var contentToAdd = new HashSet<PlexServerContent>();
var contentProcessed = new Dictionary<int, int>();
var contentProcessed = new Dictionary<int, string>();
_mocker.Setup<IPlexContentRepository>(x =>
x.GetFirstContentByCustom(It.IsAny<Expression<Func<PlexServerContent, bool>>>()))
.Returns(Task.FromResult(new PlexServerContent
@ -188,7 +188,7 @@ namespace Ombi.Schedule.Tests
{
new Metadata
{
ratingKey = 11,
ratingKey = "11",
title = "test1",
year = 2021,
type = "movie",
@ -203,7 +203,7 @@ namespace Ombi.Schedule.Tests
}
};
var contentToAdd = new HashSet<PlexServerContent>();
var contentProcessed = new Dictionary<int, int>();
var contentProcessed = new Dictionary<int, string>();
_mocker.Setup<IPlexContentRepository>(x =>
x.GetFirstContentByCustom(It.IsAny<Expression<Func<PlexServerContent, bool>>>()))
.Returns(Task.FromResult(new PlexServerContent

@ -0,0 +1,57 @@
using Moq;
using Moq.AutoMock;
using NUnit.Framework;
using Ombi.Api.Plex;
using Ombi.Api.Plex.Models;
using Ombi.Core.Authentication;
using Ombi.Core.Settings;
using Ombi.Core.Settings.Models.External;
using Ombi.Schedule.Jobs.Plex;
using Ombi.Store.Entities;
using Ombi.Test.Common;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Ombi.Schedule.Tests
{
[TestFixture]
public class PlexWatchlistImportTests
{
private PlexWatchlistImport _subject;
private AutoMocker _mocker;
private Mock<IJobExecutionContext> _context;
[SetUp]
public void Setup()
{
_mocker = new AutoMocker();
var um = MockHelper.MockUserManager(new List<OmbiUser> { new OmbiUser { Id = "abc", UserType = UserType.PlexUser, MediaServerToken = "abc", UserName = "abc", NormalizedUserName = "ABC" } });
_mocker.Use(um);
_context = _mocker.GetMock<IJobExecutionContext>();
_context.Setup(x => x.CancellationToken).Returns(CancellationToken.None);
_subject = _mocker.CreateInstance<PlexWatchlistImport>();
}
[Test]
public async Task TerminatesWhenPlexIsNotEnabled()
{
_mocker.Setup<ISettingsService<PlexSettings>, Task<PlexSettings>>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = false });
await _subject.Execute(null);
}
[Test]
public async Task EmptyWatchList()
{
_mocker.Setup<ISettingsService<PlexSettings>, Task<PlexSettings>>(x => x.GetSettingsAsync()).ReturnsAsync(new PlexSettings { Enable = true });
_mocker.Setup<IPlexApi, Task<PlexWatchlist>>(x => x.GetWatchlist(It.IsAny<string>(), It.IsAny<CancellationToken>())).ReturnsAsync(new PlexWatchlist());
await _subject.Execute(_context.Object);
}
}
}

@ -5,7 +5,7 @@ namespace Ombi.Schedule.Jobs.Plex.Models
{
public class ProcessedContent
{
public IEnumerable<int> Content { get; set; }
public IEnumerable<string> Content { get; set; }
public IEnumerable<int> Episodes { get; set; }
public bool HasProcessedContent => Content?.Any() ?? false;

@ -167,7 +167,7 @@ namespace Ombi.Schedule.Jobs.Plex
private async Task<ProcessedContent> ProcessServer(PlexServers servers, bool recentlyAddedSearch)
{
var retVal = new ProcessedContent();
var contentProcessed = new Dictionary<int, int>();
var contentProcessed = new Dictionary<int, string>();
var episodesProcessed = new List<int>();
Logger.LogDebug("Getting all content from server {0}", servers.Name);
var allContent = await GetAllContent(servers, recentlyAddedSearch);
@ -290,7 +290,7 @@ namespace Ombi.Schedule.Jobs.Plex
}
public async Task MovieLoop(PlexServers servers, Mediacontainer content, HashSet<PlexServerContent> contentToAdd,
Dictionary<int, int> contentProcessed)
Dictionary<int, string> contentProcessed)
{
Logger.LogDebug("Processing Movies");
foreach (var movie in content?.Metadata ?? Array.Empty<Metadata>())
@ -437,7 +437,7 @@ namespace Ombi.Schedule.Jobs.Plex
}
}
private async Task ProcessTvShow(PlexServers servers, Metadata show, HashSet<PlexServerContent> contentToAdd, Dictionary<int, int> contentProcessed)
private async Task ProcessTvShow(PlexServers servers, Metadata show, HashSet<PlexServerContent> contentToAdd, Dictionary<int, string> contentProcessed)
{
var seasonList = await PlexApi.GetSeasons(servers.PlexAuthToken, servers.FullUri,
show.ratingKey);

@ -1,4 +1,13 @@
using Quartz;
using Ombi.Api.Plex;
using Ombi.Api.Plex.Models;
using Ombi.Core.Authentication;
using Ombi.Core.Engine.Interfaces;
using Ombi.Core.Settings;
using Ombi.Core.Settings.Models.External;
using Ombi.Helpers;
using Ombi.Store.Entities;
using Ombi.Store.Repository.Requests;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
@ -9,14 +18,107 @@ namespace Ombi.Schedule.Jobs.Plex
{
public class PlexWatchlistImport : IPlexWatchlistImport
{
public void Dispose()
private readonly IPlexApi _plexApi;
private readonly ISettingsService<PlexSettings> _settings;
private readonly OmbiUserManager _ombiUserManager;
private readonly IMovieRequestRepository _movieRequestRepository;
private readonly ITvRequestRepository _tvRequestRepository;
private readonly IMovieRequestEngine _movieRequestEngine;
public PlexWatchlistImport(IPlexApi plexApi, ISettingsService<PlexSettings> settings, OmbiUserManager ombiUserManager,
IMovieRequestRepository movieRequestRepository, ITvRequestRepository tvRequestRepository, IMovieRequestEngine movieRequestEngine)
{
_plexApi = plexApi;
_settings = settings;
_ombiUserManager = ombiUserManager;
_movieRequestRepository = movieRequestRepository;
_tvRequestRepository = tvRequestRepository;
_movieRequestEngine = movieRequestEngine;
}
public async Task Execute(IJobExecutionContext context)
{
var token = "-DpQi6mzq2QMakYgFr2g"; // !!!!!!!!!!!!!!!!!!!! TODO REMOVE !!!!!!!!!!!!!!!!!!!!!!!
var settings = await _settings.GetSettingsAsync();
if (!settings.Enable)
{
return;
}
var plexUsersWithTokens = _ombiUserManager.Users.Where(x => x.UserType == UserType.PlexUser && x.MediaServerToken != null).ToList();
foreach (var user in plexUsersWithTokens)
{
var watchlist = await _plexApi.GetWatchlist(user.MediaServerToken, context.CancellationToken);
if (watchlist == null || !watchlist.Metadata.Any())
{
continue;
}
var items = watchlist.Metadata;
foreach (var item in items)
{
switch (item.type)
{
case "show":
await ProcessShow(item);
break;
case "movie":
await ProcessMovie(item, null);
break;
}
}
}
}
private async Task ProcessMovie(Metadata movie, PlexServers servers)
{
throw new NotImplementedException();
var providerIds = await GetProviderIds(movie, servers);
if (!providerIds.TheMovieDb.HasValue())
{
// We need a MovieDbId to support this;
return;
}
//_movieRequestEngine.RequestMovie(new() { TheMovieDbId = });
}
public Task Execute(IJobExecutionContext context)
private async Task<ProviderId> GetProviderIds(Metadata movie, PlexServers servers)
{
throw new NotImplementedException();
var guids = new List<string>();
if (!movie.Guid.Any())
{
var metaData = await _plexApi.GetMetadata(servers.PlexAuthToken, servers.FullUri,
movie.ratingKey);
var meta = metaData.MediaContainer.Metadata.FirstOrDefault();
guids.Add(meta.guid);
if (meta.Guid != null)
{
foreach (var g in meta.Guid)
{
guids.Add(g.Id);
}
}
}
else
{
// Currently a Plex Pass feature only
foreach (var g in movie.Guid)
{
guids.Add(g.Id);
}
}
var providerIds = PlexHelper.GetProviderIdsFromMetadata(guids.ToArray());
return providerIds;
}
private async Task ProcessShow(Metadata metadata)
{
}
public void Dispose() { }
}
}

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -6,7 +6,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -36,6 +36,7 @@ namespace Ombi.Store.Entities
public RequestLimitType? MusicRequestLimitType { get; set; }
public string UserAccessToken { get; set; }
public string MediaServerToken { get; set; }
public List<NotificationUserId> NotificationUserIds { get; set; }
public List<UserNotificationPreferences> UserNotificationPreferences { get; set; }

@ -7,15 +7,15 @@ namespace Ombi.Store.Entities
[Table("PlexEpisode")]
public class PlexEpisode : MediaServerEpisode
{
public int Key { get; set; } // RatingKey
public string Key { get; set; } // RatingKey
/// <value>
/// The parent key.
/// </value>
public int ParentKey { get; set; }
public string ParentKey { get; set; }
/// <value>
/// The grandparent key.
/// </value>
public int GrandparentKey { get; set; }
public string GrandparentKey { get; set; }
[NotMapped]
public PlexServerContent PlexSeries
{

@ -40,7 +40,7 @@ namespace Ombi.Store.Entities
/// <summary>
/// Plex's internal ID for this item
/// </summary>
public int Key { get; set; }
public string Key { get; set; }
public int? RequestId { get; set; }
@ -50,9 +50,9 @@ namespace Ombi.Store.Entities
[Table("PlexSeasonsContent")]
public class PlexSeasonsContent : Entity
{
public int PlexContentId { get; set; }
public string PlexContentId { get; set; }
public int SeasonNumber { get; set; }
public int SeasonKey { get; set; }
public int ParentKey { get; set; }
public string SeasonKey { get; set; }
public string ParentKey { get; set; }
}
}

@ -7,7 +7,7 @@
<Version></Version>
<PackageVersion></PackageVersion>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -13,8 +13,8 @@ namespace Ombi.Store.Repository
Task<bool> ContentExists(string providerId);
Task<PlexServerContent> Get(string providerId, ProviderType type);
Task<PlexServerContent> GetByType(string providerId, ProviderType type, MediaType mediaType);
Task<PlexServerContent> GetByKey(int key);
Task<PlexEpisode> GetEpisodeByKey(int key);
Task<PlexServerContent> GetByKey(string key);
Task<PlexEpisode> GetEpisodeByKey(string key);
IEnumerable<PlexServerContent> GetWhereContentByCustom(Expression<Func<PlexServerContent, bool>> predicate);
Task<PlexServerContent> GetFirstContentByCustom(Expression<Func<PlexServerContent, bool>> predicate);
Task DeleteEpisode(PlexEpisode content);

@ -92,7 +92,7 @@ namespace Ombi.Store.Repository
return null;
}
public async Task<PlexServerContent> GetByKey(int key)
public async Task<PlexServerContent> GetByKey(string key)
{
return await Db.PlexServerContent.Include(x => x.Seasons).FirstOrDefaultAsync(x => x.Key == key);
}
@ -154,7 +154,7 @@ namespace Ombi.Store.Repository
await InternalSaveChanges();
}
public async Task<PlexEpisode> GetEpisodeByKey(int key)
public async Task<PlexEpisode> GetEpisodeByKey(string key)
{
return await Db.PlexEpisode.FirstOrDefaultAsync(x => x.Key == key);
}

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
</PropertyGroup>

@ -7,7 +7,7 @@
<FileVersion>3.0.0.0</FileVersion>
<Version></Version>
<PackageVersion></PackageVersion>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
<Configurations>Debug;Release;NonUiBuild</Configurations>
<!--<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>-->
</PropertyGroup>

Loading…
Cancel
Save