mirror of
https://github.com/jellyfin/jellyfin-plugin-trakt.git
synced 2024-11-23 05:40:13 +00:00
10.10
This commit is contained in:
parent
74b894c55f
commit
a673d904bf
@ -47,6 +47,7 @@ public class TraktApi
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly IServerApplicationHost _appHost;
|
||||
private readonly IUserDataManager _userDataManager;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options;
|
||||
|
||||
/// <summary>
|
||||
@ -56,15 +57,18 @@ public class TraktApi
|
||||
/// <param name="httpClientFactory">The <see cref="IHttpClientFactory"/>.</param>
|
||||
/// <param name="appHost">The <see cref="IServerApplicationHost"/>.</param>
|
||||
/// <param name="userDataManager">The <see cref="IUserDataManager"/>.</param>
|
||||
/// <param name="userManager">The <see cref="IUserManager"/>.</param>
|
||||
public TraktApi(
|
||||
ILogger<TraktApi> logger,
|
||||
IHttpClientFactory httpClientFactory,
|
||||
IServerApplicationHost appHost,
|
||||
IUserDataManager userDataManager)
|
||||
IUserDataManager userDataManager,
|
||||
IUserManager userManager)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_appHost = appHost;
|
||||
_userDataManager = userDataManager;
|
||||
_userManager = userManager;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@ -707,10 +711,17 @@ public class TraktApi
|
||||
ArgumentOutOfRangeException.ThrowIfZero(movies.Count);
|
||||
ArgumentNullException.ThrowIfNull(traktUser);
|
||||
|
||||
var user = _userManager.GetUserById(traktUser.LinkedMbUserId);
|
||||
if (user is null)
|
||||
{
|
||||
_logger.LogWarning("User id ({UserId}) linked to Trakt does not exist", traktUser.LinkedMbUserId);
|
||||
return null;
|
||||
}
|
||||
|
||||
var moviesPayload = movies.Select(m =>
|
||||
{
|
||||
var lastPlayedDate = seen
|
||||
? _userDataManager.GetUserData(traktUser.LinkedMbUserId, m).LastPlayedDate
|
||||
? _userDataManager.GetUserData(user, m).LastPlayedDate
|
||||
: null;
|
||||
|
||||
return new TraktMovieWatched
|
||||
@ -784,6 +795,13 @@ public class TraktApi
|
||||
CancellationToken cancellationToken,
|
||||
bool useProviderIds = true)
|
||||
{
|
||||
var user = _userManager.GetUserById(traktUser.LinkedMbUserId);
|
||||
if (user is null)
|
||||
{
|
||||
_logger.LogWarning("User id ({UserId}) linked to Trakt does not exist", traktUser.LinkedMbUserId);
|
||||
return null;
|
||||
}
|
||||
|
||||
var data = new TraktSyncWatched
|
||||
{
|
||||
Episodes = new List<TraktEpisodeWatched>(),
|
||||
@ -793,7 +811,7 @@ public class TraktApi
|
||||
foreach (var episode in episodeChunk)
|
||||
{
|
||||
var lastPlayedDate = seen
|
||||
? _userDataManager.GetUserData(traktUser.LinkedMbUserId, episode)
|
||||
? _userDataManager.GetUserData(user, episode)
|
||||
.LastPlayedDate
|
||||
: null;
|
||||
|
||||
|
@ -37,15 +37,17 @@ public class TraktController : ControllerBase
|
||||
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
||||
/// <param name="httpClientFactory">Instance of the <see cref="IHttpClientFactory"/> interface.</param>
|
||||
/// <param name="appHost">Instance of the <see cref="IServerApplicationHost"/> interface.</param>
|
||||
/// <param name="userManager">Instance of the <see cref="IUserManager"/> interface.</param>
|
||||
public TraktController(
|
||||
IUserDataManager userDataManager,
|
||||
ILoggerFactory loggerFactory,
|
||||
IHttpClientFactory httpClientFactory,
|
||||
IServerApplicationHost appHost,
|
||||
ILibraryManager libraryManager)
|
||||
ILibraryManager libraryManager,
|
||||
IUserManager userManager)
|
||||
{
|
||||
_logger = loggerFactory.CreateLogger<TraktController>();
|
||||
_traktApi = new TraktApi(loggerFactory.CreateLogger<TraktApi>(), httpClientFactory, appHost, userDataManager);
|
||||
_traktApi = new TraktApi(loggerFactory.CreateLogger<TraktApi>(), httpClientFactory, appHost, userDataManager, userManager);
|
||||
_libraryManager = libraryManager;
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class SyncFromTraktTask : IScheduledTask
|
||||
_userDataManager = userDataManager;
|
||||
_libraryManager = libraryManager;
|
||||
_logger = loggerFactory.CreateLogger<SyncFromTraktTask>();
|
||||
_traktApi = new TraktApi(loggerFactory.CreateLogger<TraktApi>(), httpClientFactory, appHost, userDataManager);
|
||||
_traktApi = new TraktApi(loggerFactory.CreateLogger<TraktApi>(), httpClientFactory, appHost, userDataManager, userManager);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -206,7 +206,7 @@ public class SyncFromTraktTask : IScheduledTask
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var matchedWatchedMovie = Extensions.FindMatch(movie, traktWatchedMovies);
|
||||
var matchedPausedMovie = Extensions.FindMatch(movie, traktPausedMovies);
|
||||
var userData = _userDataManager.GetUserData(user.Id, movie);
|
||||
var userData = _userDataManager.GetUserData(user, movie);
|
||||
bool changed = false;
|
||||
|
||||
if (matchedWatchedMovie != null)
|
||||
@ -304,7 +304,7 @@ public class SyncFromTraktTask : IScheduledTask
|
||||
if (changed)
|
||||
{
|
||||
_userDataManager.SaveUserData(
|
||||
user.Id,
|
||||
user,
|
||||
movie,
|
||||
userData,
|
||||
UserDataSaveReason.Import,
|
||||
@ -321,7 +321,7 @@ public class SyncFromTraktTask : IScheduledTask
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var matchedWatchedShow = Extensions.FindMatch(episode.Series, traktWatchedShows);
|
||||
var matchedPausedEpisode = Extensions.FindMatch(episode, traktPausedEpisodes);
|
||||
var userData = _userDataManager.GetUserData(user.Id, episode);
|
||||
var userData = _userDataManager.GetUserData(user, episode);
|
||||
bool changed = false;
|
||||
bool episodeWatched = false;
|
||||
|
||||
@ -455,7 +455,7 @@ public class SyncFromTraktTask : IScheduledTask
|
||||
if (changed)
|
||||
{
|
||||
_userDataManager.SaveUserData(
|
||||
user.Id,
|
||||
user,
|
||||
episode,
|
||||
userData,
|
||||
UserDataSaveReason.Import,
|
||||
|
@ -60,7 +60,7 @@ public class SyncLibraryTask : IScheduledTask
|
||||
_userDataManager = userDataManager;
|
||||
_libraryManager = libraryManager;
|
||||
_logger = loggerFactory.CreateLogger<SyncLibraryTask>();
|
||||
_traktApi = new TraktApi(loggerFactory.CreateLogger<TraktApi>(), httpClientFactory, appHost, userDataManager);
|
||||
_traktApi = new TraktApi(loggerFactory.CreateLogger<TraktApi>(), httpClientFactory, appHost, userDataManager, userManager);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -199,7 +199,7 @@ public class SyncLibraryTask : IScheduledTask
|
||||
foreach (var libraryMovie in movieItems)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var userData = _userDataManager.GetUserData(user.Id, libraryMovie);
|
||||
var userData = _userDataManager.GetUserData(user, libraryMovie);
|
||||
|
||||
if (traktUser.SynchronizeCollections)
|
||||
{
|
||||
@ -438,7 +438,7 @@ public class SyncLibraryTask : IScheduledTask
|
||||
foreach (var episode in episodeItems)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var userData = _userDataManager.GetUserData(user.Id, episode);
|
||||
var userData = _userDataManager.GetUserData(user, episode);
|
||||
var isPlayedTraktTv = false;
|
||||
var traktWatchedShow = Extensions.FindMatch(episode.Series, traktWatchedShows);
|
||||
|
||||
|
@ -44,13 +44,15 @@ public class ServerMediator : IHostedService, IDisposable
|
||||
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
|
||||
/// <param name="httpClientFactory">The <see cref="IHttpClientFactory"/>.</param>
|
||||
/// <param name="appHost">The <see cref="IServerApplicationHost"/>.</param>
|
||||
/// <param name="userManager">The <see cref="IUserManager"/>.</param>
|
||||
public ServerMediator(
|
||||
ISessionManager sessionManager,
|
||||
IUserDataManager userDataManager,
|
||||
ILibraryManager libraryManager,
|
||||
ILoggerFactory loggerFactory,
|
||||
IHttpClientFactory httpClientFactory,
|
||||
IServerApplicationHost appHost)
|
||||
IServerApplicationHost appHost,
|
||||
IUserManager userManager)
|
||||
{
|
||||
_sessionManager = sessionManager;
|
||||
_libraryManager = libraryManager;
|
||||
@ -59,7 +61,7 @@ public class ServerMediator : IHostedService, IDisposable
|
||||
_logger = loggerFactory.CreateLogger<ServerMediator>();
|
||||
_playbackState = new Dictionary<Guid, PlaybackState>();
|
||||
|
||||
_traktApi = new TraktApi(loggerFactory.CreateLogger<TraktApi>(), httpClientFactory, appHost, userDataManager);
|
||||
_traktApi = new TraktApi(loggerFactory.CreateLogger<TraktApi>(), httpClientFactory, appHost, userDataManager, userManager);
|
||||
_libraryManagerEventsHelper = new LibraryManagerEventsHelper(loggerFactory.CreateLogger<LibraryManagerEventsHelper>(), _traktApi);
|
||||
_userDataManagerEventsHelper = new UserDataManagerEventsHelper(loggerFactory.CreateLogger<UserDataManagerEventsHelper>(), _traktApi);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user