MetadataOptions.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using MediaBrowser.Model.Entities;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. namespace MediaBrowser.Model.Configuration
  6. {
  7. /// <summary>
  8. /// Class MetadataOptions.
  9. /// </summary>
  10. public class MetadataOptions
  11. {
  12. public string ItemType { get; set; }
  13. public ImageOption[] ImageOptions { get; set; }
  14. public string[] DisabledMetadataSavers { get; set; }
  15. public string[] LocalMetadataReaders { get; set; }
  16. public MetadataOptions()
  17. : this(3, 1280)
  18. {
  19. }
  20. public MetadataOptions(int backdropLimit, int minBackdropWidth)
  21. {
  22. var imageOptions = new List<ImageOption>
  23. {
  24. new ImageOption
  25. {
  26. Limit = backdropLimit,
  27. MinWidth = minBackdropWidth,
  28. Type = ImageType.Backdrop
  29. }
  30. };
  31. ImageOptions = imageOptions.ToArray();
  32. DisabledMetadataSavers = new string[] { };
  33. LocalMetadataReaders = new string[] { };
  34. }
  35. public int GetLimit(ImageType type)
  36. {
  37. var option = ImageOptions.FirstOrDefault(i => i.Type == type);
  38. return option == null ? 1 : option.Limit;
  39. }
  40. public int GetMinWidth(ImageType type)
  41. {
  42. var option = ImageOptions.FirstOrDefault(i => i.Type == type);
  43. return option == null ? 0 : option.MinWidth;
  44. }
  45. public bool IsEnabled(ImageType type)
  46. {
  47. return GetLimit(type) > 0;
  48. }
  49. public bool IsMetadataSaverEnabled(string name)
  50. {
  51. return !DisabledMetadataSavers.Contains(name, StringComparer.OrdinalIgnoreCase);
  52. }
  53. }
  54. public class ImageOption
  55. {
  56. /// <summary>
  57. /// Gets or sets the type.
  58. /// </summary>
  59. /// <value>The type.</value>
  60. public ImageType Type { get; set; }
  61. /// <summary>
  62. /// Gets or sets the limit.
  63. /// </summary>
  64. /// <value>The limit.</value>
  65. public int Limit { get; set; }
  66. /// <summary>
  67. /// Gets or sets the minimum width.
  68. /// </summary>
  69. /// <value>The minimum width.</value>
  70. public int MinWidth { get; set; }
  71. public ImageOption()
  72. {
  73. Limit = 1;
  74. }
  75. }
  76. }