From 3a4c33ca5f8dbfa1bcf7b46c76a67e100404c1d4 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 9 Feb 2021 12:42:55 +0100 Subject: [PATCH 1/4] Add nfo parsing for watched, playcount and lastplayed --- .../Parsers/BaseNfoParser.cs | 74 +++++++++++++++++-- .../Parsers/EpisodeNfoParser.cs | 18 +++-- .../Parsers/MovieNfoParser.cs | 18 +++-- .../Parsers/SeasonNfoParser.cs | 18 +++-- .../Parsers/SeriesNfoParser.cs | 17 +++-- .../Providers/AlbumNfoProvider.cs | 21 ++++-- .../Providers/ArtistNfoProvider.cs | 21 ++++-- .../Providers/BaseVideoNfoProvider.cs | 11 ++- .../Providers/EpisodeNfoProvider.cs | 21 ++++-- .../Providers/MovieNfoProvider.cs | 17 +++-- .../Providers/MusicVideoNfoProvider.cs | 21 ++++-- .../Providers/SeasonNfoProvider.cs | 21 ++++-- .../Providers/SeriesNfoProvider.cs | 21 ++++-- .../Providers/VideoNfoProvider.cs | 21 ++++-- .../Parsers/EpisodeNfoProviderTests.cs | 6 +- .../Parsers/MovieNfoParserTests.cs | 6 +- .../Parsers/MusicAlbumNfoProviderTests.cs | 6 +- .../Parsers/MusicArtistNfoParserTests.cs | 6 +- .../Parsers/SeasonNfoProviderTests.cs | 6 +- .../Parsers/SeriesNfoParserTests.cs | 6 +- 20 files changed, 274 insertions(+), 82 deletions(-) diff --git a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs index f889327e0e..34861c463b 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs @@ -12,6 +12,7 @@ using System.Xml; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using MediaBrowser.XbmcMetadata.Configuration; @@ -24,20 +25,31 @@ namespace MediaBrowser.XbmcMetadata.Parsers where T : BaseItem { private readonly IConfigurationManager _config; + private readonly IUserManager _userManager; + private readonly IUserDataManager _userDataManager; private Dictionary _validProviderIds; /// /// Initializes a new instance of the class. /// - /// The logger. - /// the configuration manager. - /// The provider manager. - public BaseNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager) + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + public BaseNfoParser( + ILogger logger, + IConfigurationManager config, + IProviderManager providerManager, + IUserManager userManager, + IUserDataManager userDataManager) { Logger = logger; _config = config; ProviderManager = providerManager; _validProviderIds = new Dictionary(); + _userManager = userManager; + _userDataManager = userDataManager; } protected CultureInfo UsCulture { get; } = new CultureInfo("en-US"); @@ -261,6 +273,14 @@ namespace MediaBrowser.XbmcMetadata.Parsers { var item = itemResult.Item; + 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) { // DateCreated @@ -355,6 +375,48 @@ namespace MediaBrowser.XbmcMetadata.Parsers break; } + case "watched": + { + if (userData != null) + { + userData.Played = reader.ReadElementContentAsBoolean(); + } + + break; + } + + case "playcount": + { + if (userData != null) + { + userData.PlayCount = reader.ReadElementContentAsInt(); + } + + break; + } + + case "lasplayed": + { + if (userData != null) + { + var val = reader.ReadElementContentAsString(); + + if (!string.IsNullOrWhiteSpace(val)) + { + if (DateTime.TryParse(val, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var added)) + { + userData.LastPlayedDate = added.ToUniversalTime(); + } + else + { + Logger.LogWarning("Invalid lastplayed value found: {Value}", val); + } + } + } + + break; + } + case "countrycode": { var val = reader.ReadElementContentAsString(); @@ -622,7 +684,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers case "premiered": case "releasedate": { - var formatString = _config.GetNfoConfiguration().ReleaseDateFormat; + var formatString = nfoConfiguration.ReleaseDateFormat; var val = reader.ReadElementContentAsString(); @@ -640,7 +702,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers case "enddate": { - var formatString = _config.GetNfoConfiguration().ReleaseDateFormat; + var formatString = nfoConfiguration.ReleaseDateFormat; var val = reader.ReadElementContentAsString(); diff --git a/MediaBrowser.XbmcMetadata/Parsers/EpisodeNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/EpisodeNfoParser.cs index 81774b8735..f0c50d8e51 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/EpisodeNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/EpisodeNfoParser.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Xml; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using Microsoft.Extensions.Logging; @@ -19,11 +20,18 @@ namespace MediaBrowser.XbmcMetadata.Parsers /// /// Initializes a new instance of the class. /// - /// The logger. - /// the configuration manager. - /// The provider manager. - public EpisodeNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager) - : base(logger, config, providerManager) + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + public EpisodeNfoParser( + ILogger logger, + IConfigurationManager config, + IProviderManager providerManager, + IUserManager userManager, + IUserDataManager userDataManager) + : base(logger, config, providerManager, userManager, userDataManager) { } diff --git a/MediaBrowser.XbmcMetadata/Parsers/MovieNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/MovieNfoParser.cs index 33b0ae887f..2d0eb8433d 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/MovieNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/MovieNfoParser.cs @@ -5,6 +5,7 @@ using System.Xml; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using Microsoft.Extensions.Logging; @@ -19,11 +20,18 @@ namespace MediaBrowser.XbmcMetadata.Parsers /// /// Initializes a new instance of the class. /// - /// The logger. - /// the configuration manager. - /// The provider manager. - public MovieNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager) - : base(logger, config, providerManager) + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + public MovieNfoParser( + ILogger logger, + IConfigurationManager config, + IProviderManager providerManager, + IUserManager userManager, + IUserDataManager userDataManager) + : base(logger, config, providerManager, userManager, userDataManager) { } diff --git a/MediaBrowser.XbmcMetadata/Parsers/SeasonNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/SeasonNfoParser.cs index d8cd88b9a4..bd2607bd8d 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/SeasonNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/SeasonNfoParser.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Xml; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using Microsoft.Extensions.Logging; @@ -15,11 +16,18 @@ namespace MediaBrowser.XbmcMetadata.Parsers /// /// Initializes a new instance of the class. /// - /// The logger. - /// the configuration manager. - /// The provider manager. - public SeasonNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager) - : base(logger, config, providerManager) + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + public SeasonNfoParser( + ILogger logger, + IConfigurationManager config, + IProviderManager providerManager, + IUserManager userManager, + IUserDataManager userDataManager) + : base(logger, config, providerManager, userManager, userDataManager) { } diff --git a/MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs index 74a724989a..fbab8b5214 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/SeriesNfoParser.cs @@ -17,11 +17,18 @@ namespace MediaBrowser.XbmcMetadata.Parsers /// /// Initializes a new instance of the class. /// - /// The logger. - /// the configuration manager. - /// The provider manager. - public SeriesNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager) - : base(logger, config, providerManager) + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + public SeriesNfoParser( + ILogger logger, + IConfigurationManager config, + IProviderManager providerManager, + IUserManager userManager, + IUserDataManager userDataManager) + : base(logger, config, providerManager, userManager, userDataManager) { } diff --git a/MediaBrowser.XbmcMetadata/Providers/AlbumNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/AlbumNfoProvider.cs index 433a936d91..24f1274112 100644 --- a/MediaBrowser.XbmcMetadata/Providers/AlbumNfoProvider.cs +++ b/MediaBrowser.XbmcMetadata/Providers/AlbumNfoProvider.cs @@ -2,6 +2,7 @@ using System.IO; using System.Threading; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.IO; using MediaBrowser.XbmcMetadata.Parsers; @@ -17,30 +18,38 @@ namespace MediaBrowser.XbmcMetadata.Providers private readonly ILogger _logger; private readonly IConfigurationManager _config; private readonly IProviderManager _providerManager; + private readonly IUserManager _userManager; + private readonly IUserDataManager _userDataManager; /// /// Initializes a new instance of the class. /// - /// The logger. - /// The file system. - /// the configuration manager. - /// The provider manager. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. public AlbumNfoProvider( ILogger logger, IFileSystem fileSystem, IConfigurationManager config, - IProviderManager providerManager) + IProviderManager providerManager, + IUserManager userManager, + IUserDataManager userDataManager) : base(fileSystem) { _logger = logger; _config = config; _providerManager = providerManager; + _userManager = userManager; + _userDataManager = userDataManager; } /// protected override void Fetch(MetadataResult result, string path, CancellationToken cancellationToken) { - new BaseNfoParser(_logger, _config, _providerManager).Fetch(result, path, cancellationToken); + new BaseNfoParser(_logger, _config, _providerManager, _userManager, _userDataManager).Fetch(result, path, cancellationToken); } /// diff --git a/MediaBrowser.XbmcMetadata/Providers/ArtistNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/ArtistNfoProvider.cs index d69cdc90ae..fac28ab59c 100644 --- a/MediaBrowser.XbmcMetadata/Providers/ArtistNfoProvider.cs +++ b/MediaBrowser.XbmcMetadata/Providers/ArtistNfoProvider.cs @@ -2,6 +2,7 @@ using System.IO; using System.Threading; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.IO; using MediaBrowser.XbmcMetadata.Parsers; @@ -17,30 +18,38 @@ namespace MediaBrowser.XbmcMetadata.Providers private readonly ILogger _logger; private readonly IConfigurationManager _config; private readonly IProviderManager _providerManager; + private readonly IUserManager _userManager; + private readonly IUserDataManager _userDataManager; /// /// Initializes a new instance of the class. /// - /// The logger. - /// The file system. - /// the configuration manager. - /// The provider manager. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. public ArtistNfoProvider( IFileSystem fileSystem, ILogger logger, IConfigurationManager config, - IProviderManager providerManager) + IProviderManager providerManager, + IUserManager userManager, + IUserDataManager userDataManager) : base(fileSystem) { _logger = logger; _config = config; _providerManager = providerManager; + _userManager = userManager; + _userDataManager = userDataManager; } /// protected override void Fetch(MetadataResult result, string path, CancellationToken cancellationToken) { - new BaseNfoParser(_logger, _config, _providerManager).Fetch(result, path, cancellationToken); + new BaseNfoParser(_logger, _config, _providerManager, _userManager, _userDataManager).Fetch(result, path, cancellationToken); } /// diff --git a/MediaBrowser.XbmcMetadata/Providers/BaseVideoNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/BaseVideoNfoProvider.cs index e7aa3ca074..af722748b5 100644 --- a/MediaBrowser.XbmcMetadata/Providers/BaseVideoNfoProvider.cs +++ b/MediaBrowser.XbmcMetadata/Providers/BaseVideoNfoProvider.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.IO; using MediaBrowser.XbmcMetadata.Parsers; @@ -18,17 +19,23 @@ namespace MediaBrowser.XbmcMetadata.Providers private readonly ILogger> _logger; private readonly IConfigurationManager _config; private readonly IProviderManager _providerManager; + private readonly IUserManager _userManager; + private readonly IUserDataManager _userDataManager; public BaseVideoNfoProvider( ILogger> logger, IFileSystem fileSystem, IConfigurationManager config, - IProviderManager providerManager) + IProviderManager providerManager, + IUserManager userManager, + IUserDataManager userDataManager) : base(fileSystem) { _logger = logger; _config = config; _providerManager = providerManager; + _userManager = userManager; + _userDataManager = userDataManager; } /// @@ -38,7 +45,7 @@ namespace MediaBrowser.XbmcMetadata.Providers { Item = result.Item }; - new MovieNfoParser(_logger, _config, _providerManager).Fetch(tmpItem, path, cancellationToken); + new MovieNfoParser(_logger, _config, _providerManager, _userManager, _userDataManager).Fetch(tmpItem, path, cancellationToken); result.Item = (T)tmpItem.Item; result.People = tmpItem.People; diff --git a/MediaBrowser.XbmcMetadata/Providers/EpisodeNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/EpisodeNfoProvider.cs index 26983b1a69..7233f99dcb 100644 --- a/MediaBrowser.XbmcMetadata/Providers/EpisodeNfoProvider.cs +++ b/MediaBrowser.XbmcMetadata/Providers/EpisodeNfoProvider.cs @@ -2,6 +2,7 @@ using System.IO; using System.Threading; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.IO; using MediaBrowser.XbmcMetadata.Parsers; @@ -17,30 +18,38 @@ namespace MediaBrowser.XbmcMetadata.Providers private readonly ILogger _logger; private readonly IConfigurationManager _config; private readonly IProviderManager _providerManager; + private readonly IUserManager _userManager; + private readonly IUserDataManager _userDataManager; /// /// Initializes a new instance of the class. /// - /// The logger. - /// The file system. - /// the configuration manager. - /// The provider manager. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. public EpisodeNfoProvider( ILogger logger, IFileSystem fileSystem, IConfigurationManager config, - IProviderManager providerManager) + IProviderManager providerManager, + IUserManager userManager, + IUserDataManager userDataManager) : base(fileSystem) { _logger = logger; _config = config; _providerManager = providerManager; + _userManager = userManager; + _userDataManager = userDataManager; } /// protected override void Fetch(MetadataResult result, string path, CancellationToken cancellationToken) { - new EpisodeNfoParser(_logger, _config, _providerManager).Fetch(result, path, cancellationToken); + new EpisodeNfoParser(_logger, _config, _providerManager, _userManager, _userDataManager).Fetch(result, path, cancellationToken); } /// diff --git a/MediaBrowser.XbmcMetadata/Providers/MovieNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/MovieNfoProvider.cs index e3f6bada1b..811d39a9da 100644 --- a/MediaBrowser.XbmcMetadata/Providers/MovieNfoProvider.cs +++ b/MediaBrowser.XbmcMetadata/Providers/MovieNfoProvider.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities.Movies; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.IO; using Microsoft.Extensions.Logging; @@ -14,16 +15,20 @@ namespace MediaBrowser.XbmcMetadata.Providers /// /// Initializes a new instance of the class. /// - /// The logger. - /// The file system. - /// the configuration manager. - /// The provider manager. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. public MovieNfoProvider( ILogger logger, IFileSystem fileSystem, IConfigurationManager config, - IProviderManager providerManager) - : base(logger, fileSystem, config, providerManager) + IProviderManager providerManager, + IUserManager userManager, + IUserDataManager userDataManager) + : base(logger, fileSystem, config, providerManager, userManager, userDataManager) { } } diff --git a/MediaBrowser.XbmcMetadata/Providers/MusicVideoNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/MusicVideoNfoProvider.cs index b490a7120c..09df509eed 100644 --- a/MediaBrowser.XbmcMetadata/Providers/MusicVideoNfoProvider.cs +++ b/MediaBrowser.XbmcMetadata/Providers/MusicVideoNfoProvider.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.IO; using Microsoft.Extensions.Logging; @@ -14,12 +15,20 @@ namespace MediaBrowser.XbmcMetadata.Providers /// /// Initializes a new instance of the class. /// - /// The logger. - /// The file system. - /// the configuration manager. - /// The provider manager. - public MusicVideoNfoProvider(ILogger logger, IFileSystem fileSystem, IConfigurationManager config, IProviderManager providerManager) - : base(logger, fileSystem, config, providerManager) + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + public MusicVideoNfoProvider( + ILogger logger, + IFileSystem fileSystem, + IConfigurationManager config, + IProviderManager providerManager, + IUserManager userManager, + IUserDataManager userDataManager) + : base(logger, fileSystem, config, providerManager, userManager, userDataManager) { } } diff --git a/MediaBrowser.XbmcMetadata/Providers/SeasonNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/SeasonNfoProvider.cs index 0603fd0d13..8f0ed6df78 100644 --- a/MediaBrowser.XbmcMetadata/Providers/SeasonNfoProvider.cs +++ b/MediaBrowser.XbmcMetadata/Providers/SeasonNfoProvider.cs @@ -2,6 +2,7 @@ using System.IO; using System.Threading; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.IO; using MediaBrowser.XbmcMetadata.Parsers; @@ -17,30 +18,38 @@ namespace MediaBrowser.XbmcMetadata.Providers private readonly ILogger _logger; private readonly IConfigurationManager _config; private readonly IProviderManager _providerManager; + private readonly IUserManager _userManager; + private readonly IUserDataManager _userDataManager; /// /// Initializes a new instance of the class. /// - /// The logger. - /// The file system. - /// the configuration manager. - /// The provider manager. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. public SeasonNfoProvider( ILogger logger, IFileSystem fileSystem, IConfigurationManager config, - IProviderManager providerManager) + IProviderManager providerManager, + IUserManager userManager, + IUserDataManager userDataManager) : base(fileSystem) { _logger = logger; _config = config; _providerManager = providerManager; + _userManager = userManager; + _userDataManager = userDataManager; } /// protected override void Fetch(MetadataResult result, string path, CancellationToken cancellationToken) { - new SeasonNfoParser(_logger, _config, _providerManager).Fetch(result, path, cancellationToken); + new SeasonNfoParser(_logger, _config, _providerManager, _userManager, _userDataManager).Fetch(result, path, cancellationToken); } /// diff --git a/MediaBrowser.XbmcMetadata/Providers/SeriesNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/SeriesNfoProvider.cs index 7e059e0aae..3e496dc584 100644 --- a/MediaBrowser.XbmcMetadata/Providers/SeriesNfoProvider.cs +++ b/MediaBrowser.XbmcMetadata/Providers/SeriesNfoProvider.cs @@ -2,6 +2,7 @@ using System.IO; using System.Threading; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.IO; using MediaBrowser.XbmcMetadata.Parsers; @@ -17,30 +18,38 @@ namespace MediaBrowser.XbmcMetadata.Providers private readonly ILogger _logger; private readonly IConfigurationManager _config; private readonly IProviderManager _providerManager; + private readonly IUserManager _userManager; + private readonly IUserDataManager _userDataManager; /// /// Initializes a new instance of the class. /// - /// The logger. - /// The file system. - /// the configuration manager. - /// The provider manager. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. public SeriesNfoProvider( ILogger logger, IFileSystem fileSystem, IConfigurationManager config, - IProviderManager providerManager) + IProviderManager providerManager, + IUserManager userManager, + IUserDataManager userDataManager) : base(fileSystem) { _logger = logger; _config = config; _providerManager = providerManager; + _userManager = userManager; + _userDataManager = userDataManager; } /// protected override void Fetch(MetadataResult result, string path, CancellationToken cancellationToken) { - new SeriesNfoParser(_logger, _config, _providerManager).Fetch(result, path, cancellationToken); + new SeriesNfoParser(_logger, _config, _providerManager, _userManager, _userDataManager).Fetch(result, path, cancellationToken); } /// diff --git a/MediaBrowser.XbmcMetadata/Providers/VideoNfoProvider.cs b/MediaBrowser.XbmcMetadata/Providers/VideoNfoProvider.cs index f66ad30ca6..4717d81e6f 100644 --- a/MediaBrowser.XbmcMetadata/Providers/VideoNfoProvider.cs +++ b/MediaBrowser.XbmcMetadata/Providers/VideoNfoProvider.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.IO; using Microsoft.Extensions.Logging; @@ -14,12 +15,20 @@ namespace MediaBrowser.XbmcMetadata.Providers /// /// Initializes a new instance of the class. /// - /// The logger. - /// The file system. - /// the configuration manager. - /// The provider manager. - public VideoNfoProvider(ILogger logger, IFileSystem fileSystem, IConfigurationManager config, IProviderManager providerManager) - : base(logger, fileSystem, config, providerManager) + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + /// Instance of the interface. + public VideoNfoProvider( + ILogger logger, + IFileSystem fileSystem, + IConfigurationManager config, + IProviderManager providerManager, + IUserManager userManager, + IUserDataManager userDataManager) + : base(logger, fileSystem, config, providerManager, userManager, userDataManager) { } } diff --git a/tests/Jellyfin.XbmcMetadata.Tests/Parsers/EpisodeNfoProviderTests.cs b/tests/Jellyfin.XbmcMetadata.Tests/Parsers/EpisodeNfoProviderTests.cs index 67b4b969a3..1c41d0707c 100644 --- a/tests/Jellyfin.XbmcMetadata.Tests/Parsers/EpisodeNfoProviderTests.cs +++ b/tests/Jellyfin.XbmcMetadata.Tests/Parsers/EpisodeNfoProviderTests.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; @@ -28,7 +29,10 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers var config = new Mock(); config.Setup(x => x.GetConfiguration(It.IsAny())) .Returns(new XbmcMetadataOptions()); - _parser = new EpisodeNfoParser(new NullLogger(), config.Object, providerManager.Object); + var user = new Mock(); + var userData = new Mock(); + + _parser = new EpisodeNfoParser(new NullLogger(), config.Object, providerManager.Object, user.Object, userData.Object); } [Fact] diff --git a/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MovieNfoParserTests.cs b/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MovieNfoParserTests.cs index 765464eced..9710d31d85 100644 --- a/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MovieNfoParserTests.cs +++ b/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MovieNfoParserTests.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; @@ -26,7 +27,10 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers var config = new Mock(); config.Setup(x => x.GetConfiguration(It.IsAny())) .Returns(new XbmcMetadataOptions()); - _parser = new MovieNfoParser(new NullLogger(), config.Object, providerManager.Object); + var user = new Mock(); + var userData = new Mock(); + + _parser = new MovieNfoParser(new NullLogger(), config.Object, providerManager.Object, user.Object, userData.Object); } [Fact] diff --git a/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MusicAlbumNfoProviderTests.cs b/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MusicAlbumNfoProviderTests.cs index bdffea560c..0db0fa65df 100644 --- a/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MusicAlbumNfoProviderTests.cs +++ b/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MusicAlbumNfoProviderTests.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; @@ -28,7 +29,10 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers var config = new Mock(); config.Setup(x => x.GetConfiguration(It.IsAny())) .Returns(new XbmcMetadataOptions()); - _parser = new BaseNfoParser(new NullLogger>(), config.Object, providerManager.Object); + var user = new Mock(); + var userData = new Mock(); + + _parser = new BaseNfoParser(new NullLogger>(), config.Object, providerManager.Object, user.Object, userData.Object); } [Fact] diff --git a/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MusicArtistNfoParserTests.cs b/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MusicArtistNfoParserTests.cs index 2a4d376c6b..18daa66ac0 100644 --- a/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MusicArtistNfoParserTests.cs +++ b/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MusicArtistNfoParserTests.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; @@ -26,7 +27,10 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers var config = new Mock(); config.Setup(x => x.GetConfiguration(It.IsAny())) .Returns(new XbmcMetadataOptions()); - _parser = new BaseNfoParser(new NullLogger>(), config.Object, providerManager.Object); + var user = new Mock(); + var userData = new Mock(); + + _parser = new BaseNfoParser(new NullLogger>(), config.Object, providerManager.Object, user.Object, userData.Object); } [Fact] diff --git a/tests/Jellyfin.XbmcMetadata.Tests/Parsers/SeasonNfoProviderTests.cs b/tests/Jellyfin.XbmcMetadata.Tests/Parsers/SeasonNfoProviderTests.cs index 68b7239d22..602db7c09a 100644 --- a/tests/Jellyfin.XbmcMetadata.Tests/Parsers/SeasonNfoProviderTests.cs +++ b/tests/Jellyfin.XbmcMetadata.Tests/Parsers/SeasonNfoProviderTests.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; @@ -28,7 +29,10 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers var config = new Mock(); config.Setup(x => x.GetConfiguration(It.IsAny())) .Returns(new XbmcMetadataOptions()); - _parser = new SeasonNfoParser(new NullLogger(), config.Object, providerManager.Object); + var user = new Mock(); + var userData = new Mock(); + + _parser = new SeasonNfoParser(new NullLogger(), config.Object, providerManager.Object, user.Object, userData.Object); } [Fact] diff --git a/tests/Jellyfin.XbmcMetadata.Tests/Parsers/SeriesNfoParserTests.cs b/tests/Jellyfin.XbmcMetadata.Tests/Parsers/SeriesNfoParserTests.cs index 3bbfb66e3e..2bd53213e7 100644 --- a/tests/Jellyfin.XbmcMetadata.Tests/Parsers/SeriesNfoParserTests.cs +++ b/tests/Jellyfin.XbmcMetadata.Tests/Parsers/SeriesNfoParserTests.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; @@ -26,7 +27,10 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers var config = new Mock(); config.Setup(x => x.GetConfiguration(It.IsAny())) .Returns(new XbmcMetadataOptions()); - _parser = new SeriesNfoParser(new NullLogger(), config.Object, providerManager.Object); + var user = new Mock(); + var userData = new Mock(); + + _parser = new SeriesNfoParser(new NullLogger(), config.Object, providerManager.Object, user.Object, userData.Object); } [Fact] From dc2f8b5e6b01e4bf47aa47f8833e27aa3a47d2b6 Mon Sep 17 00:00:00 2001 From: David Ullmer Date: Thu, 11 Feb 2021 12:43:36 +0100 Subject: [PATCH 2/4] Fix xml loop --- .../Parsers/BaseNfoParser.cs | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs index 34861c463b..56c546475a 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs @@ -377,9 +377,11 @@ namespace MediaBrowser.XbmcMetadata.Parsers case "watched": { + var val = reader.ReadElementContentAsBoolean(); + if (userData != null) { - userData.Played = reader.ReadElementContentAsBoolean(); + userData.Played = val; } break; @@ -387,9 +389,13 @@ namespace MediaBrowser.XbmcMetadata.Parsers case "playcount": { - if (userData != null) + var val = reader.ReadElementContentAsString(); + if (!string.IsNullOrWhiteSpace(val) && userData != null) { - userData.PlayCount = reader.ReadElementContentAsInt(); + if (int.TryParse(val.Split(' ')[0], NumberStyles.Integer, UsCulture, out var count)) + { + userData.PlayCount = count; + } } break; @@ -397,20 +403,16 @@ namespace MediaBrowser.XbmcMetadata.Parsers case "lasplayed": { - if (userData != null) + var val = reader.ReadElementContentAsString(); + if (!string.IsNullOrWhiteSpace(val) && userData != null) { - var val = reader.ReadElementContentAsString(); - - if (!string.IsNullOrWhiteSpace(val)) + if (DateTime.TryParse(val, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var added)) { - if (DateTime.TryParse(val, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var added)) - { - userData.LastPlayedDate = added.ToUniversalTime(); - } - else - { - Logger.LogWarning("Invalid lastplayed value found: {Value}", val); - } + userData.LastPlayedDate = added.ToUniversalTime(); + } + else + { + Logger.LogWarning("Invalid lastplayed value found: {Value}", val); } } From ae57ed4ac70eda1046c86e40e41b9683b2115f59 Mon Sep 17 00:00:00 2001 From: David Ullmer Date: Thu, 11 Feb 2021 13:36:35 +0100 Subject: [PATCH 3/4] Add nfo user data tests --- .../Parsers/BaseNfoParser.cs | 2 +- .../Parsers/MovieNfoParserTests.cs | 31 ++++++++++++++++--- .../Test Data/Justice League.nfo | 5 +-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs index 56c546475a..81af1819d9 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs @@ -401,7 +401,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers break; } - case "lasplayed": + case "lastplayed": { var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val) && userData != null) diff --git a/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MovieNfoParserTests.cs b/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MovieNfoParserTests.cs index 9710d31d85..4d4270a55d 100644 --- a/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MovieNfoParserTests.cs +++ b/tests/Jellyfin.XbmcMetadata.Tests/Parsers/MovieNfoParserTests.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Threading; +using Jellyfin.Data.Entities; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; @@ -18,19 +19,35 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers public class MovieNfoParserTests { private readonly MovieNfoParser _parser; + private readonly IUserDataManager _userDataManager; + private readonly User _testUser; public MovieNfoParserTests() { + _testUser = new User("Test User", "Auth provider", "Reset provider"); + var providerManager = new Mock(); providerManager.Setup(x => x.GetExternalIdInfos(It.IsAny())) .Returns(Enumerable.Empty()); - var config = new Mock(); - config.Setup(x => x.GetConfiguration(It.IsAny())) - .Returns(new XbmcMetadataOptions()); + + var nfoConfig = new XbmcMetadataOptions() + { + UserId = "F38E6443-090B-4F7A-BD12-9CFF5020F7BC" + }; + var configManager = new Mock(); + configManager.Setup(x => x.GetConfiguration(It.IsAny())) + .Returns(nfoConfig); + var user = new Mock(); + user.Setup(x => x.GetUserById(It.IsAny())) + .Returns(_testUser); + var userData = new Mock(); + userData.Setup(x => x.GetUserData(_testUser, It.IsAny())) + .Returns(new UserItemData()); - _parser = new MovieNfoParser(new NullLogger(), config.Object, providerManager.Object, user.Object, userData.Object); + _userDataManager = userData.Object; + _parser = new MovieNfoParser(new NullLogger(), configManager.Object, providerManager.Object, user.Object, userData.Object); } [Fact] @@ -91,6 +108,12 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers Assert.Equal("Test Lyricist", lyricist!.Name); Assert.Equal(new DateTime(2019, 8, 6, 9, 1, 18), item.DateCreated); + + // userData + var userData = _userDataManager.GetUserData(_testUser, item); + Assert.Equal(2, userData.PlayCount); + Assert.True(userData.Played); + Assert.Equal(new DateTime(2021, 02, 11, 07, 47, 23), userData.LastPlayedDate); } [Fact] diff --git a/tests/Jellyfin.XbmcMetadata.Tests/Test Data/Justice League.nfo b/tests/Jellyfin.XbmcMetadata.Tests/Test Data/Justice League.nfo index 6e6da25d30..98880cdc9e 100644 --- a/tests/Jellyfin.XbmcMetadata.Tests/Test Data/Justice League.nfo +++ b/tests/Jellyfin.XbmcMetadata.Tests/Test Data/Justice League.nfo @@ -30,6 +30,9 @@ Fueled by his restored faith in humanity and inspired by Superman's selfless act, Bruce Wayne enlists the help of his newfound ally, Diana Prince, to face an even greater enemy. Together, Batman and Wonder Woman work quickly to find and recruit a team of meta-humans to stand against this newly awakened threat. But despite the formation of this unprecedented league of heroes-Batman, Wonder Woman, Aquaman, Cyborg and The Flash-it may already be too late to save the planet from an assault of catastrophic proportions. Justice for all. 120 + 2 + true + 2021-02-11 07:47:23 https://assets.fanart.tv/fanart/movies/468551/movieposter/justice-league-collection-5c24ea65591d3.jpg https://assets.fanart.tv/fanart/movies/468551/movieposter/justice-league-collection-5c24ea65591d3.jpg https://assets.fanart.tv/fanart/movies/468551/hdmovielogo/justice-league-collection-5ba855ed4239a.png @@ -81,8 +84,6 @@ https://assets.fanart.tv/fanart/movies/141052/moviebackground/justice-league-5a119394ea362.jpg Australia:M - 0 - tt0974015 tt0974015 Action From eaaab10cf3e7ced50c0cb3587d0852b56bd52ead Mon Sep 17 00:00:00 2001 From: David Ullmer Date: Thu, 11 Feb 2021 14:15:11 +0100 Subject: [PATCH 4/4] Don't split playcount --- MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs index 8a9e6674ee..6f164caf37 100644 --- a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs +++ b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs @@ -392,7 +392,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers var val = reader.ReadElementContentAsString(); if (!string.IsNullOrWhiteSpace(val) && userData != null) { - if (int.TryParse(val.Split(' ')[0], NumberStyles.Integer, UsCulture, out var count)) + if (int.TryParse(val, NumberStyles.Integer, UsCulture, out var count)) { userData.PlayCount = count; }