diff --git a/Kyoo.Common/Controllers/ICrawler.cs b/Kyoo.Common/Controllers/ICrawler.cs index 30514f7f..bbb6d4dc 100644 --- a/Kyoo.Common/Controllers/ICrawler.cs +++ b/Kyoo.Common/Controllers/ICrawler.cs @@ -1,7 +1,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Kyoo.InternalAPI +namespace Kyoo.Controllers { public interface ICrawler { diff --git a/Kyoo.Common/Controllers/ILibraryManager.cs b/Kyoo.Common/Controllers/ILibraryManager.cs index a85cceb3..3e40d923 100644 --- a/Kyoo.Common/Controllers/ILibraryManager.cs +++ b/Kyoo.Common/Controllers/ILibraryManager.cs @@ -2,7 +2,7 @@ using Kyoo.Models.Watch; using System.Collections.Generic; -namespace Kyoo.InternalAPI +namespace Kyoo.Controllers { public interface ILibraryManager { diff --git a/Kyoo.Common/Controllers/IMetadataProvider.cs b/Kyoo.Common/Controllers/IMetadataProvider.cs index 1a53a4b5..1b46283f 100644 --- a/Kyoo.Common/Controllers/IMetadataProvider.cs +++ b/Kyoo.Common/Controllers/IMetadataProvider.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Kyoo.InternalAPI +namespace Kyoo.Controllers { public interface IMetadataProvider { diff --git a/Kyoo.Common/Controllers/IPluginManager.cs b/Kyoo.Common/Controllers/IPluginManager.cs new file mode 100644 index 00000000..815c8395 --- /dev/null +++ b/Kyoo.Common/Controllers/IPluginManager.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace Kyoo.Controllers +{ + public interface IPluginManager + { + public T GetPlugin(string name); + public IEnumerable GetPlugins(); + public void ReloadPlugins(); + } +} \ No newline at end of file diff --git a/Kyoo.Common/Controllers/IThumbnailsManager.cs b/Kyoo.Common/Controllers/IThumbnailsManager.cs index 4d11d7f3..ac88cc40 100644 --- a/Kyoo.Common/Controllers/IThumbnailsManager.cs +++ b/Kyoo.Common/Controllers/IThumbnailsManager.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -namespace Kyoo.InternalAPI.ThumbnailsManager +namespace Kyoo.Controllers.ThumbnailsManager { public interface IThumbnailsManager { diff --git a/Kyoo.Common/Controllers/ITranscoder.cs b/Kyoo.Common/Controllers/ITranscoder.cs index bea35952..861cd492 100644 --- a/Kyoo.Common/Controllers/ITranscoder.cs +++ b/Kyoo.Common/Controllers/ITranscoder.cs @@ -2,7 +2,7 @@ using Kyoo.Models; using Kyoo.Models.Watch; using System.Threading.Tasks; -namespace Kyoo.InternalAPI +namespace Kyoo.Controllers { public interface ITranscoder { diff --git a/Kyoo.Common/Models/Collection.cs b/Kyoo.Common/Models/Collection.cs index 0ac1ad3b..2c520313 100644 --- a/Kyoo.Common/Models/Collection.cs +++ b/Kyoo.Common/Models/Collection.cs @@ -1,4 +1,4 @@ -using Kyoo.InternalAPI; +using Kyoo.Controllers; using Newtonsoft.Json; using System.Collections.Generic; diff --git a/Kyoo.Common/Models/Plugin.cs b/Kyoo.Common/Models/Plugin.cs new file mode 100644 index 00000000..c79de89c --- /dev/null +++ b/Kyoo.Common/Models/Plugin.cs @@ -0,0 +1,7 @@ +namespace Kyoo.Models +{ + public interface IPlugin + { + public string Name { get; } + } +} \ No newline at end of file diff --git a/Kyoo.Common/Models/Show.cs b/Kyoo.Common/Models/Show.cs index b2c267ee..7b975413 100644 --- a/Kyoo.Common/Models/Show.cs +++ b/Kyoo.Common/Models/Show.cs @@ -1,4 +1,4 @@ -using Kyoo.InternalAPI; +using Kyoo.Controllers; using Newtonsoft.Json; using System.Collections.Generic; diff --git a/Kyoo.Common/Models/WatchItem.cs b/Kyoo.Common/Models/WatchItem.cs index 4d092aa4..5ef7d5ab 100644 --- a/Kyoo.Common/Models/WatchItem.cs +++ b/Kyoo.Common/Models/WatchItem.cs @@ -1,4 +1,4 @@ -using Kyoo.InternalAPI; +using Kyoo.Controllers; using Newtonsoft.Json; using System; using System.Collections.Generic; diff --git a/Kyoo.Common/Plugins/MetadataAttribute.cs b/Kyoo.Common/Plugins/MetadataAttribute.cs deleted file mode 100644 index 35199691..00000000 --- a/Kyoo.Common/Plugins/MetadataAttribute.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace Kyoo.InternalAPI.MetadataProvider -{ - [AttributeUsage(AttributeTargets.Class)] - public class MetaProvider : Attribute - { - public MetaProvider() { } - } -} diff --git a/Kyoo.Common/Utility/ImageHelper.cs b/Kyoo.Common/Utility/ImageHelper.cs index c9b075e7..d75bd30d 100644 --- a/Kyoo.Common/Utility/ImageHelper.cs +++ b/Kyoo.Common/Utility/ImageHelper.cs @@ -1,6 +1,6 @@ using Kyoo.Models; -namespace Kyoo.InternalAPI.Utility +namespace Kyoo.Controllers.Utility { public static class ImageHelper { diff --git a/Kyoo.Common/Utility/Slugifier.cs b/Kyoo.Common/Utility/Slugifier.cs index 395c4d77..22cbc4f3 100644 --- a/Kyoo.Common/Utility/Slugifier.cs +++ b/Kyoo.Common/Utility/Slugifier.cs @@ -1,6 +1,6 @@ using System.Text.RegularExpressions; -namespace Kyoo.InternalAPI.Utility +namespace Kyoo.Controllers.Utility { public class Slugifier { diff --git a/Kyoo/Controllers/Crawler.cs b/Kyoo/Controllers/Crawler.cs index 89ff7daf..3a3662ef 100644 --- a/Kyoo/Controllers/Crawler.cs +++ b/Kyoo/Controllers/Crawler.cs @@ -1,5 +1,4 @@ -using Kyoo.InternalAPI.Utility; -using Kyoo.Models; +using Kyoo.Models; using Microsoft.Extensions.Configuration; using System.Collections.Generic; using System.Diagnostics; @@ -8,9 +7,10 @@ using System.Linq; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; +using Kyoo.Controllers.Utility; using Kyoo.Models.Watch; -namespace Kyoo.InternalAPI +namespace Kyoo.Controllers { public class Crawler : ICrawler { diff --git a/Kyoo/Controllers/LibraryManager.cs b/Kyoo/Controllers/LibraryManager.cs index 69d9c630..e55c5f5e 100644 --- a/Kyoo/Controllers/LibraryManager.cs +++ b/Kyoo/Controllers/LibraryManager.cs @@ -7,7 +7,7 @@ using System.Data.SQLite; using System.Diagnostics; using System.IO; -namespace Kyoo.InternalAPI +namespace Kyoo.Controllers { public class LibraryManager : ILibraryManager { diff --git a/Kyoo/Controllers/PluginManager.cs b/Kyoo/Controllers/PluginManager.cs new file mode 100644 index 00000000..78d2444d --- /dev/null +++ b/Kyoo/Controllers/PluginManager.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using Kyoo.Models; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Kyoo.Controllers +{ + public class PluginManager : IPluginManager + { + private readonly IServiceProvider provider; + private readonly IConfiguration config; + private List plugins; + + public PluginManager(IServiceProvider provider, IConfiguration config) + { + this.provider = provider; + this.config = config; + ReloadPlugins(); + } + + public T GetPlugin(string name) + { + return (T)(from plugin in plugins where plugin.Name == name && plugin is T + select plugin).FirstOrDefault(); + } + + public IEnumerable GetPlugins() + { + return from plugin in plugins where plugin is T + select (T)plugin; + } + + public void ReloadPlugins() + { + string pluginFolder = config.GetValue("plugins"); + + if (!Directory.Exists(pluginFolder)) + return; + string[] pluginsPaths = Directory.GetFiles(pluginFolder); + + plugins = pluginsPaths.Select(path => + { + Assembly ass = Assembly.LoadFile(path); + return (from type in ass.GetTypes() + where typeof(IPlugin).IsAssignableFrom(type) + select (IPlugin)ActivatorUtilities.CreateInstance(provider, type, null)).FirstOrDefault(); + }).Where(x => x != null).ToList(); + } + } +} \ No newline at end of file diff --git a/Kyoo/Controllers/ProviderManager.cs b/Kyoo/Controllers/ProviderManager.cs index cc2ea92e..4cf11925 100644 --- a/Kyoo/Controllers/ProviderManager.cs +++ b/Kyoo/Controllers/ProviderManager.cs @@ -1,6 +1,4 @@ -using Kyoo.InternalAPI.MetadataProvider; -using Kyoo.InternalAPI.ThumbnailsManager; -using Kyoo.Models; +using Kyoo.Models; using Microsoft.Extensions.Configuration; using System; using System.Collections.Generic; @@ -8,56 +6,21 @@ using System.IO; using System.Linq; using System.Reflection; using System.Threading.Tasks; +using Kyoo.Controllers.ThumbnailsManager; -namespace Kyoo.InternalAPI +namespace Kyoo.Controllers { public class ProviderManager : IMetadataProvider { - private readonly List providers = new List(); + private readonly IEnumerable providers; private readonly IThumbnailsManager thumbnailsManager; private readonly IConfiguration config; - public ProviderManager(IThumbnailsManager thumbnailsManager, IConfiguration configuration) + public ProviderManager(IThumbnailsManager thumbnailsManager, IPluginManager pluginManager, IConfiguration config) { this.thumbnailsManager = thumbnailsManager; - config = configuration; - LoadProviders(); - } - - void LoadProviders() - { - providers.Clear(); - string pluginFolder = config.GetValue("providerPlugins"); - - if (Directory.Exists(pluginFolder)) - { - string[] pluginsPaths = Directory.GetFiles(pluginFolder); - List plugins = new List(); - List types = new List(); - - for (int i = 0; i < pluginsPaths.Length; i++) - { - plugins.Add(Assembly.LoadFile(pluginsPaths[i])); - types.AddRange(plugins[i].GetTypes()); - } - - List providersPlugins = types.FindAll(x => - { - object[] atr = x.GetCustomAttributes(typeof(MetaProvider), false); - - if (atr == null || atr.Length == 0) - return false; - - List interfaces = new List(x.GetInterfaces()); - - if (interfaces.Contains(typeof(IMetadataProvider))) - return true; - - return false; - }); - - providers.AddRange(providersPlugins.ConvertAll(x => Activator.CreateInstance(x) as IMetadataProvider)); - } + this.config = config; + providers = pluginManager.GetPlugins(); } public Show Merge(IEnumerable shows) diff --git a/Kyoo/Controllers/ThumbnailsManager.cs b/Kyoo/Controllers/ThumbnailsManager.cs index 94b11fd3..3e0a468c 100644 --- a/Kyoo/Controllers/ThumbnailsManager.cs +++ b/Kyoo/Controllers/ThumbnailsManager.cs @@ -7,7 +7,7 @@ using System.IO; using System.Net; using System.Threading.Tasks; -namespace Kyoo.InternalAPI.ThumbnailsManager +namespace Kyoo.Controllers.ThumbnailsManager { public class ThumbnailsManager : IThumbnailsManager { diff --git a/Kyoo/Controllers/Transcoder/Transcoder.cs b/Kyoo/Controllers/Transcoder/Transcoder.cs index cae60986..47811e4f 100644 --- a/Kyoo/Controllers/Transcoder/Transcoder.cs +++ b/Kyoo/Controllers/Transcoder/Transcoder.cs @@ -1,14 +1,15 @@ using System; using Kyoo.Models; -using Kyoo.InternalAPI.TranscoderLink; using Microsoft.Extensions.Configuration; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; using System.Threading.Tasks; +using Kyoo.Controllers.TranscoderLink; + #pragma warning disable 4014 -namespace Kyoo.InternalAPI +namespace Kyoo.Controllers { public class Transcoder : ITranscoder { diff --git a/Kyoo/Controllers/Transcoder/TranscoderAPI.cs b/Kyoo/Controllers/Transcoder/TranscoderAPI.cs index 27c13f31..b95c0584 100644 --- a/Kyoo/Controllers/Transcoder/TranscoderAPI.cs +++ b/Kyoo/Controllers/Transcoder/TranscoderAPI.cs @@ -5,7 +5,7 @@ using Kyoo.Models; using Kyoo.Models.Watch; // ReSharper disable InconsistentNaming -namespace Kyoo.InternalAPI.TranscoderLink +namespace Kyoo.Controllers.TranscoderLink { public static class TranscoderAPI { diff --git a/Kyoo/HtmlAPI/AdminController.cs b/Kyoo/HtmlAPI/AdminController.cs index 976f9140..fdd006c6 100644 --- a/Kyoo/HtmlAPI/AdminController.cs +++ b/Kyoo/HtmlAPI/AdminController.cs @@ -1,4 +1,4 @@ -using Kyoo.InternalAPI; +using Kyoo.Controllers; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; diff --git a/Kyoo/HtmlAPI/CollectionController.cs b/Kyoo/HtmlAPI/CollectionController.cs index 9e1a84e1..8d1a8543 100644 --- a/Kyoo/HtmlAPI/CollectionController.cs +++ b/Kyoo/HtmlAPI/CollectionController.cs @@ -1,4 +1,4 @@ -using Kyoo.InternalAPI; +using Kyoo.Controllers; using Kyoo.Models; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; diff --git a/Kyoo/HtmlAPI/EpisodesController.cs b/Kyoo/HtmlAPI/EpisodesController.cs index ac2ac30e..b3876234 100644 --- a/Kyoo/HtmlAPI/EpisodesController.cs +++ b/Kyoo/HtmlAPI/EpisodesController.cs @@ -1,4 +1,4 @@ -using Kyoo.InternalAPI; +using Kyoo.Controllers; using Kyoo.Models; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; diff --git a/Kyoo/HtmlAPI/LibrariesController.cs b/Kyoo/HtmlAPI/LibrariesController.cs index a2c05df3..c142f00e 100644 --- a/Kyoo/HtmlAPI/LibrariesController.cs +++ b/Kyoo/HtmlAPI/LibrariesController.cs @@ -1,4 +1,4 @@ -using Kyoo.InternalAPI; +using Kyoo.Controllers; using Kyoo.Models; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; diff --git a/Kyoo/HtmlAPI/PeopleController.cs b/Kyoo/HtmlAPI/PeopleController.cs index 9c08379f..2e93b8b5 100644 --- a/Kyoo/HtmlAPI/PeopleController.cs +++ b/Kyoo/HtmlAPI/PeopleController.cs @@ -1,4 +1,4 @@ -using Kyoo.InternalAPI; +using Kyoo.Controllers; using Kyoo.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; diff --git a/Kyoo/HtmlAPI/SearchController.cs b/Kyoo/HtmlAPI/SearchController.cs index 1dd08d17..e070ab41 100644 --- a/Kyoo/HtmlAPI/SearchController.cs +++ b/Kyoo/HtmlAPI/SearchController.cs @@ -1,4 +1,4 @@ -using Kyoo.InternalAPI; +using Kyoo.Controllers; using Kyoo.Models; using Microsoft.AspNetCore.Mvc; diff --git a/Kyoo/HtmlAPI/ShowsController.cs b/Kyoo/HtmlAPI/ShowsController.cs index 97f7ecae..436f6c45 100644 --- a/Kyoo/HtmlAPI/ShowsController.cs +++ b/Kyoo/HtmlAPI/ShowsController.cs @@ -1,4 +1,4 @@ -using Kyoo.InternalAPI; +using Kyoo.Controllers; using Kyoo.Models; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; diff --git a/Kyoo/HtmlAPI/SubtitleController.cs b/Kyoo/HtmlAPI/SubtitleController.cs index c3487a42..747e6cc0 100644 --- a/Kyoo/HtmlAPI/SubtitleController.cs +++ b/Kyoo/HtmlAPI/SubtitleController.cs @@ -1,8 +1,6 @@ -using Kyoo.InternalAPI; -using Kyoo.Models; +using Kyoo.Models; using Microsoft.AspNetCore.Mvc; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Threading.Tasks; diff --git a/Kyoo/HtmlAPI/ThumbnailController.cs b/Kyoo/HtmlAPI/ThumbnailController.cs index 74100b7a..6c0bd2ba 100644 --- a/Kyoo/HtmlAPI/ThumbnailController.cs +++ b/Kyoo/HtmlAPI/ThumbnailController.cs @@ -1,11 +1,10 @@ -using Kyoo.InternalAPI; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using System.IO; namespace Kyoo.Controllers { - public class ThumbnailController : Controller + public class ThumbnailController : ControllerBase { private readonly ILibraryManager libraryManager; private readonly string peoplePath; diff --git a/Kyoo/HtmlAPI/VideoController.cs b/Kyoo/HtmlAPI/VideoController.cs index c5ebc43c..b58da90f 100644 --- a/Kyoo/HtmlAPI/VideoController.cs +++ b/Kyoo/HtmlAPI/VideoController.cs @@ -1,4 +1,4 @@ -using Kyoo.InternalAPI; +using Kyoo.Controllers; using Kyoo.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; diff --git a/Kyoo/HtmlAPI/WatchController.cs b/Kyoo/HtmlAPI/WatchController.cs index 0de4d726..a1eadf95 100644 --- a/Kyoo/HtmlAPI/WatchController.cs +++ b/Kyoo/HtmlAPI/WatchController.cs @@ -1,4 +1,4 @@ -using Kyoo.InternalAPI; +using Kyoo.Controllers; using Kyoo.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; diff --git a/Kyoo/Startup.cs b/Kyoo/Startup.cs index 71ea8672..f2b74b67 100644 --- a/Kyoo/Startup.cs +++ b/Kyoo/Startup.cs @@ -1,5 +1,5 @@ -using Kyoo.InternalAPI; -using Kyoo.InternalAPI.ThumbnailsManager; +using Kyoo.Controllers; +using Kyoo.Controllers.ThumbnailsManager; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.SpaServices.AngularCli; @@ -30,12 +30,9 @@ namespace Kyoo }); services.AddControllers().AddNewtonsoftJson(); - - //Services needed in the private and in the public API + services.AddSingleton(); services.AddSingleton(); - - //Services used to get informations about files and register them services.AddSingleton(); services.AddSingleton(); services.AddSingleton();