From a348e1b8b3acf3b81fb6d03400b41080c9e1e6e3 Mon Sep 17 00:00:00 2001 From: lukepulverenti <3607463+LukePulverenti@users.noreply.github.com> Date: Thu, 11 Jul 2024 12:22:34 -0400 Subject: [PATCH] add game classes --- NfoMetadata/Parsers/GameNfoParser.cs | 23 ++++++++++ NfoMetadata/Providers/GameNfoProvider.cs | 51 +++++++++++++++++++++ NfoMetadata/Savers/GameNfoSaver.cs | 58 ++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 NfoMetadata/Parsers/GameNfoParser.cs create mode 100644 NfoMetadata/Providers/GameNfoProvider.cs create mode 100644 NfoMetadata/Savers/GameNfoSaver.cs diff --git a/NfoMetadata/Parsers/GameNfoParser.cs b/NfoMetadata/Parsers/GameNfoParser.cs new file mode 100644 index 0000000..e396d76 --- /dev/null +++ b/NfoMetadata/Parsers/GameNfoParser.cs @@ -0,0 +1,23 @@ +using MediaBrowser.Common.Configuration; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.IO; +using MediaBrowser.Model.Logging; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Text; +using System.Threading.Tasks; +using System.Threading; +using System.Xml; + +namespace NfoMetadata.Parsers +{ + public class GameNfoParser : BaseNfoParser + { + public GameNfoParser(ILogger logger, IConfigurationManager config, IProviderManager providerManager, IFileSystem fileSystem) : base(logger, config, providerManager, fileSystem) + { + } + } +} diff --git a/NfoMetadata/Providers/GameNfoProvider.cs b/NfoMetadata/Providers/GameNfoProvider.cs new file mode 100644 index 0000000..b5b6522 --- /dev/null +++ b/NfoMetadata/Providers/GameNfoProvider.cs @@ -0,0 +1,51 @@ +using MediaBrowser.Common.Configuration; +using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.IO; +using MediaBrowser.Model.Logging; +using NfoMetadata.Parsers; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Threading.Tasks; +using System.Threading; + +namespace NfoMetadata.Providers +{ + public class GameNfoProvider : BaseNfoProvider + { + private readonly ILogger _logger; + private readonly IConfigurationManager _config; + private readonly IProviderManager _providerManager; + + public GameNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config, IProviderManager providerManager) + : base(fileSystem) + { + _logger = logger; + _config = config; + _providerManager = providerManager; + } + + protected override Task Fetch(MetadataResult result, string path, CancellationToken cancellationToken) + { + return new GameNfoParser(_logger, _config, _providerManager, FileSystem).Fetch(result, path, cancellationToken); + } + + protected override FileSystemMetadata GetXmlFile(ItemInfo info, LibraryOptions libraryOptions, IDirectoryService directoryService) + { + var path = info.Path; + + if (string.IsNullOrEmpty(path) || BaseItem.MediaSourceManager.GetPathProtocol(path.AsSpan()) != MediaBrowser.Model.MediaInfo.MediaProtocol.File) + { + return null; + } + + path = Path.ChangeExtension(path, ".nfo"); + + return directoryService.GetFile(path); + } + } +} diff --git a/NfoMetadata/Savers/GameNfoSaver.cs b/NfoMetadata/Savers/GameNfoSaver.cs new file mode 100644 index 0000000..eb85bb6 --- /dev/null +++ b/NfoMetadata/Savers/GameNfoSaver.cs @@ -0,0 +1,58 @@ +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.IO; +using MediaBrowser.Model.Logging; +using NfoMetadata.Configuration; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Xml; + +namespace NfoMetadata.Savers +{ + public class GameNfoSaver : BaseNfoSaver + { + public GameNfoSaver(IFileSystem fileSystem, ILibraryMonitor libraryMonitor, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, IUserManager userManager, IUserDataManager userDataManager, ILogger logger) : base(fileSystem, libraryMonitor, configurationManager, libraryManager, userManager, userDataManager, logger) + { + } + + protected override string GetSavePath(BaseItem item, LibraryOptions libraryOptions) + { + return Path.ChangeExtension(item.Path, ".nfo"); + } + + protected override string GetRootElementName(BaseItem item) + { + return "game"; + } + + public override bool IsEnabledFor(BaseItem item, ItemUpdateType updateType) + { + if (!item.IsFileProtocol) + { + return false; + } + + return item is Game && updateType >= MinimumUpdateType; + } + + protected override void WriteCustomElements(BaseItem item, XmlWriter writer, int nodeIndex, int numNodes) + { + } + + protected override List GetTagsUsed(BaseItem item, XbmcMetadataOptions options) + { + var list = base.GetTagsUsed(item, options); + list.AddRange(new string[] + { + }); + return list; + } + } +} \ No newline at end of file