123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using MediaBrowser.Common.Plugins;
- using MediaBrowser.Controller.ScheduledTasks;
- using MediaBrowser.Model.Plugins;
- using MediaBrowser.Plugins.Trailers.Configuration;
- using MediaBrowser.Plugins.Trailers.ScheduledTasks;
- using System;
- using System.ComponentModel.Composition;
- using System.IO;
- namespace MediaBrowser.Plugins.Trailers
- {
- /// <summary>
- /// Class Plugin
- /// </summary>
- [Export(typeof(IPlugin))]
- public class Plugin : BasePlugin<PluginConfiguration>
- {
- /// <summary>
- /// Gets the name of the plugin
- /// </summary>
- /// <value>The name.</value>
- public override string Name
- {
- get { return "Trailers"; }
- }
- /// <summary>
- /// Gets the description.
- /// </summary>
- /// <value>The description.</value>
- public override string Description
- {
- get
- {
- return "Movie trailers for your collection.";
- }
- }
- /// <summary>
- /// Gets the instance.
- /// </summary>
- /// <value>The instance.</value>
- public static Plugin Instance { get; private set; }
- /// <summary>
- /// Initializes a new instance of the <see cref="Plugin" /> class.
- /// </summary>
- public Plugin()
- : base()
- {
- Instance = this;
- }
- /// <summary>
- /// The _download path
- /// </summary>
- private string _downloadPath;
- /// <summary>
- /// Gets the path to the trailer download directory
- /// </summary>
- /// <value>The download path.</value>
- public string DownloadPath
- {
- get
- {
- if (_downloadPath == null)
- {
- // Use
- _downloadPath = Configuration.DownloadPath;
- if (string.IsNullOrWhiteSpace(_downloadPath))
- {
- _downloadPath = Path.Combine(Controller.Kernel.Instance.ApplicationPaths.DataPath, Name);
- }
- if (!Directory.Exists(_downloadPath))
- {
- Directory.CreateDirectory(_downloadPath);
- }
- }
- return _downloadPath;
- }
- }
- /// <summary>
- /// Starts the plugin on the server
- /// </summary>
- /// <param name="isFirstRun">if set to <c>true</c> [is first run].</param>
- protected override void InitializeOnServer(bool isFirstRun)
- {
- base.InitializeOnServer(isFirstRun);
- if (isFirstRun)
- {
- Kernel.TaskManager.QueueScheduledTask<CurrentTrailerDownloadTask>();
- }
- }
- /// <summary>
- /// Completely overwrites the current configuration with a new copy
- /// Returns true or false indicating success or failure
- /// </summary>
- /// <param name="configuration">The configuration.</param>
- public override void UpdateConfiguration(BasePluginConfiguration configuration)
- {
- var config = (PluginConfiguration) configuration;
- var pathChanged = !string.Equals(Configuration.DownloadPath, config.DownloadPath, StringComparison.OrdinalIgnoreCase);
- base.UpdateConfiguration(configuration);
- if (pathChanged)
- {
- _downloadPath = null;
- Kernel.TaskManager.QueueScheduledTask<RefreshMediaLibraryTask>();
- }
- }
- }
- }
|