From ffc4cc4a0472989f96d62d9082b5b3a4fd56fbac Mon Sep 17 00:00:00 2001 From: ProfessionalismIsMyMiddleName Date: Wed, 25 Jan 2023 07:35:18 +0100 Subject: [PATCH] Save modified userData after parsing an nfo in case of "watched", "playcount" or "lastplayed" tags. --- .../Parsers/BaseNfoParser.cs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs index 96c512a46..c3a735c6d 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs @@ -266,11 +266,6 @@ namespace MediaBrowser.XbmcMetadata.Parsers var nfoConfiguration = _config.GetNfoConfiguration(); UserItemData? userData = null; - if (!string.IsNullOrWhiteSpace(nfoConfiguration.UserId)) - { - var user = _userManager.GetUserById(Guid.Parse(nfoConfiguration.UserId)); - userData = _userDataManager.GetUserData(user, item); - } switch (reader.Name) { @@ -370,9 +365,12 @@ namespace MediaBrowser.XbmcMetadata.Parsers { var val = reader.ReadElementContentAsBoolean(); - if (userData is not null) + if (!string.IsNullOrWhiteSpace(nfoConfiguration.UserId)) { + var user = _userManager.GetUserById(Guid.Parse(nfoConfiguration.UserId)); + userData = _userDataManager.GetUserData(user, item); userData.Played = val; + _userDataManager.SaveUserData(user, item, userData, UserDataSaveReason.Import, CancellationToken.None); } break; @@ -381,11 +379,14 @@ namespace MediaBrowser.XbmcMetadata.Parsers case "playcount": { var val = reader.ReadElementContentAsString(); - if (!string.IsNullOrWhiteSpace(val) && userData is not null) + if (!string.IsNullOrWhiteSpace(val) && !string.IsNullOrWhiteSpace(nfoConfiguration.UserId)) { if (int.TryParse(val, NumberStyles.Integer, CultureInfo.InvariantCulture, out var count)) { + var user = _userManager.GetUserById(Guid.Parse(nfoConfiguration.UserId)); + userData = _userDataManager.GetUserData(user, item); userData.PlayCount = count; + _userDataManager.SaveUserData(user, item, userData, UserDataSaveReason.Import, CancellationToken.None); } } @@ -395,12 +396,15 @@ namespace MediaBrowser.XbmcMetadata.Parsers case "lastplayed": { var val = reader.ReadElementContentAsString(); - if (!string.IsNullOrWhiteSpace(val) && userData is not null) + if (!string.IsNullOrWhiteSpace(val) && !string.IsNullOrWhiteSpace(nfoConfiguration.UserId)) { if (DateTime.TryParse(val, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal, out var added)) { + var user = _userManager.GetUserById(Guid.Parse(nfoConfiguration.UserId)); + userData = _userDataManager.GetUserData(user, item); userData.LastPlayedDate = added; - } + _userDataManager.SaveUserData(user, item, userData, UserDataSaveReason.Import, CancellationToken.None); + } else { Logger.LogWarning("Invalid lastplayed value found: {Value}", val);