Plugin.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using MediaBrowser.Common.Plugins;
  2. using MediaBrowser.Controller.ScheduledTasks;
  3. using MediaBrowser.Model.Plugins;
  4. using MediaBrowser.Plugins.Trailers.Configuration;
  5. using MediaBrowser.Plugins.Trailers.ScheduledTasks;
  6. using System;
  7. using System.ComponentModel.Composition;
  8. using System.IO;
  9. namespace MediaBrowser.Plugins.Trailers
  10. {
  11. /// <summary>
  12. /// Class Plugin
  13. /// </summary>
  14. [Export(typeof(IPlugin))]
  15. public class Plugin : BasePlugin<PluginConfiguration>
  16. {
  17. /// <summary>
  18. /// Gets the name of the plugin
  19. /// </summary>
  20. /// <value>The name.</value>
  21. public override string Name
  22. {
  23. get { return "Trailers"; }
  24. }
  25. /// <summary>
  26. /// Gets the description.
  27. /// </summary>
  28. /// <value>The description.</value>
  29. public override string Description
  30. {
  31. get
  32. {
  33. return "Movie trailers for your collection.";
  34. }
  35. }
  36. /// <summary>
  37. /// Gets the instance.
  38. /// </summary>
  39. /// <value>The instance.</value>
  40. public static Plugin Instance { get; private set; }
  41. /// <summary>
  42. /// Initializes a new instance of the <see cref="Plugin" /> class.
  43. /// </summary>
  44. public Plugin()
  45. : base()
  46. {
  47. Instance = this;
  48. }
  49. /// <summary>
  50. /// The _download path
  51. /// </summary>
  52. private string _downloadPath;
  53. /// <summary>
  54. /// Gets the path to the trailer download directory
  55. /// </summary>
  56. /// <value>The download path.</value>
  57. public string DownloadPath
  58. {
  59. get
  60. {
  61. if (_downloadPath == null)
  62. {
  63. // Use
  64. _downloadPath = Configuration.DownloadPath;
  65. if (string.IsNullOrWhiteSpace(_downloadPath))
  66. {
  67. _downloadPath = Path.Combine(Controller.Kernel.Instance.ApplicationPaths.DataPath, Name);
  68. }
  69. if (!Directory.Exists(_downloadPath))
  70. {
  71. Directory.CreateDirectory(_downloadPath);
  72. }
  73. }
  74. return _downloadPath;
  75. }
  76. }
  77. /// <summary>
  78. /// Starts the plugin on the server
  79. /// </summary>
  80. /// <param name="isFirstRun">if set to <c>true</c> [is first run].</param>
  81. protected override void InitializeOnServer(bool isFirstRun)
  82. {
  83. base.InitializeOnServer(isFirstRun);
  84. if (isFirstRun)
  85. {
  86. Kernel.TaskManager.QueueScheduledTask<CurrentTrailerDownloadTask>();
  87. }
  88. }
  89. /// <summary>
  90. /// Completely overwrites the current configuration with a new copy
  91. /// Returns true or false indicating success or failure
  92. /// </summary>
  93. /// <param name="configuration">The configuration.</param>
  94. public override void UpdateConfiguration(BasePluginConfiguration configuration)
  95. {
  96. var config = (PluginConfiguration) configuration;
  97. var pathChanged = !string.Equals(Configuration.DownloadPath, config.DownloadPath, StringComparison.OrdinalIgnoreCase);
  98. base.UpdateConfiguration(configuration);
  99. if (pathChanged)
  100. {
  101. _downloadPath = null;
  102. Kernel.TaskManager.QueueScheduledTask<RefreshMediaLibraryTask>();
  103. }
  104. }
  105. }
  106. }