add item to user data save event
This commit is contained in:
parent
77cff18dce
commit
6415776cd1
|
@ -228,7 +228,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
// Set favorite status
|
||||
data.IsFavorite = isFavorite;
|
||||
|
||||
await UserDataRepository.SaveUserData(userId, key, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None).ConfigureAwait(false);
|
||||
await UserDataRepository.SaveUserData(userId, item, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
data = UserDataRepository.GetUserData(userId, key);
|
||||
|
||||
|
@ -254,7 +254,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
|
||||
data.Likes = likes;
|
||||
|
||||
await UserDataRepository.SaveUserData(userId, key, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None).ConfigureAwait(false);
|
||||
await UserDataRepository.SaveUserData(userId, item, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
data = UserDataRepository.GetUserData(userId, key);
|
||||
|
||||
|
|
|
@ -608,7 +608,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
// Set favorite status
|
||||
data.IsFavorite = isFavorite;
|
||||
|
||||
await _userDataRepository.SaveUserData(user.Id, key, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None).ConfigureAwait(false);
|
||||
await _userDataRepository.SaveUserData(user.Id, item, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
data = _userDataRepository.GetUserData(user.Id, key);
|
||||
|
||||
|
@ -657,7 +657,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
|
||||
data.Likes = likes;
|
||||
|
||||
await _userDataRepository.SaveUserData(user.Id, key, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None).ConfigureAwait(false);
|
||||
await _userDataRepository.SaveUserData(user.Id, item, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
data = _userDataRepository.GetUserData(user.Id, key);
|
||||
|
||||
|
|
|
@ -1339,7 +1339,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
data.LastPlayedDate = datePlayed ?? data.LastPlayedDate;
|
||||
data.Played = true;
|
||||
|
||||
await userManager.SaveUserData(user.Id, key, data, UserDataSaveReason.TogglePlayed, CancellationToken.None).ConfigureAwait(false);
|
||||
await userManager.SaveUserData(user.Id, this, data, UserDataSaveReason.TogglePlayed, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1368,7 +1368,7 @@ namespace MediaBrowser.Controller.Entities
|
|||
data.LastPlayedDate = null;
|
||||
data.Played = false;
|
||||
|
||||
await userManager.SaveUserData(user.Id, key, data, UserDataSaveReason.TogglePlayed, CancellationToken.None).ConfigureAwait(false);
|
||||
await userManager.SaveUserData(user.Id, this, data, UserDataSaveReason.TogglePlayed, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -20,12 +20,12 @@ namespace MediaBrowser.Controller.Library
|
|||
/// Saves the user data.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="userData">The user data.</param>
|
||||
/// <param name="reason">The reason.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
Task SaveUserData(Guid userId, string key, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken);
|
||||
Task SaveUserData(Guid userId, BaseItem item, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user data.
|
||||
|
|
|
@ -32,5 +32,11 @@ namespace MediaBrowser.Controller.Library
|
|||
/// </summary>
|
||||
/// <value>The user data.</value>
|
||||
public UserItemData UserData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the item.
|
||||
/// </summary>
|
||||
/// <value>The item.</value>
|
||||
public BaseItem Item { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -248,11 +248,6 @@ namespace MediaBrowser.Controller.Providers
|
|||
return true;
|
||||
}
|
||||
|
||||
if (RequiresInternet && DateTime.UtcNow > (providerInfo.LastRefreshed.AddDays(ConfigurationManager.Configuration.MetadataRefreshDays)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (providerInfo.LastRefreshStatus != ProviderRefreshStatus.Success)
|
||||
{
|
||||
return true;
|
||||
|
|
|
@ -123,17 +123,13 @@ namespace MediaBrowser.Providers.TV
|
|||
|
||||
if (parts.Length == 3)
|
||||
{
|
||||
var seasonNumberString = parts[1];
|
||||
|
||||
int seasonNumber;
|
||||
|
||||
if (int.TryParse(seasonNumberString, NumberStyles.Integer, UsCulture, out seasonNumber))
|
||||
if (int.TryParse(parts[1], NumberStyles.Integer, UsCulture, out seasonNumber))
|
||||
{
|
||||
var episodeNumberString = parts[2];
|
||||
|
||||
int episodeNumber;
|
||||
|
||||
if (int.TryParse(episodeNumberString, NumberStyles.Integer, UsCulture, out episodeNumber))
|
||||
if (int.TryParse(parts[2], NumberStyles.Integer, UsCulture, out episodeNumber))
|
||||
{
|
||||
return new Tuple<int, int>(seasonNumber, episodeNumber);
|
||||
}
|
||||
|
@ -145,22 +141,17 @@ namespace MediaBrowser.Providers.TV
|
|||
.Where(i => i.Item1 != -1 && i.Item2 != -1)
|
||||
.ToList();
|
||||
|
||||
var existingEpisodes = series.RecursiveChildren
|
||||
.OfType<Episode>()
|
||||
.Where(i => i.IndexNumber.HasValue && i.ParentIndexNumber.HasValue)
|
||||
.ToList();
|
||||
|
||||
var hasChanges = false;
|
||||
|
||||
if (_config.Configuration.CreateVirtualMissingEpisodes || _config.Configuration.CreateVirtualFutureEpisodes)
|
||||
{
|
||||
if (_config.Configuration.EnableInternetProviders)
|
||||
{
|
||||
hasChanges = await AddMissingEpisodes(series, seriesDataPath, existingEpisodes, episodeLookup, cancellationToken).ConfigureAwait(false);
|
||||
hasChanges = await AddMissingEpisodes(series, seriesDataPath, episodeLookup, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
var anyRemoved = await RemoveObsoleteMissingEpisodes(series, existingEpisodes, cancellationToken).ConfigureAwait(false);
|
||||
var anyRemoved = await RemoveObsoleteMissingEpisodes(series, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (hasChanges || anyRemoved)
|
||||
{
|
||||
|
@ -174,12 +165,15 @@ namespace MediaBrowser.Providers.TV
|
|||
/// </summary>
|
||||
/// <param name="series">The series.</param>
|
||||
/// <param name="seriesDataPath">The series data path.</param>
|
||||
/// <param name="existingEpisodes">The existing episodes.</param>
|
||||
/// <param name="episodeLookup">The episode lookup.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
private async Task<bool> AddMissingEpisodes(Series series, string seriesDataPath, List<Episode> existingEpisodes, IEnumerable<Tuple<int, int>> episodeLookup, CancellationToken cancellationToken)
|
||||
private async Task<bool> AddMissingEpisodes(Series series, string seriesDataPath, IEnumerable<Tuple<int, int>> episodeLookup, CancellationToken cancellationToken)
|
||||
{
|
||||
var existingEpisodes = series.RecursiveChildren
|
||||
.OfType<Episode>()
|
||||
.ToList();
|
||||
|
||||
var hasChanges = false;
|
||||
|
||||
foreach (var tuple in episodeLookup)
|
||||
|
@ -209,8 +203,9 @@ namespace MediaBrowser.Providers.TV
|
|||
{
|
||||
continue;
|
||||
}
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
if (airDate.Value < DateTime.UtcNow && _config.Configuration.CreateVirtualMissingEpisodes)
|
||||
if (airDate.Value < now && _config.Configuration.CreateVirtualMissingEpisodes)
|
||||
{
|
||||
// tvdb has a lot of nearly blank episodes
|
||||
_logger.Info("Creating virtual missing episode {0} {1}x{2}", series.Name, tuple.Item1, tuple.Item2);
|
||||
|
@ -219,7 +214,7 @@ namespace MediaBrowser.Providers.TV
|
|||
|
||||
hasChanges = true;
|
||||
}
|
||||
else if (airDate.Value > DateTime.UtcNow && _config.Configuration.CreateVirtualFutureEpisodes)
|
||||
else if (airDate.Value > now && _config.Configuration.CreateVirtualFutureEpisodes)
|
||||
{
|
||||
// tvdb has a lot of nearly blank episodes
|
||||
_logger.Info("Creating virtual future episode {0} {1}x{2}", series.Name, tuple.Item1, tuple.Item2);
|
||||
|
@ -236,14 +231,21 @@ namespace MediaBrowser.Providers.TV
|
|||
/// <summary>
|
||||
/// Removes the virtual entry after a corresponding physical version has been added
|
||||
/// </summary>
|
||||
private async Task<bool> RemoveObsoleteMissingEpisodes(Series series, List<Episode> existingEpisodes, CancellationToken cancellationToken)
|
||||
private async Task<bool> RemoveObsoleteMissingEpisodes(Series series, CancellationToken cancellationToken)
|
||||
{
|
||||
var existingEpisodes = series.RecursiveChildren
|
||||
.OfType<Episode>()
|
||||
.ToList();
|
||||
|
||||
var physicalEpisodes = existingEpisodes
|
||||
.Where(i => i.LocationType != LocationType.Virtual)
|
||||
.ToList();
|
||||
|
||||
var episodesToRemove = existingEpisodes
|
||||
var virtualEpisodes = existingEpisodes
|
||||
.Where(i => i.LocationType == LocationType.Virtual)
|
||||
.ToList();
|
||||
|
||||
var episodesToRemove = virtualEpisodes
|
||||
.Where(i =>
|
||||
{
|
||||
if (i.IndexNumber.HasValue && i.ParentIndexNumber.HasValue)
|
||||
|
@ -279,7 +281,8 @@ namespace MediaBrowser.Providers.TV
|
|||
/// <returns>Task.</returns>
|
||||
private async Task AddEpisode(Series series, int seasonNumber, int episodeNumber, CancellationToken cancellationToken)
|
||||
{
|
||||
var season = series.Children.OfType<Season>().FirstOrDefault(i => i.IndexNumber.HasValue && i.IndexNumber.Value == seasonNumber);
|
||||
var season = series.Children.OfType<Season>()
|
||||
.FirstOrDefault(i => i.IndexNumber.HasValue && i.IndexNumber.Value == seasonNumber);
|
||||
|
||||
if (season == null)
|
||||
{
|
||||
|
@ -290,7 +293,7 @@ namespace MediaBrowser.Providers.TV
|
|||
|
||||
var episode = new Episode
|
||||
{
|
||||
Name = string.Format("Episode {0}", episodeNumber.ToString(UsCulture)),
|
||||
Name = name,
|
||||
IndexNumber = episodeNumber,
|
||||
ParentIndexNumber = seasonNumber,
|
||||
Parent = season,
|
||||
|
|
|
@ -37,37 +37,37 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
/// Saves the user data.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="userData">The user data.</param>
|
||||
/// <param name="reason">The reason.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">
|
||||
/// userData
|
||||
/// <exception cref="System.ArgumentNullException">userData
|
||||
/// or
|
||||
/// cancellationToken
|
||||
/// or
|
||||
/// userId
|
||||
/// or
|
||||
/// key
|
||||
/// </exception>
|
||||
public async Task SaveUserData(Guid userId, string key, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken)
|
||||
/// key</exception>
|
||||
public async Task SaveUserData(Guid userId, BaseItem item, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken)
|
||||
{
|
||||
if (userData == null)
|
||||
{
|
||||
throw new ArgumentNullException("userData");
|
||||
}
|
||||
if (item == null)
|
||||
{
|
||||
throw new ArgumentNullException("item");
|
||||
}
|
||||
if (userId == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("userId");
|
||||
}
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
throw new ArgumentNullException("key");
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var key = item.GetUserDataKey();
|
||||
|
||||
try
|
||||
{
|
||||
await Repository.SaveUserData(userId, key, userData, cancellationToken).ConfigureAwait(false);
|
||||
|
@ -89,7 +89,8 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
Key = key,
|
||||
UserData = userData,
|
||||
SaveReason = reason,
|
||||
UserId = userId
|
||||
UserId = userId,
|
||||
Item = item
|
||||
|
||||
}, _logger);
|
||||
}
|
||||
|
|
|
@ -254,7 +254,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
data.Played = true;
|
||||
}
|
||||
|
||||
await _userDataRepository.SaveUserData(user.Id, key, data, UserDataSaveReason.PlaybackStart, CancellationToken.None).ConfigureAwait(false);
|
||||
await _userDataRepository.SaveUserData(user.Id, info.Item, data, UserDataSaveReason.PlaybackStart, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
// Nothing to save here
|
||||
// Fire events to inform plugins
|
||||
|
@ -298,7 +298,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
|
||||
UpdatePlayState(info.Item, data, info.PositionTicks.Value);
|
||||
|
||||
await _userDataRepository.SaveUserData(user.Id, key, data, UserDataSaveReason.PlaybackProgress, CancellationToken.None).ConfigureAwait(false);
|
||||
await _userDataRepository.SaveUserData(user.Id, info.Item, data, UserDataSaveReason.PlaybackProgress, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
EventHelper.QueueEventIfNotNull(PlaybackProgress, this, new PlaybackProgressEventArgs
|
||||
|
@ -361,7 +361,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
data.PlaybackPositionTicks = 0;
|
||||
}
|
||||
|
||||
await _userDataRepository.SaveUserData(user.Id, key, data, UserDataSaveReason.PlaybackFinished, CancellationToken.None).ConfigureAwait(false);
|
||||
await _userDataRepository.SaveUserData(user.Id, info.Item, data, UserDataSaveReason.PlaybackFinished, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
EventHelper.QueueEventIfNotNull(PlaybackStopped, this, new PlaybackProgressEventArgs
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user