BaseVideoNfoProvider.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using MediaBrowser.Common.Configuration;
  2. using MediaBrowser.Common.IO;
  3. using MediaBrowser.Controller.Entities;
  4. using MediaBrowser.Controller.Providers;
  5. using MediaBrowser.Model.Entities;
  6. using MediaBrowser.Model.Logging;
  7. using MediaBrowser.XbmcMetadata.Parsers;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Threading;
  11. namespace MediaBrowser.XbmcMetadata.Providers
  12. {
  13. public class BaseVideoNfoProvider<T> : BaseNfoProvider<T>
  14. where T : Video, new ()
  15. {
  16. private readonly ILogger _logger;
  17. private readonly IConfigurationManager _config;
  18. public BaseVideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config)
  19. : base(fileSystem)
  20. {
  21. _logger = logger;
  22. _config = config;
  23. }
  24. protected override void Fetch(LocalMetadataResult<T> result, string path, CancellationToken cancellationToken)
  25. {
  26. var chapters = new List<ChapterInfo>();
  27. new MovieNfoParser(_logger, _config).Fetch(result.Item, result.UserDataLIst, chapters, path, cancellationToken);
  28. result.Chapters = chapters;
  29. }
  30. protected override FileSystemInfo GetXmlFile(ItemInfo info, IDirectoryService directoryService)
  31. {
  32. var path = GetMovieSavePath(info, FileSystem);
  33. return directoryService.GetFile(path);
  34. }
  35. public static string GetMovieSavePath(ItemInfo item, IFileSystem fileSystem)
  36. {
  37. if (Directory.Exists(item.Path))
  38. {
  39. var path = item.Path;
  40. return Path.Combine(path, Path.GetFileName(path) + ".nfo");
  41. }
  42. return Path.ChangeExtension(item.Path, ".nfo");
  43. }
  44. }
  45. }