diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index fc1679cb..ab5ed716 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -1,5 +1,5 @@ name: Analysis -on: [push, pull_request] +on: [push, pull_request, workflow_dispatch] jobs: analysis: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ecbb0b21..83b3e507 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,5 @@ name: Build -on: [push, pull_request] +on: [push, pull_request, workflow_dispatch] jobs: build: @@ -10,7 +10,7 @@ jobs: fail-fast: false matrix: include: - - os: ubuntu-latest #ubuntu-16.04 # We are using an old version of ubuntu to have an old libc version (forward compatibility exist but not backward) + - os: ubuntu-latest runtime: linux-x64 artifact: linux - os: windows-latest @@ -35,13 +35,18 @@ jobs: elif [[ "${{runner.os}}" == "macOS" ]]; then brew install ffmpeg else - # sudo add-apt-repository -y "deb http://azure.archive.ubuntu.com/ubuntu groovy main multiverse restricted universe" - sudo apt-get update + sudo apt-get update sudo apt-get install -y libavutil-dev libavcodec-dev libavformat-dev fi - name: Enabling windows compilations tools if: matrix.artifact == 'windows' uses: ilammy/msvc-dev-cmd@v1 + - name: Select the project to build + shell: bash + run: | + echo "PROJECT=$([ "${{runner.os}}" == "Windows" ] \ + && echo " -p:IncludeConsole=true Kyoo.Host.WindowsTrait" \ + || echo Kyoo.Host.Console)" >> $GITHUB_ENV - name: Build the app env: INCLUDE: ${{env.INCLUDE}};C:\Program Files\FFmpeg\include @@ -49,7 +54,7 @@ jobs: LIBPATH: ${{env.LIBPATH}};C:\Program Files\FFmpeg\lib CFLAGS: -I/usr/local/include LDFLAGS: -L/usr/local/lib - run: dotnet publish -r ${{matrix.runtime}} -c Release -o dist Kyoo + run: dotnet publish -r ${{matrix.runtime}} -c Release -o dist ${{env.PROJECT}} - name: Compression output shell: bash run: | @@ -69,7 +74,34 @@ jobs: path: | *.zip *.tar.gz - + + windows_release: + name: Create windows release + runs-on: windows-latest + needs: build + if: github.ref == 'refs/heads/master' + steps: + - uses: actions/checkout@v1 + - name: Download windows build + uses: actions/download-artifact@v2 + with: + name: kyoo_windows + path: artifact + - name: Unzip windows files + run: mkdir dist_win && 7z x artifact/kyoo_windows.zip -odist_win + - name: Install Inno Setup + shell: cmd + run: | + curl -L https://jrsoftware.org/download.php/is.exe > innosetup.exe + innosetup.exe /VERYSILENT /SUPPRESSMSGBOXES /Log=log.txt || (cat log.txt && exit 1) + - name: Create windows installer + shell: bash + run: iscc -Dkyoo=$(realpath dist_win) -O./ -Fkyoo-windows deployment/kyoo-windows.iss + - uses: actions/upload-artifact@v2 + with: + name: kyoo_windows_installer + path: ./kyoo-windows.exe + release: name: Create debian, rpm & arch releases runs-on: ubuntu-latest @@ -80,7 +112,8 @@ jobs: version: v0.0.1 #${{ github.ref }} steps: - uses: actions/checkout@v1 - - uses: actions/download-artifact@v2 + - name: Download linux build + uses: actions/download-artifact@v2 with: name: kyoo_linux path: artifact @@ -89,19 +122,18 @@ jobs: - name: Create the package structure run: | sudo mkdir -p pkg/usr/lib/ - sudo mkdir -p pkg/DEBIAN sudo cp -r --no-preserve ownership dist pkg/usr/lib/kyoo sudo install -Dm 644 deployment/kyoo.service -t pkg/usr/lib/systemd/system/ sudo install -Dm 644 deployment/kyoo.sysusers pkg/usr/lib/sysusers.d/kyoo.conf sudo install -Dm 644 deployment/kyoo.tmpfiles pkg/usr/lib/tmpfiles.d/kyoo.conf - sudo install -Dm 755 deployment/postinst -t pkg/DEBIAN/ - - uses: jiro4989/build-deb-action@v2 + - name: Build debian package + uses: jiro4989/build-deb-action@v2 with: package: kyoo package_root: pkg maintainer: Zoe Roux version: ${{env.version}} - depends: "postgresql, libavutil-dev, libavcodec-dev, libavformat-dev" + depends: "libavutil-dev, libavcodec-dev, libavformat-dev" arch: amd64 desc: ${{env.description}} - name: Build rpm package diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index e61395ff..c68715f0 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,6 +1,5 @@ name: Docker - -on: [push, pull_request] +on: [push, pull_request, workflow_dispatch] jobs: build: diff --git a/Kyoo.Abstractions/Controllers/IApplication.cs b/Kyoo.Abstractions/Controllers/IApplication.cs new file mode 100644 index 00000000..8e72280e --- /dev/null +++ b/Kyoo.Abstractions/Controllers/IApplication.cs @@ -0,0 +1,31 @@ +namespace Kyoo.Abstractions.Controllers +{ + /// + /// An interface that allow one to interact with the host and shutdown or restart the app. + /// + public interface IApplication + { + /// + /// Shutdown the process and stop gracefully. + /// + void Shutdown(); + + /// + /// Restart Kyoo from scratch, reload plugins, configurations and restart the web server. + /// + void Restart(); + + /// + /// Get the data directory + /// + /// Retrieve the data directory where runtime data should be stored + string GetDataDirectory(); + + /// + /// Retrieve the path of the json configuration file + /// (relative to the data directory, see ). + /// + /// The configuration file name. + string GetConfigFile(); + } +} \ No newline at end of file diff --git a/Kyoo.Abstractions/Controllers/IPlugin.cs b/Kyoo.Abstractions/Controllers/IPlugin.cs index 0ff6c932..6fc2cc3c 100644 --- a/Kyoo.Abstractions/Controllers/IPlugin.cs +++ b/Kyoo.Abstractions/Controllers/IPlugin.cs @@ -93,14 +93,5 @@ namespace Kyoo.Abstractions.Controllers { // Skipped } - - /// - /// An optional callback function called when the startups ends and this plugin has been flagged has disabled. - /// It allow a plugin to log an error or warning message to inform why it has been disabled. - /// - void Disabled() - { - // Skipped - } } } \ No newline at end of file diff --git a/Kyoo.Abstractions/Controllers/IRepository.cs b/Kyoo.Abstractions/Controllers/IRepository.cs index 3a7dee05..45c866ba 100644 --- a/Kyoo.Abstractions/Controllers/IRepository.cs +++ b/Kyoo.Abstractions/Controllers/IRepository.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using JetBrains.Annotations; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Exceptions; +using Kyoo.Utils; namespace Kyoo.Abstractions.Controllers { diff --git a/Kyoo.Abstractions/Kyoo.Abstractions.csproj b/Kyoo.Abstractions/Kyoo.Abstractions.csproj index 9831afb3..2c7ac85d 100644 --- a/Kyoo.Abstractions/Kyoo.Abstractions.csproj +++ b/Kyoo.Abstractions/Kyoo.Abstractions.csproj @@ -2,7 +2,6 @@ net5.0 - true Kyoo.Abstractions Zoe Roux Base package to create plugins for Kyoo. diff --git a/Kyoo.Abstractions/Models/ConfigurationReference.cs b/Kyoo.Abstractions/Models/ConfigurationReference.cs index 8b1064dd..676367e3 100644 --- a/Kyoo.Abstractions/Models/ConfigurationReference.cs +++ b/Kyoo.Abstractions/Models/ConfigurationReference.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Reflection; using JetBrains.Annotations; +using Kyoo.Utils; namespace Kyoo.Abstractions.Models { diff --git a/Kyoo.Abstractions/Models/Page.cs b/Kyoo.Abstractions/Models/Page.cs index eb8898d2..5dc37abb 100644 --- a/Kyoo.Abstractions/Models/Page.cs +++ b/Kyoo.Abstractions/Models/Page.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Kyoo.Utils; namespace Kyoo.Abstractions.Models { diff --git a/Kyoo.Abstractions/Models/Resources/Genre.cs b/Kyoo.Abstractions/Models/Resources/Genre.cs index b346381f..0cf2d9b3 100644 --- a/Kyoo.Abstractions/Models/Resources/Genre.cs +++ b/Kyoo.Abstractions/Models/Resources/Genre.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Kyoo.Abstractions.Models.Attributes; +using Kyoo.Utils; namespace Kyoo.Abstractions.Models { diff --git a/Kyoo.Abstractions/Models/Resources/Provider.cs b/Kyoo.Abstractions/Models/Resources/Provider.cs index 61726100..d1a34223 100644 --- a/Kyoo.Abstractions/Models/Resources/Provider.cs +++ b/Kyoo.Abstractions/Models/Resources/Provider.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models.Attributes; +using Kyoo.Utils; namespace Kyoo.Abstractions.Models { diff --git a/Kyoo.Abstractions/Models/Resources/Studio.cs b/Kyoo.Abstractions/Models/Resources/Studio.cs index f0e14567..fbc4934b 100644 --- a/Kyoo.Abstractions/Models/Resources/Studio.cs +++ b/Kyoo.Abstractions/Models/Resources/Studio.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Kyoo.Abstractions.Models.Attributes; +using Kyoo.Utils; namespace Kyoo.Abstractions.Models { diff --git a/Kyoo.Abstractions/Module.cs b/Kyoo.Abstractions/Module.cs index f4594387..dcc5bc18 100644 --- a/Kyoo.Abstractions/Module.cs +++ b/Kyoo.Abstractions/Module.cs @@ -1,6 +1,7 @@ using Autofac; using Autofac.Builder; using Kyoo.Abstractions.Controllers; +using Kyoo.Utils; using Microsoft.Extensions.Configuration; namespace Kyoo.Abstractions diff --git a/Kyoo.Abstractions/Utility/EnumerableExtensions.cs b/Kyoo.Abstractions/Utility/EnumerableExtensions.cs index 93f1b52e..9bd81157 100644 --- a/Kyoo.Abstractions/Utility/EnumerableExtensions.cs +++ b/Kyoo.Abstractions/Utility/EnumerableExtensions.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using JetBrains.Annotations; -namespace Kyoo +namespace Kyoo.Utils { /// /// A set of extensions class for enumerable. diff --git a/Kyoo.Abstractions/Utility/Merger.cs b/Kyoo.Abstractions/Utility/Merger.cs index c59f47a1..fe00a924 100644 --- a/Kyoo.Abstractions/Utility/Merger.cs +++ b/Kyoo.Abstractions/Utility/Merger.cs @@ -8,7 +8,7 @@ using JetBrains.Annotations; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Attributes; -namespace Kyoo +namespace Kyoo.Utils { /// /// A class containing helper methods to merge objects. diff --git a/Kyoo.Abstractions/Utility/MethodOfUtils.cs b/Kyoo.Abstractions/Utility/MethodOfUtils.cs index 5d051f69..30a1ce4c 100644 --- a/Kyoo.Abstractions/Utility/MethodOfUtils.cs +++ b/Kyoo.Abstractions/Utility/MethodOfUtils.cs @@ -1,7 +1,7 @@ using System; using System.Reflection; -namespace Kyoo +namespace Kyoo.Utils { /// /// Static class containing MethodOf calls. diff --git a/Kyoo.Abstractions/Utility/TaskUtils.cs b/Kyoo.Abstractions/Utility/TaskUtils.cs index a0d04b03..91413f2c 100644 --- a/Kyoo.Abstractions/Utility/TaskUtils.cs +++ b/Kyoo.Abstractions/Utility/TaskUtils.cs @@ -2,7 +2,7 @@ using System; using System.Threading.Tasks; using JetBrains.Annotations; -namespace Kyoo +namespace Kyoo.Utils { /// /// A class containing helper method for tasks. diff --git a/Kyoo.Abstractions/Utility/Utility.cs b/Kyoo.Abstractions/Utility/Utility.cs index ab4fc92d..d1bb91b1 100644 --- a/Kyoo.Abstractions/Utility/Utility.cs +++ b/Kyoo.Abstractions/Utility/Utility.cs @@ -9,7 +9,7 @@ using System.Text; using System.Text.RegularExpressions; using JetBrains.Annotations; -namespace Kyoo +namespace Kyoo.Utils { /// /// A set of utility functions that can be used everywhere. diff --git a/Kyoo.Authentication/AuthenticationModule.cs b/Kyoo.Authentication/AuthenticationModule.cs index 61f3d929..805b01cd 100644 --- a/Kyoo.Authentication/AuthenticationModule.cs +++ b/Kyoo.Authentication/AuthenticationModule.cs @@ -110,6 +110,14 @@ namespace Kyoo.Authentication CertificateOption certificateOptions = new(); _configuration.GetSection(CertificateOption.Path).Bind(certificateOptions); + clients.AddRange(IdentityContext.GetClients()); + foreach (Client client in clients) + { + client.RedirectUris = client.RedirectUris + .Select(x => x.StartsWith("/") ? publicUrl + x : x) + .ToArray(); + } + services.AddIdentityServer(options => { options.IssuerUri = publicUrl; @@ -120,7 +128,7 @@ namespace Kyoo.Authentication .AddInMemoryIdentityResources(IdentityContext.GetIdentityResources()) .AddInMemoryApiScopes(IdentityContext.GetScopes()) .AddInMemoryApiResources(IdentityContext.GetApis()) - .AddInMemoryClients(IdentityContext.GetClients().Concat(clients)) + .AddInMemoryClients(clients) .AddProfileService() .AddSigninKeys(certificateOptions); diff --git a/Kyoo.Authentication/Kyoo.Authentication.csproj b/Kyoo.Authentication/Kyoo.Authentication.csproj index 080795b2..313f57ce 100644 --- a/Kyoo.Authentication/Kyoo.Authentication.csproj +++ b/Kyoo.Authentication/Kyoo.Authentication.csproj @@ -22,7 +22,7 @@ - + login/%(RecursiveDir)%(Filename)%(Extension) Always diff --git a/Kyoo.Authentication/Models/DTO/RegisterRequest.cs b/Kyoo.Authentication/Models/DTO/RegisterRequest.cs index e10967fd..1e505bb7 100644 --- a/Kyoo.Authentication/Models/DTO/RegisterRequest.cs +++ b/Kyoo.Authentication/Models/DTO/RegisterRequest.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using Kyoo.Abstractions.Models; +using Kyoo.Utils; namespace Kyoo.Authentication.Models.DTO { diff --git a/Kyoo/.gitignore b/Kyoo.Core/.gitignore similarity index 100% rename from Kyoo/.gitignore rename to Kyoo.Core/.gitignore diff --git a/Kyoo.Core/Application.cs b/Kyoo.Core/Application.cs new file mode 100644 index 00000000..150dfb6a --- /dev/null +++ b/Kyoo.Core/Application.cs @@ -0,0 +1,276 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using Autofac; +using Autofac.Extensions.DependencyInjection; +using JetBrains.Annotations; +using Kyoo.Abstractions.Controllers; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.Win32; +using Serilog; +using Serilog.Templates; +using Serilog.Templates.Themes; +using ILogger = Serilog.ILogger; + +namespace Kyoo.Core +{ + public class Application : IApplication + { + /// + /// The path to the data directory. + /// + private string _dataDir; + + /// + /// Should the application restart after a shutdown? + /// + private bool _shouldRestart; + + /// + /// The cancellation token source used to allow the app to be shutdown or restarted. + /// + private CancellationTokenSource _tokenSource; + + /// + /// The environment in witch Kyoo will run (ether "Production" or "Development"). + /// + private readonly string _environment; + + /// + /// The logger used for startup and error messages. + /// + private ILogger _logger; + + + /// + /// Create a new that will use the specified environment. + /// + /// The environment to run in. + public Application(string environment) + { + _environment = environment; + } + + + /// + /// Start the application with the given console args. + /// This is generally called from the Main entrypoint of Kyoo. + /// + /// The console arguments to use for kyoo. + /// A task representing the whole process + public Task Start(string[] args) + { + return Start(args, _ => { }); + } + + /// + /// Start the application with the given console args. + /// This is generally called from the Main entrypoint of Kyoo. + /// + /// The console arguments to use for kyoo. + /// A custom action to configure the container before the start + /// A task representing the whole process + public async Task Start(string[] args, Action configure) + { + _dataDir = _SetupDataDir(args); + + LoggerConfiguration config = new(); + _ConfigureLogging(config, null, null); + Log.Logger = config.CreateBootstrapLogger(); + _logger = Log.Logger.ForContext(); + + AppDomain.CurrentDomain.ProcessExit += (_, _) => Log.CloseAndFlush(); + AppDomain.CurrentDomain.UnhandledException += (_, ex) + => Log.Fatal(ex.ExceptionObject as Exception, "Unhandled exception"); + + do + { + IHost host = _CreateWebHostBuilder(args) + .ConfigureContainer(configure) + .Build(); + + _tokenSource = new CancellationTokenSource(); + await _StartWithHost(host, _tokenSource.Token); + } + while (_shouldRestart); + } + + /// + public void Shutdown() + { + _shouldRestart = false; + _tokenSource.Cancel(); + } + + /// + public void Restart() + { + _shouldRestart = true; + _tokenSource.Cancel(); + } + + /// + public string GetDataDirectory() + { + return _dataDir; + } + + + /// + public string GetConfigFile() + { + return "./settings.json"; + } + + /// + /// Parse the data directory from environment variables and command line arguments, create it if necessary. + /// Set the current directory to said data folder and place a default configuration file if it does not already + /// exists. + /// + /// The command line arguments + /// The current data directory. + private string _SetupDataDir(string[] args) + { + Dictionary registry = new(); + + if (OperatingSystem.IsWindows()) + { + object dataDir = Registry.GetValue(@"HKEY_LOCAL_MACHINE\Software\SDG\Kyoo\Settings", "DataDir", null) + ?? Registry.GetValue(@"HKEY_CURRENT_USER\Software\SDG\Kyoo\Settings", "DataDir", null); + if (dataDir is string data) + registry.Add("DataDir", data); + } + + IConfiguration parsed = new ConfigurationBuilder() + .AddInMemoryCollection(registry) + .AddEnvironmentVariables() + .AddEnvironmentVariables("KYOO_") + .AddCommandLine(args) + .Build(); + + string path = parsed.GetValue("datadir") + ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Kyoo"); + + if (!Directory.Exists(path)) + Directory.CreateDirectory(path); + Environment.CurrentDirectory = path; + + if (!File.Exists(GetConfigFile())) + File.Copy(Path.Join(AppDomain.CurrentDomain.BaseDirectory, GetConfigFile()), + GetConfigFile()); + + return path; + } + + /// + /// Start the given host and log failing exceptions. + /// + /// The host to start. + /// A token to allow one to stop the host. + private async Task _StartWithHost(IHost host, CancellationToken cancellationToken) + { + try + { + _logger.Information("Running as {Name}", Environment.UserName); + _logger.Information("Data directory: {DataDirectory}", GetDataDirectory()); + await host.RunAsync(cancellationToken); + } + catch (Exception ex) + { + _logger.Fatal(ex, "Unhandled exception"); + } + } + + /// + /// Create a a web host + /// + /// Command line parameters that can be handled by kestrel + /// A new web host instance + private IHostBuilder _CreateWebHostBuilder(string[] args) + { + IConfiguration configuration = _SetupConfig(new ConfigurationBuilder(), args).Build(); + + return new HostBuilder() + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) + .UseContentRoot(AppDomain.CurrentDomain.BaseDirectory) + .UseEnvironment(_environment) + .ConfigureAppConfiguration(x => _SetupConfig(x, args)) + .UseSerilog((host, services, builder) => _ConfigureLogging(builder, host.Configuration, services)) + .ConfigureServices(x => x.AddRouting()) + .ConfigureContainer(x => + { + x.RegisterInstance(this).As().SingleInstance().ExternallyOwned(); + }) + .ConfigureWebHost(x => x + .UseKestrel(options => { options.AddServerHeader = false; }) + .UseIIS() + .UseIISIntegration() + .UseUrls(configuration.GetValue("basics:url")) + .UseStartup(host => PluginsStartup.FromWebHost(host, new LoggerFactory().AddSerilog())) + ); + } + + /// + /// Register settings.json, environment variables and command lines arguments as configuration. + /// + /// The configuration builder to use + /// The command line arguments + /// The modified configuration builder + private IConfigurationBuilder _SetupConfig(IConfigurationBuilder builder, string[] args) + { + return builder.SetBasePath(GetDataDirectory()) + .AddJsonFile(Path.Join(AppDomain.CurrentDomain.BaseDirectory, GetConfigFile()), false, true) + .AddJsonFile(GetConfigFile(), false, true) + .AddEnvironmentVariables() + .AddEnvironmentVariables("KYOO_") + .AddCommandLine(args); + } + + /// + /// Configure the logging. + /// + /// The logger builder to configure. + /// The configuration to read settings from. + /// The services to read configuration from. + private void _ConfigureLogging(LoggerConfiguration builder, + [CanBeNull] IConfiguration configuration, + [CanBeNull] IServiceProvider services) + { + if (configuration != null) + { + try + { + builder.ReadFrom.Configuration(configuration, "logging"); + } + catch (Exception ex) + { + _logger.Fatal(ex, "Could not read serilog configuration"); + } + } + + if (services != null) + builder.ReadFrom.Services(services); + + const string template = + "[{@t:HH:mm:ss} {@l:u3} {Substring(SourceContext, LastIndexOf(SourceContext, '.') + 1), 15} " + + "({@i:0000000000})] {@m}{#if not EndsWith(@m, '\n')}\n{#end}{@x}"; + + builder + .WriteTo.Console(new ExpressionTemplate(template, theme: TemplateTheme.Code)) + .WriteTo.File( + path: Path.Combine(GetDataDirectory(), "logs", "log-.log"), + formatter: new ExpressionTemplate(template), + rollingInterval: RollingInterval.Day, + rollOnFileSizeLimit: true + ) + .Enrich.WithThreadId() + .Enrich.FromLogContext(); + } + } +} \ No newline at end of file diff --git a/Kyoo/Controllers/ConfigurationManager.cs b/Kyoo.Core/Controllers/ConfigurationManager.cs similarity index 91% rename from Kyoo/Controllers/ConfigurationManager.cs rename to Kyoo.Core/Controllers/ConfigurationManager.cs index c6476551..7f5432f1 100644 --- a/Kyoo/Controllers/ConfigurationManager.cs +++ b/Kyoo.Core/Controllers/ConfigurationManager.cs @@ -8,11 +8,11 @@ using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Exceptions; -using Kyoo.Api; +using Kyoo.Core.Api; using Microsoft.Extensions.Configuration; using Newtonsoft.Json.Linq; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { public class ConfigurationManager : IConfigurationManager { @@ -21,6 +21,11 @@ namespace Kyoo.Controllers /// private readonly IConfiguration _configuration; + /// + /// The application running Kyoo, it is used to retrieve the configuration file. + /// + private readonly IApplication _application; + /// /// The strongly typed list of options /// @@ -31,9 +36,11 @@ namespace Kyoo.Controllers /// /// The configuration to use. /// The strongly typed option list. - public ConfigurationManager(IConfiguration configuration, IEnumerable references) + /// The application running Kyoo, it is used to retrieve the configuration file. + public ConfigurationManager(IConfiguration configuration, IEnumerable references, IApplication application) { _configuration = configuration; + _application = application; _references = references.ToDictionary(x => x.Path, x => x.Type, StringComparer.OrdinalIgnoreCase); } @@ -131,7 +138,7 @@ namespace Kyoo.Controllers IDictionary configDic = config; configDic[path] = value; JObject obj = JObject.FromObject(config); - await using StreamWriter writer = new(Program.JsonConfigPath); + await using StreamWriter writer = new(_application.GetConfigFile()); await writer.WriteAsync(obj.ToString()); } diff --git a/Kyoo/Controllers/FileSystems/FileSystemComposite.cs b/Kyoo.Core/Controllers/FileSystems/FileSystemComposite.cs similarity index 99% rename from Kyoo/Controllers/FileSystems/FileSystemComposite.cs rename to Kyoo.Core/Controllers/FileSystems/FileSystemComposite.cs index bab7167d..4a715602 100644 --- a/Kyoo/Controllers/FileSystems/FileSystemComposite.cs +++ b/Kyoo.Core/Controllers/FileSystems/FileSystemComposite.cs @@ -9,11 +9,11 @@ using JetBrains.Annotations; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models.Attributes; using Kyoo.Abstractions.Models; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A composite that merge every available diff --git a/Kyoo/Controllers/FileSystems/HttpFileSystem.cs b/Kyoo.Core/Controllers/FileSystems/HttpFileSystem.cs similarity index 99% rename from Kyoo/Controllers/FileSystems/HttpFileSystem.cs rename to Kyoo.Core/Controllers/FileSystems/HttpFileSystem.cs index 8bd3d62f..0b5618fa 100644 --- a/Kyoo/Controllers/FileSystems/HttpFileSystem.cs +++ b/Kyoo.Core/Controllers/FileSystems/HttpFileSystem.cs @@ -9,7 +9,7 @@ using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Attributes; using Microsoft.AspNetCore.Mvc; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A for http/https links. diff --git a/Kyoo/Controllers/FileSystems/LocalFileSystem.cs b/Kyoo.Core/Controllers/FileSystems/LocalFileSystem.cs similarity index 98% rename from Kyoo/Controllers/FileSystems/LocalFileSystem.cs rename to Kyoo.Core/Controllers/FileSystems/LocalFileSystem.cs index 3c4da8a0..3c75717f 100644 --- a/Kyoo/Controllers/FileSystems/LocalFileSystem.cs +++ b/Kyoo.Core/Controllers/FileSystems/LocalFileSystem.cs @@ -5,12 +5,12 @@ using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Attributes; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.Options; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A for the local filesystem (using System.IO). diff --git a/Kyoo/Controllers/LibraryManager.cs b/Kyoo.Core/Controllers/LibraryManager.cs similarity index 99% rename from Kyoo/Controllers/LibraryManager.cs rename to Kyoo.Core/Controllers/LibraryManager.cs index 2b396ed5..e7759f0a 100644 --- a/Kyoo/Controllers/LibraryManager.cs +++ b/Kyoo.Core/Controllers/LibraryManager.cs @@ -6,8 +6,9 @@ using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Exceptions; +using Kyoo.Utils; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { public class LibraryManager : ILibraryManager { diff --git a/Kyoo/Controllers/PassthroughPermissionValidator.cs b/Kyoo.Core/Controllers/PassthroughPermissionValidator.cs similarity index 96% rename from Kyoo/Controllers/PassthroughPermissionValidator.cs rename to Kyoo.Core/Controllers/PassthroughPermissionValidator.cs index 5b623008..914835bf 100644 --- a/Kyoo/Controllers/PassthroughPermissionValidator.cs +++ b/Kyoo.Core/Controllers/PassthroughPermissionValidator.cs @@ -2,7 +2,7 @@ using Kyoo.Abstractions.Models.Permissions; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Logging; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A permission validator that always validate permissions. This effectively disable the permission system. diff --git a/Kyoo/Controllers/PluginManager.cs b/Kyoo.Core/Controllers/PluginManager.cs similarity index 90% rename from Kyoo/Controllers/PluginManager.cs rename to Kyoo.Core/Controllers/PluginManager.cs index 3b60e83f..7fc2c6cf 100644 --- a/Kyoo/Controllers/PluginManager.cs +++ b/Kyoo.Core/Controllers/PluginManager.cs @@ -5,12 +5,12 @@ using System.Linq; using System.Reflection; using System.Runtime.Loader; using Kyoo.Abstractions.Controllers; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// An implementation of . @@ -21,7 +21,7 @@ namespace Kyoo.Controllers /// /// The service provider. It allow plugin's activation. /// - private IServiceProvider _provider; + private readonly IServiceProvider _provider; /// /// The configuration to get the plugin's directory. /// @@ -51,14 +51,6 @@ namespace Kyoo.Controllers _logger = logger; } - public void SetProvider(IServiceProvider provider) - { - // TODO temporary bullshit to inject services before the configure asp net. - // TODO should rework this when the host will be reworked, as well as the asp net configure. - _provider = provider; - } - - /// public T GetPlugin(string name) { @@ -111,16 +103,13 @@ namespace Kyoo.Controllers _logger.LogTrace("Loading new plugins..."); string[] pluginsPaths = Directory.GetFiles(pluginFolder, "*.dll", SearchOption.AllDirectories); - IPlugin[] newPlugins = plugins + _plugins.AddRange(plugins .Concat(pluginsPaths.SelectMany(LoadPlugin)) + .Where(x => x.Enabled) .GroupBy(x => x.Name) .Select(x => x.First()) - .ToArray(); - _plugins.AddRange(newPlugins.Where(x => x.Enabled)); - - foreach (IPlugin plugin in newPlugins.Where(x => !x.Enabled)) - plugin.Disabled(); - + ); + if (!_plugins.Any()) _logger.LogInformation("No plugin enabled"); else diff --git a/Kyoo/Controllers/ProviderComposite.cs b/Kyoo.Core/Controllers/ProviderComposite.cs similarity index 98% rename from Kyoo/Controllers/ProviderComposite.cs rename to Kyoo.Core/Controllers/ProviderComposite.cs index dd9ecb41..1032b022 100644 --- a/Kyoo/Controllers/ProviderComposite.cs +++ b/Kyoo.Core/Controllers/ProviderComposite.cs @@ -4,9 +4,10 @@ using System.Linq; using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; +using Kyoo.Utils; using Microsoft.Extensions.Logging; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A metadata provider composite that merge results from all available providers. diff --git a/Kyoo/Controllers/RegexIdentifier.cs b/Kyoo.Core/Controllers/RegexIdentifier.cs similarity index 97% rename from Kyoo/Controllers/RegexIdentifier.cs rename to Kyoo.Core/Controllers/RegexIdentifier.cs index 41a6e0d8..1032d4bb 100644 --- a/Kyoo/Controllers/RegexIdentifier.cs +++ b/Kyoo.Core/Controllers/RegexIdentifier.cs @@ -7,11 +7,12 @@ using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Exceptions; -using Kyoo.Models.Options; -using Kyoo.Models.Watch; +using Kyoo.Core.Models.Options; +using Kyoo.Core.Models.Watch; +using Kyoo.Utils; using Microsoft.Extensions.Options; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// An identifier that use a regex to extract basics metadata. diff --git a/Kyoo/Controllers/Repositories/CollectionRepository.cs b/Kyoo.Core/Controllers/Repositories/CollectionRepository.cs similarity index 98% rename from Kyoo/Controllers/Repositories/CollectionRepository.cs rename to Kyoo.Core/Controllers/Repositories/CollectionRepository.cs index cdb0740a..f6d1e220 100644 --- a/Kyoo/Controllers/Repositories/CollectionRepository.cs +++ b/Kyoo.Core/Controllers/Repositories/CollectionRepository.cs @@ -8,7 +8,7 @@ using Kyoo.Abstractions.Models; using Kyoo.Database; using Microsoft.EntityFrameworkCore; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A local repository to handle collections diff --git a/Kyoo/Controllers/Repositories/EpisodeRepository.cs b/Kyoo.Core/Controllers/Repositories/EpisodeRepository.cs similarity index 99% rename from Kyoo/Controllers/Repositories/EpisodeRepository.cs rename to Kyoo.Core/Controllers/Repositories/EpisodeRepository.cs index d31e97cc..f19acdb2 100644 --- a/Kyoo/Controllers/Repositories/EpisodeRepository.cs +++ b/Kyoo.Core/Controllers/Repositories/EpisodeRepository.cs @@ -7,9 +7,10 @@ using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Database; +using Kyoo.Utils; using Microsoft.EntityFrameworkCore; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A local repository to handle episodes. diff --git a/Kyoo/Controllers/Repositories/GenreRepository.cs b/Kyoo.Core/Controllers/Repositories/GenreRepository.cs similarity index 98% rename from Kyoo/Controllers/Repositories/GenreRepository.cs rename to Kyoo.Core/Controllers/Repositories/GenreRepository.cs index b791f627..f72b13e7 100644 --- a/Kyoo/Controllers/Repositories/GenreRepository.cs +++ b/Kyoo.Core/Controllers/Repositories/GenreRepository.cs @@ -8,7 +8,7 @@ using Kyoo.Abstractions.Models; using Kyoo.Database; using Microsoft.EntityFrameworkCore; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A local repository for genres. diff --git a/Kyoo/Controllers/Repositories/LibraryItemRepository.cs b/Kyoo.Core/Controllers/Repositories/LibraryItemRepository.cs similarity index 99% rename from Kyoo/Controllers/Repositories/LibraryItemRepository.cs rename to Kyoo.Core/Controllers/Repositories/LibraryItemRepository.cs index 172c7ab6..ba075c09 100644 --- a/Kyoo/Controllers/Repositories/LibraryItemRepository.cs +++ b/Kyoo.Core/Controllers/Repositories/LibraryItemRepository.cs @@ -9,7 +9,7 @@ using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Database; using Microsoft.EntityFrameworkCore; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A local repository to handle library items. diff --git a/Kyoo/Controllers/Repositories/LibraryRepository.cs b/Kyoo.Core/Controllers/Repositories/LibraryRepository.cs similarity index 98% rename from Kyoo/Controllers/Repositories/LibraryRepository.cs rename to Kyoo.Core/Controllers/Repositories/LibraryRepository.cs index e532d4e0..1e835114 100644 --- a/Kyoo/Controllers/Repositories/LibraryRepository.cs +++ b/Kyoo.Core/Controllers/Repositories/LibraryRepository.cs @@ -6,9 +6,10 @@ using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Database; +using Kyoo.Utils; using Microsoft.EntityFrameworkCore; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A local repository to handle libraries. diff --git a/Kyoo/Controllers/Repositories/LocalRepository.cs b/Kyoo.Core/Controllers/Repositories/LocalRepository.cs similarity index 99% rename from Kyoo/Controllers/Repositories/LocalRepository.cs rename to Kyoo.Core/Controllers/Repositories/LocalRepository.cs index 14d4cb40..55c6e259 100644 --- a/Kyoo/Controllers/Repositories/LocalRepository.cs +++ b/Kyoo.Core/Controllers/Repositories/LocalRepository.cs @@ -8,10 +8,11 @@ using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Attributes; using Kyoo.Abstractions.Models.Exceptions; -using Kyoo.Api; +using Kyoo.Utils; +using Kyoo.Core.Api; using Microsoft.EntityFrameworkCore; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A base class to create repositories using Entity Framework. diff --git a/Kyoo/Controllers/Repositories/PeopleRepository.cs b/Kyoo.Core/Controllers/Repositories/PeopleRepository.cs similarity index 99% rename from Kyoo/Controllers/Repositories/PeopleRepository.cs rename to Kyoo.Core/Controllers/Repositories/PeopleRepository.cs index 10ca820b..9b8eb38f 100644 --- a/Kyoo/Controllers/Repositories/PeopleRepository.cs +++ b/Kyoo.Core/Controllers/Repositories/PeopleRepository.cs @@ -7,9 +7,10 @@ using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Database; +using Kyoo.Utils; using Microsoft.EntityFrameworkCore; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A local repository to handle people. diff --git a/Kyoo/Controllers/Repositories/ProviderRepository.cs b/Kyoo.Core/Controllers/Repositories/ProviderRepository.cs similarity index 98% rename from Kyoo/Controllers/Repositories/ProviderRepository.cs rename to Kyoo.Core/Controllers/Repositories/ProviderRepository.cs index a1f00608..321b11d3 100644 --- a/Kyoo/Controllers/Repositories/ProviderRepository.cs +++ b/Kyoo.Core/Controllers/Repositories/ProviderRepository.cs @@ -8,7 +8,7 @@ using Kyoo.Abstractions.Models; using Kyoo.Database; using Microsoft.EntityFrameworkCore; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A local repository to handle providers. diff --git a/Kyoo/Controllers/Repositories/SeasonRepository.cs b/Kyoo.Core/Controllers/Repositories/SeasonRepository.cs similarity index 99% rename from Kyoo/Controllers/Repositories/SeasonRepository.cs rename to Kyoo.Core/Controllers/Repositories/SeasonRepository.cs index f63f37e2..1a22fe15 100644 --- a/Kyoo/Controllers/Repositories/SeasonRepository.cs +++ b/Kyoo.Core/Controllers/Repositories/SeasonRepository.cs @@ -9,7 +9,7 @@ using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Database; using Microsoft.EntityFrameworkCore; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A local repository to handle seasons. diff --git a/Kyoo/Controllers/Repositories/ShowRepository.cs b/Kyoo.Core/Controllers/Repositories/ShowRepository.cs similarity index 99% rename from Kyoo/Controllers/Repositories/ShowRepository.cs rename to Kyoo.Core/Controllers/Repositories/ShowRepository.cs index 1605eab6..dca498c7 100644 --- a/Kyoo/Controllers/Repositories/ShowRepository.cs +++ b/Kyoo.Core/Controllers/Repositories/ShowRepository.cs @@ -5,10 +5,11 @@ using System.Linq.Expressions; using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; +using Kyoo.Utils; using Kyoo.Database; using Microsoft.EntityFrameworkCore; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A local repository to handle shows diff --git a/Kyoo/Controllers/Repositories/StudioRepository.cs b/Kyoo.Core/Controllers/Repositories/StudioRepository.cs similarity index 98% rename from Kyoo/Controllers/Repositories/StudioRepository.cs rename to Kyoo.Core/Controllers/Repositories/StudioRepository.cs index 42b98b44..185e4420 100644 --- a/Kyoo/Controllers/Repositories/StudioRepository.cs +++ b/Kyoo.Core/Controllers/Repositories/StudioRepository.cs @@ -8,7 +8,7 @@ using Kyoo.Abstractions.Models; using Kyoo.Database; using Microsoft.EntityFrameworkCore; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A local repository to handle studios diff --git a/Kyoo/Controllers/Repositories/TrackRepository.cs b/Kyoo.Core/Controllers/Repositories/TrackRepository.cs similarity index 98% rename from Kyoo/Controllers/Repositories/TrackRepository.cs rename to Kyoo.Core/Controllers/Repositories/TrackRepository.cs index b7c29c47..c6b7889c 100644 --- a/Kyoo/Controllers/Repositories/TrackRepository.cs +++ b/Kyoo.Core/Controllers/Repositories/TrackRepository.cs @@ -7,7 +7,7 @@ using Kyoo.Abstractions.Models; using Kyoo.Database; using Microsoft.EntityFrameworkCore; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A local repository to handle tracks. diff --git a/Kyoo/Controllers/Repositories/UserRepository.cs b/Kyoo.Core/Controllers/Repositories/UserRepository.cs similarity index 98% rename from Kyoo/Controllers/Repositories/UserRepository.cs rename to Kyoo.Core/Controllers/Repositories/UserRepository.cs index 896b8480..1b267ab6 100644 --- a/Kyoo/Controllers/Repositories/UserRepository.cs +++ b/Kyoo.Core/Controllers/Repositories/UserRepository.cs @@ -8,7 +8,7 @@ using Kyoo.Abstractions.Models; using Kyoo.Database; using Microsoft.EntityFrameworkCore; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A repository for users. diff --git a/Kyoo/Controllers/TaskManager.cs b/Kyoo.Core/Controllers/TaskManager.cs similarity index 99% rename from Kyoo/Controllers/TaskManager.cs rename to Kyoo.Core/Controllers/TaskManager.cs index df89f290..af1d24e6 100644 --- a/Kyoo/Controllers/TaskManager.cs +++ b/Kyoo.Core/Controllers/TaskManager.cs @@ -10,12 +10,12 @@ using JetBrains.Annotations; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models.Attributes; using Kyoo.Abstractions.Models.Exceptions; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// A service to handle long running tasks and a background runner. diff --git a/Kyoo/Controllers/ThumbnailsManager.cs b/Kyoo.Core/Controllers/ThumbnailsManager.cs similarity index 99% rename from Kyoo/Controllers/ThumbnailsManager.cs rename to Kyoo.Core/Controllers/ThumbnailsManager.cs index 274b655f..d82db69f 100644 --- a/Kyoo/Controllers/ThumbnailsManager.cs +++ b/Kyoo.Core/Controllers/ThumbnailsManager.cs @@ -7,7 +7,7 @@ using Kyoo.Abstractions.Models; using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.Logging; -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { /// /// Download images and retrieve the path of those images for a resource. diff --git a/Kyoo/Controllers/Transcoder.cs b/Kyoo.Core/Controllers/Transcoder.cs similarity index 71% rename from Kyoo/Controllers/Transcoder.cs rename to Kyoo.Core/Controllers/Transcoder.cs index a8adc9d1..1f2f8d08 100644 --- a/Kyoo/Controllers/Transcoder.cs +++ b/Kyoo.Core/Controllers/Transcoder.cs @@ -4,14 +4,14 @@ using System.Runtime.InteropServices; using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.Extensions.Options; -using Stream = Kyoo.Models.Watch.Stream; +using Stream = Kyoo.Core.Models.Watch.Stream; // We use threads so tasks are not always awaited. #pragma warning disable 4014 -namespace Kyoo.Controllers +namespace Kyoo.Core.Controllers { public class BadTranscoderException : Exception {} @@ -22,29 +22,40 @@ namespace Kyoo.Controllers private const string TranscoderPath = "transcoder"; [DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)] - public static extern int init(); + private static extern int init(); - [DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)] - public static extern int transmux(string path, string outpath, out float playableDuration); - - [DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)] - public static extern int transcode(string path, string outpath, out float playableDuration); + public static int Init() => init(); - [DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)] + [DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl, + CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)] + private static extern int transmux(string path, string outpath, out float playableDuration); + + public static int Transmux(string path, string outPath, out float playableDuration) + { + path = path.Replace('\\', '/'); + outPath = outPath.Replace('\\', '/'); + return transmux(path, outPath, out playableDuration); + } + + [DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl, + CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)] private static extern IntPtr extract_infos(string path, string outpath, - out int length, - out int trackCount, + out uint length, + out uint trackCount, bool reextracct); - + [DllImport(TranscoderPath, CallingConvention = CallingConvention.Cdecl)] - private static extern void free(IntPtr ptr); - - + private static extern void free_streams(IntPtr streams, uint count); + + public static Track[] ExtractInfos(string path, string outPath, bool reextract) { - int size = Marshal.SizeOf(); - IntPtr ptr = extract_infos(path, outPath, out int arrayLength, out int trackCount, reextract); + path = path.Replace('\\', '/'); + outPath = outPath.Replace('\\', '/'); + + int size = Marshal.SizeOf(); + IntPtr ptr = extract_infos(path, outPath, out uint arrayLength, out uint trackCount, reextract); IntPtr streamsPtr = ptr; Track[] tracks; @@ -55,7 +66,7 @@ namespace Kyoo.Controllers int j = 0; for (int i = 0; i < arrayLength; i++) { - Stream stream = Marshal.PtrToStructure(streamsPtr); + Models.Watch.Stream stream = Marshal.PtrToStructure(streamsPtr); if (stream!.Type != StreamType.Unknown) { tracks[j] = stream.ToTrack(); @@ -68,7 +79,7 @@ namespace Kyoo.Controllers tracks = Array.Empty(); if (ptr != IntPtr.Zero) - free(ptr); // free_streams is not necessary since the Marshal free the unmanaged pointers. + free_streams(ptr, trackCount); return tracks; } } @@ -83,7 +94,7 @@ namespace Kyoo.Controllers _options = options; _library = library; - if (TranscoderAPI.init() != Marshal.SizeOf()) + if (TranscoderAPI.Init() != Marshal.SizeOf()) throw new BadTranscoderException(); } @@ -122,8 +133,7 @@ namespace Kyoo.Controllers Task.Factory.StartNew(() => { - string cleanManifest = manifest.Replace('\\', '/'); - transmuxFailed = TranscoderAPI.transmux(episode.Path, cleanManifest, out playableDuration) != 0; + transmuxFailed = TranscoderAPI.Transmux(episode.Path, manifest, out playableDuration) != 0; }, TaskCreationOptions.LongRunning); while (playableDuration < 10 || !File.Exists(manifest) && !transmuxFailed) await Task.Delay(10); diff --git a/Kyoo/CoreModule.cs b/Kyoo.Core/CoreModule.cs similarity index 94% rename from Kyoo/CoreModule.cs rename to Kyoo.Core/CoreModule.cs index b6445b3d..ef0961cc 100644 --- a/Kyoo/CoreModule.cs +++ b/Kyoo.Core/CoreModule.cs @@ -7,19 +7,20 @@ using Autofac.Extras.AttributeMetadata; using Kyoo.Abstractions; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models.Permissions; -using Kyoo.Api; -using Kyoo.Controllers; +using Kyoo.Core.Api; +using Kyoo.Core.Controllers; +using Kyoo.Core.Models.Options; +using Kyoo.Core.Tasks; using Kyoo.Database; -using Kyoo.Models.Options; -using Kyoo.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Serilog; using IMetadataProvider = Kyoo.Abstractions.Controllers.IMetadataProvider; -namespace Kyoo +namespace Kyoo.Core { /// /// The core module containing default implementations @@ -70,10 +71,11 @@ namespace Kyoo builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); + builder.RegisterType().As().As().SingleInstance(); + builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().InstancePerLifetimeScope(); - builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().SingleInstance(); @@ -135,8 +137,6 @@ namespace Kyoo }); services.AddHttpClient(); - - services.AddHostedService(x => x.GetService() as TaskManager); } /// @@ -152,6 +152,7 @@ namespace Kyoo app.UseHsts(); } }, SA.Before), + SA.New(app => app.UseSerilogRequestLogging(), SA.Before), SA.New(app => app.UseResponseCompression(), SA.Routing + 1), SA.New(app => app.UseRouting(), SA.Routing), SA.New(app => app.UseEndpoints(x => x.MapControllers()), SA.Endpoint) diff --git a/Kyoo/Helper.cs b/Kyoo.Core/Helper.cs similarity index 97% rename from Kyoo/Helper.cs rename to Kyoo.Core/Helper.cs index ad8a6dfb..570e22d6 100644 --- a/Kyoo/Helper.cs +++ b/Kyoo.Core/Helper.cs @@ -2,7 +2,7 @@ using System.Net.Http; using System.Threading.Tasks; using Newtonsoft.Json; -namespace Kyoo +namespace Kyoo.Core { public static class Helper { diff --git a/Kyoo/Kyoo.csproj b/Kyoo.Core/Kyoo.Core.csproj similarity index 60% rename from Kyoo/Kyoo.csproj rename to Kyoo.Core/Kyoo.Core.csproj index e76cf005..0e37a4f9 100644 --- a/Kyoo/Kyoo.csproj +++ b/Kyoo.Core/Kyoo.Core.csproj @@ -1,4 +1,4 @@ - + net5.0 @@ -7,10 +7,9 @@ SDG Zoe Roux https://github.com/AnonymusRaccoon/Kyoo - Kyoo.Program default - + true true @@ -18,12 +17,16 @@ - transcoder.dll - libtranscoder.dylib - libtranscoder.so + transcoder.dll + libtranscoder.dylib + libtranscoder.so + + + + @@ -35,7 +38,7 @@ - + @@ -44,9 +47,14 @@ - - - + + + + + + + + @@ -55,4 +63,9 @@ false + + + + + diff --git a/Kyoo/Models/FileExtensions.cs b/Kyoo.Core/Models/FileExtensions.cs similarity index 98% rename from Kyoo/Models/FileExtensions.cs rename to Kyoo.Core/Models/FileExtensions.cs index 5b29fe08..26e520d1 100644 --- a/Kyoo/Models/FileExtensions.cs +++ b/Kyoo.Core/Models/FileExtensions.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.IO; -namespace Kyoo.Models.Watch +namespace Kyoo.Core.Models.Watch { /// /// A static class allowing one to identify files extensions. diff --git a/Kyoo/Models/Options/BasicOptions.cs b/Kyoo.Core/Models/Options/BasicOptions.cs similarity index 98% rename from Kyoo/Models/Options/BasicOptions.cs rename to Kyoo.Core/Models/Options/BasicOptions.cs index ca018fd4..5bb108f8 100644 --- a/Kyoo/Models/Options/BasicOptions.cs +++ b/Kyoo.Core/Models/Options/BasicOptions.cs @@ -1,7 +1,7 @@ using Kyoo.Abstractions.Models; using System; -namespace Kyoo.Models.Options +namespace Kyoo.Core.Models.Options { /// /// The typed list of basic/global options for Kyoo diff --git a/Kyoo/Models/Options/MediaOptions.cs b/Kyoo.Core/Models/Options/MediaOptions.cs similarity index 92% rename from Kyoo/Models/Options/MediaOptions.cs rename to Kyoo.Core/Models/Options/MediaOptions.cs index 4b02e4db..3133e8d2 100644 --- a/Kyoo/Models/Options/MediaOptions.cs +++ b/Kyoo.Core/Models/Options/MediaOptions.cs @@ -1,4 +1,4 @@ -namespace Kyoo.Models.Options +namespace Kyoo.Core.Models.Options { /// /// Options for media registering. diff --git a/Kyoo/Models/Options/TaskOptions.cs b/Kyoo.Core/Models/Options/TaskOptions.cs similarity index 94% rename from Kyoo/Models/Options/TaskOptions.cs rename to Kyoo.Core/Models/Options/TaskOptions.cs index 922a9ff4..89b77687 100644 --- a/Kyoo/Models/Options/TaskOptions.cs +++ b/Kyoo.Core/Models/Options/TaskOptions.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using JetBrains.Annotations; -namespace Kyoo.Models.Options +namespace Kyoo.Core.Models.Options { /// /// Options related to tasks diff --git a/Kyoo/Models/Stream.cs b/Kyoo.Core/Models/Stream.cs similarity index 97% rename from Kyoo/Models/Stream.cs rename to Kyoo.Core/Models/Stream.cs index 6d2b4a3c..2980adae 100644 --- a/Kyoo/Models/Stream.cs +++ b/Kyoo.Core/Models/Stream.cs @@ -2,7 +2,7 @@ using System.Runtime.InteropServices; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Attributes; -namespace Kyoo.Models.Watch +namespace Kyoo.Core.Models.Watch { /// /// The unmanaged stream that the transcoder will return. diff --git a/Kyoo/PluginsStartup.cs b/Kyoo.Core/PluginsStartup.cs similarity index 92% rename from Kyoo/PluginsStartup.cs rename to Kyoo.Core/PluginsStartup.cs index 4bcd362f..470c9a4f 100644 --- a/Kyoo/PluginsStartup.cs +++ b/Kyoo.Core/PluginsStartup.cs @@ -5,13 +5,14 @@ using Autofac; using Kyoo.Abstractions; using Kyoo.Abstractions.Controllers; using Kyoo.Authentication; -using Kyoo.Controllers; -using Kyoo.Models.Options; +using Kyoo.Core.Controllers; +using Kyoo.Core.Models.Options; +using Kyoo.Core.Tasks; using Kyoo.Postgresql; using Kyoo.SqLite; -using Kyoo.Tasks; using Kyoo.TheMovieDb; using Kyoo.TheTvdb; +using Kyoo.Utils; using Kyoo.WebApp; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -21,7 +22,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -namespace Kyoo +namespace Kyoo.Core { /// /// The Startup class is used to configure the AspNet's webhost. @@ -131,19 +132,13 @@ namespace Kyoo /// This is meant to be used from . /// /// The context of the web host. - /// - /// The method used to configure the logger factory used by the plugin manager and plugins during startup. + /// + /// The logger factory used to log while the application is setting itself up. /// /// A new . public static PluginsStartup FromWebHost(WebHostBuilderContext host, - Action loggingConfiguration) + ILoggerFactory logger) { - HostBuilderContext genericHost = new(new Dictionary()) - { - Configuration = host.Configuration, - HostingEnvironment = host.HostingEnvironment - }; - ILoggerFactory logger = LoggerFactory.Create(builder => loggingConfiguration(genericHost, builder)); HostServiceProvider hostProvider = new(host.HostingEnvironment, host.Configuration, logger); PluginManager plugins = new( hostProvider, diff --git a/Kyoo/Tasks/Crawler.cs b/Kyoo.Core/Tasks/Crawler.cs similarity index 98% rename from Kyoo/Tasks/Crawler.cs rename to Kyoo.Core/Tasks/Crawler.cs index cc2762c4..3633fbb3 100644 --- a/Kyoo/Tasks/Crawler.cs +++ b/Kyoo.Core/Tasks/Crawler.cs @@ -7,10 +7,10 @@ using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Attributes; -using Kyoo.Models.Watch; +using Kyoo.Core.Models.Watch; using Microsoft.Extensions.Logging; -namespace Kyoo.Tasks +namespace Kyoo.Core.Tasks { /// /// A task to add new video files. @@ -146,7 +146,7 @@ namespace Kyoo.Tasks string[] subtitles = files .Where(FileExtensions.IsSubtitle) - .Where(x => !x.Contains("/Extra/")) + .Where(x => !x.Contains("Extra")) .Where(x => tracks.All(y => y.Path != x)) .ToArray(); percent = 0; diff --git a/Kyoo/Tasks/ExtractMetadata.cs b/Kyoo.Core/Tasks/ExtractMetadata.cs similarity index 100% rename from Kyoo/Tasks/ExtractMetadata.cs rename to Kyoo.Core/Tasks/ExtractMetadata.cs diff --git a/Kyoo/Tasks/Housekeeping.cs b/Kyoo.Core/Tasks/Housekeeping.cs similarity index 99% rename from Kyoo/Tasks/Housekeeping.cs rename to Kyoo.Core/Tasks/Housekeeping.cs index 1724b0e7..38d1c9f4 100644 --- a/Kyoo/Tasks/Housekeeping.cs +++ b/Kyoo.Core/Tasks/Housekeeping.cs @@ -6,7 +6,7 @@ using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Attributes; using Microsoft.Extensions.Logging; -namespace Kyoo.Tasks +namespace Kyoo.Core.Tasks { /// /// A task to remove orphaned episode and series. diff --git a/Kyoo/Tasks/MetadataProviderLoader.cs b/Kyoo.Core/Tasks/MetadataProviderLoader.cs similarity index 98% rename from Kyoo/Tasks/MetadataProviderLoader.cs rename to Kyoo.Core/Tasks/MetadataProviderLoader.cs index 3c9163c4..cfe398ae 100644 --- a/Kyoo/Tasks/MetadataProviderLoader.cs +++ b/Kyoo.Core/Tasks/MetadataProviderLoader.cs @@ -6,7 +6,7 @@ using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models.Attributes; using Kyoo.Abstractions.Models.Exceptions; -namespace Kyoo.Tasks +namespace Kyoo.Core.Tasks { /// /// A task that download metadata providers images. diff --git a/Kyoo/Tasks/PluginInitializer.cs b/Kyoo.Core/Tasks/PluginInitializer.cs similarity index 98% rename from Kyoo/Tasks/PluginInitializer.cs rename to Kyoo.Core/Tasks/PluginInitializer.cs index 7f9e5171..a5b36b6d 100644 --- a/Kyoo/Tasks/PluginInitializer.cs +++ b/Kyoo.Core/Tasks/PluginInitializer.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models.Attributes; -namespace Kyoo.Tasks +namespace Kyoo.Core.Tasks { /// /// A task run on Kyoo's startup to initialize plugins diff --git a/Kyoo/Tasks/ReScan.cs b/Kyoo.Core/Tasks/ReScan.cs similarity index 100% rename from Kyoo/Tasks/ReScan.cs rename to Kyoo.Core/Tasks/ReScan.cs diff --git a/Kyoo/Tasks/RegisterEpisode.cs b/Kyoo.Core/Tasks/RegisterEpisode.cs similarity index 99% rename from Kyoo/Tasks/RegisterEpisode.cs rename to Kyoo.Core/Tasks/RegisterEpisode.cs index 851d658d..d713a9d1 100644 --- a/Kyoo/Tasks/RegisterEpisode.cs +++ b/Kyoo.Core/Tasks/RegisterEpisode.cs @@ -7,7 +7,7 @@ using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Attributes; using Kyoo.Abstractions.Models.Exceptions; -namespace Kyoo.Tasks +namespace Kyoo.Core.Tasks { /// /// A task to register a new episode diff --git a/Kyoo/Tasks/RegisterSubtitle.cs b/Kyoo.Core/Tasks/RegisterSubtitle.cs similarity index 98% rename from Kyoo/Tasks/RegisterSubtitle.cs rename to Kyoo.Core/Tasks/RegisterSubtitle.cs index 2ace1f0b..3b931ab7 100644 --- a/Kyoo/Tasks/RegisterSubtitle.cs +++ b/Kyoo.Core/Tasks/RegisterSubtitle.cs @@ -6,7 +6,7 @@ using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Attributes; using Kyoo.Abstractions.Models.Exceptions; -namespace Kyoo.Tasks +namespace Kyoo.Core.Tasks { /// /// A task to register a new episode diff --git a/Kyoo/Views/CollectionApi.cs b/Kyoo.Core/Views/CollectionApi.cs similarity index 98% rename from Kyoo/Views/CollectionApi.cs rename to Kyoo.Core/Views/CollectionApi.cs index b6cada95..56af8b0a 100644 --- a/Kyoo/Views/CollectionApi.cs +++ b/Kyoo.Core/Views/CollectionApi.cs @@ -7,10 +7,10 @@ using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Abstractions.Models.Permissions; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.Extensions.Options; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [Route("api/collection")] [Route("api/collections")] diff --git a/Kyoo/Views/ConfigurationApi.cs b/Kyoo.Core/Views/ConfigurationApi.cs similarity index 99% rename from Kyoo/Views/ConfigurationApi.cs rename to Kyoo.Core/Views/ConfigurationApi.cs index 1abef5bf..0b20df11 100644 --- a/Kyoo/Views/ConfigurationApi.cs +++ b/Kyoo.Core/Views/ConfigurationApi.cs @@ -5,7 +5,7 @@ using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Abstractions.Models.Permissions; using Microsoft.AspNetCore.Mvc; -namespace Kyoo.Api +namespace Kyoo.Core.Api { /// /// An API to retrieve or edit configuration settings diff --git a/Kyoo/Views/EpisodeApi.cs b/Kyoo.Core/Views/EpisodeApi.cs similarity index 99% rename from Kyoo/Views/EpisodeApi.cs rename to Kyoo.Core/Views/EpisodeApi.cs index f225c0b7..c4fdf566 100644 --- a/Kyoo/Views/EpisodeApi.cs +++ b/Kyoo.Core/Views/EpisodeApi.cs @@ -7,10 +7,10 @@ using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Abstractions.Models.Permissions; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.Extensions.Options; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [Route("api/episode")] [Route("api/episodes")] diff --git a/Kyoo/Views/GenreApi.cs b/Kyoo.Core/Views/GenreApi.cs similarity index 97% rename from Kyoo/Views/GenreApi.cs rename to Kyoo.Core/Views/GenreApi.cs index 3076fca2..d6e6a678 100644 --- a/Kyoo/Views/GenreApi.cs +++ b/Kyoo.Core/Views/GenreApi.cs @@ -5,11 +5,11 @@ using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Permissions; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [Route("api/genre")] [Route("api/genres")] diff --git a/Kyoo/Views/Helper/ApiHelper.cs b/Kyoo.Core/Views/Helper/ApiHelper.cs similarity index 99% rename from Kyoo/Views/Helper/ApiHelper.cs rename to Kyoo.Core/Views/Helper/ApiHelper.cs index f2650942..31e545c6 100644 --- a/Kyoo/Views/Helper/ApiHelper.cs +++ b/Kyoo.Core/Views/Helper/ApiHelper.cs @@ -6,7 +6,7 @@ using System.Linq.Expressions; using System.Reflection; using Kyoo.Abstractions.Models; -namespace Kyoo.Api +namespace Kyoo.Core.Api { public static class ApiHelper { diff --git a/Kyoo/Views/Helper/CrudApi.cs b/Kyoo.Core/Views/Helper/CrudApi.cs similarity index 99% rename from Kyoo/Views/Helper/CrudApi.cs rename to Kyoo.Core/Views/Helper/CrudApi.cs index eba42b1d..ab1eef72 100644 --- a/Kyoo/Views/Helper/CrudApi.cs +++ b/Kyoo.Core/Views/Helper/CrudApi.cs @@ -8,7 +8,7 @@ using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Abstractions.Models.Permissions; using Microsoft.AspNetCore.Mvc; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [ApiController] [ResourceView] diff --git a/Kyoo/Views/Helper/JsonSerializer.cs b/Kyoo.Core/Views/Helper/JsonSerializer.cs similarity index 99% rename from Kyoo/Views/Helper/JsonSerializer.cs rename to Kyoo.Core/Views/Helper/JsonSerializer.cs index c5b91b03..96d6d6ea 100644 --- a/Kyoo/Views/Helper/JsonSerializer.cs +++ b/Kyoo.Core/Views/Helper/JsonSerializer.cs @@ -6,11 +6,12 @@ using System.Reflection; using System.Text.RegularExpressions; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Attributes; +using Kyoo.Utils; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Newtonsoft.Json.Serialization; -namespace Kyoo.Api +namespace Kyoo.Core.Api { public class JsonPropertyIgnorer : CamelCasePropertyNamesContractResolver { diff --git a/Kyoo/Views/Helper/ResourceViewAttribute.cs b/Kyoo.Core/Views/Helper/ResourceViewAttribute.cs similarity index 98% rename from Kyoo/Views/Helper/ResourceViewAttribute.cs rename to Kyoo.Core/Views/Helper/ResourceViewAttribute.cs index 386dc60c..ad4d9055 100644 --- a/Kyoo/Views/Helper/ResourceViewAttribute.cs +++ b/Kyoo.Core/Views/Helper/ResourceViewAttribute.cs @@ -6,12 +6,13 @@ using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Attributes; +using Kyoo.Utils; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.DependencyInjection; -namespace Kyoo.Api +namespace Kyoo.Core.Api { public class ResourceViewAttribute : ActionFilterAttribute { diff --git a/Kyoo/Views/LibraryApi.cs b/Kyoo.Core/Views/LibraryApi.cs similarity index 99% rename from Kyoo/Views/LibraryApi.cs rename to Kyoo.Core/Views/LibraryApi.cs index 69203926..60991589 100644 --- a/Kyoo/Views/LibraryApi.cs +++ b/Kyoo.Core/Views/LibraryApi.cs @@ -6,10 +6,10 @@ using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Permissions; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.Extensions.Options; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [Route("api/library")] [Route("api/libraries")] diff --git a/Kyoo/Views/LibraryItemApi.cs b/Kyoo.Core/Views/LibraryItemApi.cs similarity index 96% rename from Kyoo/Views/LibraryItemApi.cs rename to Kyoo.Core/Views/LibraryItemApi.cs index 0c801a5c..207eae9c 100644 --- a/Kyoo/Views/LibraryItemApi.cs +++ b/Kyoo.Core/Views/LibraryItemApi.cs @@ -6,11 +6,11 @@ using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Abstractions.Models.Permissions; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [Route("api/item")] [Route("api/items")] diff --git a/Kyoo/Views/PeopleApi.cs b/Kyoo.Core/Views/PeopleApi.cs similarity index 98% rename from Kyoo/Views/PeopleApi.cs rename to Kyoo.Core/Views/PeopleApi.cs index 06ce4df7..5135aa86 100644 --- a/Kyoo/Views/PeopleApi.cs +++ b/Kyoo.Core/Views/PeopleApi.cs @@ -5,11 +5,11 @@ using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Abstractions.Models.Permissions; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [Route("api/people")] [ApiController] diff --git a/Kyoo/Views/ProviderApi.cs b/Kyoo.Core/Views/ProviderApi.cs similarity index 96% rename from Kyoo/Views/ProviderApi.cs rename to Kyoo.Core/Views/ProviderApi.cs index 04f999a1..431fefed 100644 --- a/Kyoo/Views/ProviderApi.cs +++ b/Kyoo.Core/Views/ProviderApi.cs @@ -2,11 +2,11 @@ using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Permissions; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [Route("api/provider")] [Route("api/providers")] diff --git a/Kyoo/Views/SearchApi.cs b/Kyoo.Core/Views/SearchApi.cs similarity index 99% rename from Kyoo/Views/SearchApi.cs rename to Kyoo.Core/Views/SearchApi.cs index 5abe1467..a6e17c91 100644 --- a/Kyoo/Views/SearchApi.cs +++ b/Kyoo.Core/Views/SearchApi.cs @@ -5,7 +5,7 @@ using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Permissions; using Microsoft.AspNetCore.Mvc; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [Route("api/search/{query}")] [ApiController] diff --git a/Kyoo/Views/SeasonApi.cs b/Kyoo.Core/Views/SeasonApi.cs similarity index 98% rename from Kyoo/Views/SeasonApi.cs rename to Kyoo.Core/Views/SeasonApi.cs index 6979b47b..f7be874a 100644 --- a/Kyoo/Views/SeasonApi.cs +++ b/Kyoo.Core/Views/SeasonApi.cs @@ -6,10 +6,10 @@ using System.Linq; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Permissions; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.Extensions.Options; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [Route("api/season")] [Route("api/seasons")] diff --git a/Kyoo/Views/ShowApi.cs b/Kyoo.Core/Views/ShowApi.cs similarity index 99% rename from Kyoo/Views/ShowApi.cs rename to Kyoo.Core/Views/ShowApi.cs index 1c3c3fa5..fe0aaeee 100644 --- a/Kyoo/Views/ShowApi.cs +++ b/Kyoo.Core/Views/ShowApi.cs @@ -8,10 +8,10 @@ using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Abstractions.Models.Permissions; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.Extensions.Options; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [Route("api/show")] [Route("api/shows")] diff --git a/Kyoo/Views/StudioApi.cs b/Kyoo.Core/Views/StudioApi.cs similarity index 97% rename from Kyoo/Views/StudioApi.cs rename to Kyoo.Core/Views/StudioApi.cs index 5474d1f5..87a06a11 100644 --- a/Kyoo/Views/StudioApi.cs +++ b/Kyoo.Core/Views/StudioApi.cs @@ -5,11 +5,11 @@ using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Permissions; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [Route("api/studio")] [Route("api/studios")] diff --git a/Kyoo/Views/SubtitleApi.cs b/Kyoo.Core/Views/SubtitleApi.cs similarity index 99% rename from Kyoo/Views/SubtitleApi.cs rename to Kyoo.Core/Views/SubtitleApi.cs index b6681841..04ddf1d5 100644 --- a/Kyoo/Views/SubtitleApi.cs +++ b/Kyoo.Core/Views/SubtitleApi.cs @@ -7,7 +7,7 @@ using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Permissions; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [Route("subtitle")] [ApiController] diff --git a/Kyoo/Views/TaskApi.cs b/Kyoo.Core/Views/TaskApi.cs similarity index 97% rename from Kyoo/Views/TaskApi.cs rename to Kyoo.Core/Views/TaskApi.cs index 25097411..4bb5b534 100644 --- a/Kyoo/Views/TaskApi.cs +++ b/Kyoo.Core/Views/TaskApi.cs @@ -5,7 +5,7 @@ using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Abstractions.Models.Permissions; using Microsoft.AspNetCore.Mvc; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [Route("api/task")] [Route("api/tasks")] diff --git a/Kyoo/Views/TrackApi.cs b/Kyoo.Core/Views/TrackApi.cs similarity index 95% rename from Kyoo/Views/TrackApi.cs rename to Kyoo.Core/Views/TrackApi.cs index a6a1b6cb..6d16f632 100644 --- a/Kyoo/Views/TrackApi.cs +++ b/Kyoo.Core/Views/TrackApi.cs @@ -4,11 +4,11 @@ using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Abstractions.Models.Permissions; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [Route("api/track")] [Route("api/tracks")] diff --git a/Kyoo/Views/VideoApi.cs b/Kyoo.Core/Views/VideoApi.cs similarity index 98% rename from Kyoo/Views/VideoApi.cs rename to Kyoo.Core/Views/VideoApi.cs index 2badb6dd..b2fa82df 100644 --- a/Kyoo/Views/VideoApi.cs +++ b/Kyoo.Core/Views/VideoApi.cs @@ -5,11 +5,11 @@ using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Abstractions.Models.Permissions; -using Kyoo.Models.Options; +using Kyoo.Core.Models.Options; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Options; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [Route("video")] [ApiController] diff --git a/Kyoo/Views/WatchApi.cs b/Kyoo.Core/Views/WatchApi.cs similarity index 97% rename from Kyoo/Views/WatchApi.cs rename to Kyoo.Core/Views/WatchApi.cs index d4a46e8a..f310c258 100644 --- a/Kyoo/Views/WatchApi.cs +++ b/Kyoo.Core/Views/WatchApi.cs @@ -5,7 +5,7 @@ using Kyoo.Abstractions.Models.Exceptions; using Kyoo.Abstractions.Models.Permissions; using Microsoft.AspNetCore.Mvc; -namespace Kyoo.Api +namespace Kyoo.Core.Api { [Route("api/watch")] [ApiController] diff --git a/Kyoo/settings.json b/Kyoo.Core/settings.json similarity index 67% rename from Kyoo/settings.json rename to Kyoo.Core/settings.json index a3d90396..64466270 100644 --- a/Kyoo/settings.json +++ b/Kyoo.Core/settings.json @@ -30,12 +30,14 @@ }, "logging": { - "logLevel": { - "default": "Warning", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information", - "Microsoft.EntityFrameworkCore": "None", - "Kyoo": "Trace" + "MinimumLevel": { + "Default": "Warning", + "Override": { + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information", + "Microsoft.EntityFrameworkCore": "Fatal", + "Kyoo": "Verbose" + } } }, @@ -45,12 +47,12 @@ "scan": "24:00:00" } }, - + "media": { "regex": [ - "^\\/?(?.+)?\\/(?.+?)(?: \\((?\\d+)\\))?\\/\\k(?: \\(\\d+\\))? S(?\\d+)E(?\\d+)\\..*$", - "^\\/?(?.+)?\\/(?.+?)(?: \\((?\\d+)\\))?\\/\\k(?: \\(\\d+\\))? (?\\d+)\\..*$", - "^\\/?(?.+)?\\/(?.+?)(?: \\((?\\d+)\\))?\\/\\k(?: \\(\\d+\\))?\\..*$" + "^[\\/\\\\]*(?.+)?[\\/\\\\]+(?.+?)(?: \\((?\\d+)\\))?[\\/\\\\]+\\k(?: \\(\\d+\\))? S(?\\d+)E(?\\d+)\\..*$", + "^[\\/\\\\]*(?.+)?[\\/\\\\]+(?.+?)(?: \\((?\\d+)\\))?[\\/\\\\]+\\k(?: \\(\\d+\\))? (?\\d+)\\..*$", + "^[\\/\\\\]*(?.+)?[\\/\\\\]+(?.+?)(?: \\((?\\d+)\\))?[\\/\\\\]+\\k(?: \\(\\d+\\))?\\..*$" ], "subtitleRegex": [ "^(?.+)\\.(?\\w{1,3})\\.(?default\\.)?(?forced\\.)?.*$" @@ -72,9 +74,9 @@ }, "tvdb": { - "apiKey": "REDACTED" + "apiKey": "" }, "the-moviedb": { - "apiKey": "REDACTED" + "apiKey": "" } } diff --git a/Kyoo.Database/Extensions.cs b/Kyoo.Database/Extensions.cs index 43031638..57c72417 100644 --- a/Kyoo.Database/Extensions.cs +++ b/Kyoo.Database/Extensions.cs @@ -1,7 +1,7 @@ using System.Data.Common; using Microsoft.Extensions.Configuration; -namespace Kyoo +namespace Kyoo.Database { /// /// A class that regroup extensions used by some asp-net related parts of the app. diff --git a/Kyoo.Host.Console/Kyoo.Host.Console.csproj b/Kyoo.Host.Console/Kyoo.Host.Console.csproj new file mode 100644 index 00000000..20dc8559 --- /dev/null +++ b/Kyoo.Host.Console/Kyoo.Host.Console.csproj @@ -0,0 +1,25 @@ + + + Exe + net5.0 + Kyoo.Host.Console.Program + + SDG + Zoe Roux + https://github.com/AnonymusRaccoon/Kyoo + default + + + + + win-x64 + + + + + + diff --git a/Kyoo.Host.Console/Program.cs b/Kyoo.Host.Console/Program.cs new file mode 100644 index 00000000..6d5edb49 --- /dev/null +++ b/Kyoo.Host.Console/Program.cs @@ -0,0 +1,31 @@ +using System.Threading.Tasks; +using Kyoo.Core; +using Microsoft.AspNetCore.Hosting; + +namespace Kyoo.Host.Console +{ + /// + /// Program entrypoint. + /// + public static class Program + { + /// + /// The string representation of the environment used in . + /// +#if DEBUG + private const string Environment = "Development"; +#else + private const string Environment = "Production"; +#endif + + /// + /// Main function of the program + /// + /// Command line arguments + public static Task Main(string[] args) + { + Application application = new(Environment); + return application.Start(args); + } + } +} diff --git a/Kyoo.Host.WindowsTrait/Kyoo.Host.WindowsTrait.csproj b/Kyoo.Host.WindowsTrait/Kyoo.Host.WindowsTrait.csproj new file mode 100644 index 00000000..41ab83db --- /dev/null +++ b/Kyoo.Host.WindowsTrait/Kyoo.Host.WindowsTrait.csproj @@ -0,0 +1,12 @@ + + + true + + + + + + + + + \ No newline at end of file diff --git a/Kyoo.Host.WindowsTrait/Kyoo.Host.WindowsTrait.linux.target b/Kyoo.Host.WindowsTrait/Kyoo.Host.WindowsTrait.linux.target new file mode 100644 index 00000000..e60b9c2a --- /dev/null +++ b/Kyoo.Host.WindowsTrait/Kyoo.Host.WindowsTrait.linux.target @@ -0,0 +1,26 @@ + + + + + + + net5.0 + NU1503 + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Kyoo.Host.WindowsTrait/Kyoo.Host.WindowsTrait.target b/Kyoo.Host.WindowsTrait/Kyoo.Host.WindowsTrait.target new file mode 100644 index 00000000..d0f97e34 --- /dev/null +++ b/Kyoo.Host.WindowsTrait/Kyoo.Host.WindowsTrait.target @@ -0,0 +1,24 @@ + + + + + WinExe + net5.0-windows + true + Kyoo.WindowsHost + + + + + + + + + + + PreserveNewest + + + diff --git a/Kyoo.Host.WindowsTrait/Program.cs b/Kyoo.Host.WindowsTrait/Program.cs new file mode 100644 index 00000000..65b9a2bc --- /dev/null +++ b/Kyoo.Host.WindowsTrait/Program.cs @@ -0,0 +1,32 @@ +using System.Threading.Tasks; +using Autofac; +using Kyoo.Core; + +namespace Kyoo.Host.WindowsTrait +{ + public static class Program + { + /// + /// The string representation of the environment used in IWebHostEnvironment. + /// +#if DEBUG + private const string Environment = "Development"; +#else + private const string Environment = "Production"; +#endif + + /// + /// The main entry point for the application that overrides the default host. + /// It adds a system trait for windows and since the host is build as a windows executable instead of a console + /// app, the console is not showed. + /// + public static Task Main(string[] args) + { + Application application = new(Environment); + return application.Start(args, builder => + { + builder.RegisterType().As().SingleInstance(); + }); + } + } +} \ No newline at end of file diff --git a/Kyoo.Host.WindowsTrait/SystemTrait.cs b/Kyoo.Host.WindowsTrait/SystemTrait.cs new file mode 100644 index 00000000..34708f86 --- /dev/null +++ b/Kyoo.Host.WindowsTrait/SystemTrait.cs @@ -0,0 +1,163 @@ +using System; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.Threading; +using System.Windows.Forms; +using Autofac; +using Kyoo.Abstractions.Controllers; +using Kyoo.Core.Models.Options; +using Microsoft.Extensions.Options; + +namespace Kyoo.Host.WindowsTrait +{ + /// + /// A singleton that add an notification icon on the window's toolbar. + /// + public sealed class SystemTrait : IStartable, IDisposable + { + /// + /// The application running Kyoo. + /// + private readonly IApplication _application; + + /// + /// The options containing the . + /// + private readonly IOptions _options; + + /// + /// The thread where the trait is running. + /// + private Thread _thread; + + + /// + /// Create a new . + /// + /// The application running Kyoo. + /// The options to use. + public SystemTrait(IApplication application, IOptions options) + { + _application = application; + _options = options; + } + + /// + public void Start() + { + _thread = new Thread(() => InternalSystemTrait.Run(_application, _options)) + { + IsBackground = true + }; + _thread.Start(); + } + + /// + public void Dispose() + { + System.Windows.Forms.Application.Exit(); + _thread?.Join(); + _thread = null; + } + + /// + /// The internal class for . It should be invoked via + /// . + /// + private class InternalSystemTrait : ApplicationContext + { + /// + /// The application running Kyoo. + /// + private readonly IApplication _application; + + /// + /// The options containing the . + /// + private readonly IOptions _options; + + /// + /// The Icon that is displayed in the window's bar. + /// + private readonly NotifyIcon _icon; + + /// + /// Create a new . Used only by . + /// + /// The application running Kyoo. + /// The option containing the public url. + private InternalSystemTrait(IApplication application, IOptions options) + { + _application = application; + _options = options; + + AppDomain.CurrentDomain.ProcessExit += (_, _) => Dispose(); + System.Windows.Forms.Application.ApplicationExit += (_, _) => Dispose(); + + _icon = new NotifyIcon(); + _icon.Text = "Kyoo"; + _icon.Icon = new Icon(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "kyoo.ico")); + _icon.Visible = true; + _icon.MouseClick += (_, e) => + { + if (e.Button != MouseButtons.Left) + return; + _StartBrowser(); + }; + + _icon.ContextMenuStrip = new ContextMenuStrip(); + _icon.ContextMenuStrip.Items.AddRange(new ToolStripItem[] + { + new ToolStripMenuItem("Open browser", null, (_, _) => { _StartBrowser(); }), + new ToolStripMenuItem("Open logs", null, (_, _) => { _OpenLogs(); }), + new ToolStripSeparator(), + new ToolStripMenuItem("Exit", null, (_, _) => { _application.Shutdown(); }) + }); + } + + /// + /// Run the trait in the current thread, this method does not return while the trait is running. + /// + /// The application running Kyoo. + /// The options to pass to . + public static void Run(IApplication application, IOptions options) + { + using InternalSystemTrait trait = new(application, options); + System.Windows.Forms.Application.Run(trait); + } + + /// + protected override void Dispose(bool disposing) + { + _icon.Visible = false; + base.Dispose(disposing); + _icon.Dispose(); + } + + /// + /// Open kyoo's page in the user's default browser. + /// + private void _StartBrowser() + { + Process browser = new() + { + StartInfo = new ProcessStartInfo(_options.Value.PublicUrl.ToString()) + { + UseShellExecute = true + } + }; + browser.Start(); + } + + /// + /// Open the log directory in windows's explorer. + /// + private void _OpenLogs() + { + string logDir = Path.Combine(_application.GetDataDirectory(), "logs"); + Process.Start("explorer.exe", logDir); + } + } + } +} \ No newline at end of file diff --git a/Kyoo.Host.WindowsTrait/kyoo.ico b/Kyoo.Host.WindowsTrait/kyoo.ico new file mode 100644 index 00000000..61e16024 Binary files /dev/null and b/Kyoo.Host.WindowsTrait/kyoo.ico differ diff --git a/Kyoo.Postgresql/PostgresContext.cs b/Kyoo.Postgresql/PostgresContext.cs index cbefb849..c8477169 100644 --- a/Kyoo.Postgresql/PostgresContext.cs +++ b/Kyoo.Postgresql/PostgresContext.cs @@ -5,6 +5,7 @@ using System.Reflection; using EFCore.NamingConventions.Internal; using Kyoo.Abstractions.Models; using Kyoo.Database; +using Kyoo.Utils; using Microsoft.EntityFrameworkCore; using Npgsql; diff --git a/Kyoo.SqLite/SqLiteContext.cs b/Kyoo.SqLite/SqLiteContext.cs index 123de717..87aa5637 100644 --- a/Kyoo.SqLite/SqLiteContext.cs +++ b/Kyoo.SqLite/SqLiteContext.cs @@ -4,6 +4,7 @@ using System.Linq.Expressions; using System.Reflection; using Kyoo.Abstractions.Models; using Kyoo.Database; +using Kyoo.Utils; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; diff --git a/Kyoo.TheMovieDb/Convertors/CollectionConvertors.cs b/Kyoo.TheMovieDb/Convertors/CollectionConvertors.cs index 3c1460f2..47c88f41 100644 --- a/Kyoo.TheMovieDb/Convertors/CollectionConvertors.cs +++ b/Kyoo.TheMovieDb/Convertors/CollectionConvertors.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Kyoo.Abstractions.Models; +using Kyoo.Utils; using TMDbLib.Objects.Search; namespace Kyoo.TheMovieDb diff --git a/Kyoo.TheMovieDb/Convertors/MovieConvertors.cs b/Kyoo.TheMovieDb/Convertors/MovieConvertors.cs index f859c489..d123ca28 100644 --- a/Kyoo.TheMovieDb/Convertors/MovieConvertors.cs +++ b/Kyoo.TheMovieDb/Convertors/MovieConvertors.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using Kyoo.Abstractions.Models; +using Kyoo.Utils; using TMDbLib.Objects.Movies; using TMDbLib.Objects.Search; diff --git a/Kyoo.TheMovieDb/Convertors/PeopleConvertors.cs b/Kyoo.TheMovieDb/Convertors/PeopleConvertors.cs index 32a0cbaf..61c57db9 100644 --- a/Kyoo.TheMovieDb/Convertors/PeopleConvertors.cs +++ b/Kyoo.TheMovieDb/Convertors/PeopleConvertors.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Kyoo.Abstractions.Models; +using Kyoo.Utils; using TMDbLib.Objects.General; using TMDbLib.Objects.People; using TMDbLib.Objects.Search; diff --git a/Kyoo.TheMovieDb/Convertors/ShowConvertors.cs b/Kyoo.TheMovieDb/Convertors/ShowConvertors.cs index a47b62c5..99ccc046 100644 --- a/Kyoo.TheMovieDb/Convertors/ShowConvertors.cs +++ b/Kyoo.TheMovieDb/Convertors/ShowConvertors.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using Kyoo.Abstractions.Models; +using Kyoo.Utils; using TMDbLib.Objects.Search; using TMDbLib.Objects.TvShows; diff --git a/Kyoo.TheMovieDb/Convertors/StudioConvertors.cs b/Kyoo.TheMovieDb/Convertors/StudioConvertors.cs index 42290c73..22f2ef9d 100644 --- a/Kyoo.TheMovieDb/Convertors/StudioConvertors.cs +++ b/Kyoo.TheMovieDb/Convertors/StudioConvertors.cs @@ -1,4 +1,5 @@ using Kyoo.Abstractions.Models; +using Kyoo.Utils; using TMDbLib.Objects.Companies; using TMDbLib.Objects.Search; diff --git a/Kyoo.TheMovieDb/PluginTmdb.cs b/Kyoo.TheMovieDb/PluginTmdb.cs index 6fb94e23..9af1a267 100644 --- a/Kyoo.TheMovieDb/PluginTmdb.cs +++ b/Kyoo.TheMovieDb/PluginTmdb.cs @@ -4,6 +4,8 @@ using Autofac; using Kyoo.Abstractions; using Kyoo.Abstractions.Controllers; using Kyoo.TheMovieDb.Models; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; namespace Kyoo.TheMovieDb { @@ -16,17 +18,38 @@ namespace Kyoo.TheMovieDb public string Slug => "the-moviedb"; /// - public string Name => "TheMovieDb Provider"; + public string Name => "TheMovieDb"; /// public string Description => "A metadata provider for TheMovieDB."; - + + /// + public bool Enabled => !string.IsNullOrEmpty(_configuration.GetValue("the-moviedb:apikey")); + /// public Dictionary Configuration => new() { { TheMovieDbOptions.Path, typeof(TheMovieDbOptions) } }; + /// + /// The configuration used to check if the api key is present or not. + /// + private readonly IConfiguration _configuration; + + /// + /// Create a new . + /// + /// The configuration used to check if the api key is present or not. + /// The logger used to warn when the api key is not present. + public PluginTmdb(IConfiguration configuration, ILogger logger) + { + _configuration = configuration; + if (!Enabled) + logger.LogWarning("No API key configured for TheMovieDB provider. " + + "To enable TheMovieDB, specify one in the setting the-moviedb:APIKEY "); + } + /// public void Configure(ContainerBuilder builder) { diff --git a/Kyoo.TheTvdb/Convertors.cs b/Kyoo.TheTvdb/Convertors.cs index 20413570..d53dfe62 100644 --- a/Kyoo.TheTvdb/Convertors.cs +++ b/Kyoo.TheTvdb/Convertors.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using Kyoo.Abstractions.Models; +using Kyoo.Utils; using TvDbSharper.Dto; namespace Kyoo.TheTvdb diff --git a/Kyoo.TheTvdb/Kyoo.TheTvdb.csproj b/Kyoo.TheTvdb/Kyoo.TheTvdb.csproj index 29995a3c..f2c052ff 100644 --- a/Kyoo.TheTvdb/Kyoo.TheTvdb.csproj +++ b/Kyoo.TheTvdb/Kyoo.TheTvdb.csproj @@ -10,6 +10,7 @@ + diff --git a/Kyoo.TheTvdb/PluginTvdb.cs b/Kyoo.TheTvdb/PluginTvdb.cs index 8d43cb81..75feee76 100644 --- a/Kyoo.TheTvdb/PluginTvdb.cs +++ b/Kyoo.TheTvdb/PluginTvdb.cs @@ -4,6 +4,8 @@ using Autofac; using Kyoo.Abstractions; using Kyoo.Abstractions.Controllers; using Kyoo.TheTvdb.Models; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; using TvDbSharper; namespace Kyoo.TheTvdb @@ -15,19 +17,40 @@ namespace Kyoo.TheTvdb { /// public string Slug => "the-tvdb"; - + /// - public string Name => "The TVDB Provider"; - + public string Name => "TVDB"; + /// public string Description => "A metadata provider for The TVDB."; + /// + public bool Enabled => !string.IsNullOrEmpty(_configuration.GetValue("tvdb:apikey")); + /// public Dictionary Configuration => new() { { TvdbOption.Path, typeof(TvdbOption) } }; + /// + /// The configuration used to check if the api key is present or not. + /// + private readonly IConfiguration _configuration; + + /// + /// Create a new . + /// + /// The configuration used to check if the api key is present or not. + /// The logger used to warn when the api key is not present. + public PluginTvdb(IConfiguration configuration, ILogger logger) + { + _configuration = configuration; + if (!Enabled) + logger.LogWarning("No API key configured for TVDB provider. " + + "To enable TVDB, specify one in the setting TVDB:APIKEY "); + } + /// public void Configure(ContainerBuilder builder) { diff --git a/Kyoo.Transcoder b/Kyoo.Transcoder index 75b49dcd..7bae8def 160000 --- a/Kyoo.Transcoder +++ b/Kyoo.Transcoder @@ -1 +1 @@ -Subproject commit 75b49dcd25aed20eda7454faa4bc016a12c51680 +Subproject commit 7bae8def39ace7bab481efea4825c4802e9e1f31 diff --git a/Kyoo.WebApp/Front b/Kyoo.WebApp/Front index 865b82ec..a3da5f1e 160000 --- a/Kyoo.WebApp/Front +++ b/Kyoo.WebApp/Front @@ -1 +1 @@ -Subproject commit 865b82ec43f37b8afc173259b66566d8ad4c18de +Subproject commit a3da5f1e6edb982e3b71792a7ea6fcd45661c337 diff --git a/Kyoo.WebApp/Kyoo.WebApp.csproj b/Kyoo.WebApp/Kyoo.WebApp.csproj index c8c5fe64..910d2167 100644 --- a/Kyoo.WebApp/Kyoo.WebApp.csproj +++ b/Kyoo.WebApp/Kyoo.WebApp.csproj @@ -1,4 +1,6 @@ - + + + net5.0 true @@ -6,6 +8,7 @@ false $(DefaultItemExcludes);$(SpaRoot)node_modules/** Front/ + $(SpaRoot)node_modules/.install-stamp false @@ -33,17 +36,24 @@ - + + + + + + + + + + + - + @@ -53,18 +63,13 @@ - - - - - - - - + - - - - + + + NpmInstall; + RunWebpack; + $(BuildDependsOn) + + diff --git a/Kyoo.WebApp/WebAppModule.cs b/Kyoo.WebApp/WebAppModule.cs index dc17c899..a83910cb 100644 --- a/Kyoo.WebApp/WebAppModule.cs +++ b/Kyoo.WebApp/WebAppModule.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Runtime.CompilerServices; using Kyoo.Abstractions.Controllers; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; @@ -33,28 +34,17 @@ namespace Kyoo.WebApp /// public bool Enabled => Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot")); - - /// - /// A logger only used to inform the user if the webapp could not be enabled. - /// - private readonly ILogger _logger; - /// /// Create a new . /// /// A logger only used to inform the user if the webapp could not be enabled. public WebAppModule(ILogger logger) { - _logger = logger; + if (!Enabled) + logger.LogError("The web app files could not be found, it will be disabled. " + + "If you cloned the project, you probably forgot to use the --recurse flag"); } - - /// - public void Disabled() - { - _logger.LogError("The web app files could not be found, it will be disabled. " + - "If you cloned the project, you probably forgot to use the --recurse flag"); - } - + /// public void Configure(IServiceCollection services) { @@ -99,12 +89,27 @@ namespace Kyoo.WebApp { app.UseSpa(spa => { - spa.Options.SourcePath = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "Kyoo.WebApp", "Front"); + spa.Options.SourcePath = _GetSpaSourcePath(); if (env.IsDevelopment()) spa.UseAngularCliServer("start"); }); }, SA.Endpoint - 500) }; + + /// + /// Get the root directory of the web app + /// + /// The path of the source code of the web app or null if the directory has been deleted. + private static string _GetSpaSourcePath() + { + string GetSelfPath([CallerFilePath] string path = null) + { + return path; + } + + string path = Path.Join(Path.GetDirectoryName(GetSelfPath()), "Front"); + return Directory.Exists(path) ? path : null; + } } } \ No newline at end of file diff --git a/Kyoo.sln b/Kyoo.sln index 701d760b..39e1cc4e 100644 --- a/Kyoo.sln +++ b/Kyoo.sln @@ -1,5 +1,5 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kyoo", "Kyoo\Kyoo.csproj", "{0F8275B6-C7DD-42DF-A168-755C81B1C329}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kyoo.Core", "Kyoo.Core\Kyoo.Core.csproj", "{0F8275B6-C7DD-42DF-A168-755C81B1C329}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.Abstractions", "Kyoo.Abstractions\Kyoo.Abstractions.csproj", "{BAB2CAE1-AC28-4509-AA3E-8DC75BD59220}" EndProject @@ -19,6 +19,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.Tests", "tests\Kyoo.Te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.WebApp", "Kyoo.WebApp\Kyoo.WebApp.csproj", "{2374D500-1ADB-4752-85DB-8BB0DDF5A8E8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.Host.WindowsTrait", "Kyoo.Host.WindowsTrait\Kyoo.Host.WindowsTrait.csproj", "{98851001-40DD-46A6-94B3-2F8D90722076}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kyoo.Host.Console", "Kyoo.Host.Console\Kyoo.Host.Console.csproj", "{D8658BEA-8949-45AC-BEBB-A4FFC4F800F5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -65,5 +69,17 @@ Global {2374D500-1ADB-4752-85DB-8BB0DDF5A8E8}.Debug|Any CPU.Build.0 = Debug|Any CPU {2374D500-1ADB-4752-85DB-8BB0DDF5A8E8}.Release|Any CPU.ActiveCfg = Release|Any CPU {2374D500-1ADB-4752-85DB-8BB0DDF5A8E8}.Release|Any CPU.Build.0 = Release|Any CPU + {4FF1ECD9-6EEF-4440-B037-A661D78FB04D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4FF1ECD9-6EEF-4440-B037-A661D78FB04D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4FF1ECD9-6EEF-4440-B037-A661D78FB04D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4FF1ECD9-6EEF-4440-B037-A661D78FB04D}.Release|Any CPU.Build.0 = Release|Any CPU + {98851001-40DD-46A6-94B3-2F8D90722076}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {98851001-40DD-46A6-94B3-2F8D90722076}.Debug|Any CPU.Build.0 = Debug|Any CPU + {98851001-40DD-46A6-94B3-2F8D90722076}.Release|Any CPU.ActiveCfg = Release|Any CPU + {98851001-40DD-46A6-94B3-2F8D90722076}.Release|Any CPU.Build.0 = Release|Any CPU + {D8658BEA-8949-45AC-BEBB-A4FFC4F800F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D8658BEA-8949-45AC-BEBB-A4FFC4F800F5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D8658BEA-8949-45AC-BEBB-A4FFC4F800F5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D8658BEA-8949-45AC-BEBB-A4FFC4F800F5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Kyoo/Program.cs b/Kyoo/Program.cs deleted file mode 100644 index e9f21a0b..00000000 --- a/Kyoo/Program.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; -using System.IO; -using System.Threading.Tasks; -using Autofac.Extensions.DependencyInjection; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; - -namespace Kyoo -{ - /// - /// Program entrypoint. - /// - public static class Program - { - /// - /// The path of the json configuration of the application. - /// - public const string JsonConfigPath = "./settings.json"; - - /// - /// The string representation of the environment used in . - /// -#if DEBUG - private const string Environment = "Development"; -#else - private const string Environment = "Production"; -#endif - - /// - /// Main function of the program - /// - /// Command line arguments - public static async Task Main(string[] args) - { - if (!File.Exists(JsonConfigPath)) - File.Copy(Path.Join(AppDomain.CurrentDomain.BaseDirectory, JsonConfigPath), JsonConfigPath); - - IHost host = CreateWebHostBuilder(args) - .UseEnvironment(Environment) - .Build(); - - try - { - host.Services.GetRequiredService>() - .LogInformation("Running as {Name}", System.Environment.UserName); - await host.RunAsync(); - } - catch (Exception ex) - { - host.Services.GetRequiredService>().LogCritical(ex, "Unhandled exception"); - } - } - - /// - /// Register settings.json, environment variables and command lines arguments as configuration. - /// - /// The configuration builder to use - /// The command line arguments - /// The modified configuration builder - private static IConfigurationBuilder SetupConfig(IConfigurationBuilder builder, string[] args) - { - return builder.SetBasePath(System.Environment.CurrentDirectory) - .AddJsonFile(JsonConfigPath, false, true) - .AddEnvironmentVariables() - .AddCommandLine(args); - } - - /// - /// Configure the logging. - /// - /// The host context that contains the configuration - /// The logger builder to configure. - private static void _ConfigureLogging(HostBuilderContext context, ILoggingBuilder builder) - { - builder.AddConfiguration(context.Configuration.GetSection("logging")) - .AddSimpleConsole(x => - { - x.TimestampFormat = "[hh:mm:ss] "; - }) - .AddDebug() - .AddEventSourceLogger(); - } - - /// - /// Create a a web host - /// - /// Command line parameters that can be handled by kestrel - /// - /// An action to configure the logging. If it is null, will be used. - /// - /// A new web host instance - public static IHostBuilder CreateWebHostBuilder(string[] args, - Action loggingConfiguration = null) - { - IConfiguration configuration = SetupConfig(new ConfigurationBuilder(), args).Build(); - loggingConfiguration ??= _ConfigureLogging; - - return new HostBuilder() - .UseServiceProviderFactory(new AutofacServiceProviderFactory()) - .UseContentRoot(AppDomain.CurrentDomain.BaseDirectory) - .ConfigureAppConfiguration(x => SetupConfig(x, args)) - .ConfigureLogging(loggingConfiguration) - .ConfigureServices(x => x.AddRouting()) - .ConfigureWebHost(x => x - .UseKestrel(options => { options.AddServerHeader = false; }) - .UseIIS() - .UseIISIntegration() - .UseUrls(configuration.GetValue("basics:url")) - .UseStartup(host => PluginsStartup.FromWebHost(host, loggingConfiguration)) - ); - } - - /// - /// An useless class only used to have a logger in the main. - /// - private class Application {} - } -} diff --git a/deployment/PKGBUILD b/deployment/PKGBUILD index 005865a1..5446499f 100644 --- a/deployment/PKGBUILD +++ b/deployment/PKGBUILD @@ -8,9 +8,8 @@ arch=("i686" "x86_64" "armv6h") url="https://github.com/AnonymusRaccoon/Kyoo" license=("GPLv3") groups=() -depends=("dotnet-runtime>=5" "aspnet-runtime>=5" "postgresql" "ffmpeg") +depends=("dotnet-runtime>=5" "aspnet-runtime>=5" "ffmpeg") makedepends=("dotnet-sdk>=5" "cmake" "gcc" "make" "npm" "git") -install="kyoo.install" source=("git+https://github.com/AnonymusRaccoon/Kyoo" #tag=v${pkgver} "kyoo.service" "kyoo.sysusers" @@ -30,7 +29,7 @@ build() { # cd "Kyoo-$pkgver" cd "Kyoo" export DOTNET_CLI_TELEMETRY_OPTOUT=1 - dotnet publish -c Release -o "$srcdir/output" Kyoo + dotnet publish -c Release -o "$srcdir/output" Kyoo.Host.Console } package() { diff --git a/deployment/PKGBUILD.github b/deployment/PKGBUILD.github index 1fbdaa3d..e464dfc8 100644 --- a/deployment/PKGBUILD.github +++ b/deployment/PKGBUILD.github @@ -8,9 +8,8 @@ arch=("i686" "x86_64" "armv6h") url="https://github.com/AnonymusRaccoon/Kyoo" license=("GPLv3") groups=() -depends=("postgresql" "ffmpeg") +depends=("ffmpeg") makedepends=() -install="kyoo.install" # The output folder is needed but we can't use directory in the source array. source=() sha256sums=() diff --git a/deployment/kyoo-windows.iss b/deployment/kyoo-windows.iss new file mode 100644 index 00000000..276fe810 --- /dev/null +++ b/deployment/kyoo-windows.iss @@ -0,0 +1,67 @@ +[Setup] +AppId={{31A61284-7939-46BC-B584-D2279A6EEEE8} +AppName=Kyoo +AppVersion=1.0 +AppPublisher=SDG +AppPublisherURL=https://github.com/AnonymusRaccoon/Kyoo +AppSupportURL=https://github.com/AnonymusRaccoon/Kyoo +AppUpdatesURL=https://github.com/AnonymusRaccoon/Kyoo +DefaultDirName={commonpf}\Kyoo +DisableProgramGroupPage=yes +LicenseFile={#kyoo}\LICENSE +SetupIconFile={#kyoo}\wwwroot\favicon.ico +Compression=lzma +SolidCompression=yes +WizardStyle=modern +AppCopyright=GPL-3.0 +ArchitecturesInstallIn64BitMode=x64 arm64 ia64 + +[Languages] +Name: "english"; MessagesFile: "compiler:Default.isl" + +[Tasks] +Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked +Name: "startupShortcut"; Description: "Create shortcut in Startup folder (Starts when you log into Windows)"; GroupDescription: "Start automatically"; Flags: exclusive +Name: "none"; Description: "Do not start automatically"; GroupDescription: "Start automatically"; Flags: exclusive unchecked + +[Files] +Source: "{#kyoo}\Kyoo.Host.Console.exe"; DestDir: "{app}"; Flags: ignoreversion +Source: "{#kyoo}\Kyoo.Host.WindowsTrait.exe"; DestDir: "{app}"; Flags: ignoreversion +Source: "{#kyoo}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs + +[Registry] +Root: HKA; Subkey: "Software\SDG"; Flags: uninsdeletekeyifempty +Root: HKA; Subkey: "Software\SDG\Kyoo"; Flags: uninsdeletekey +Root: HKA; Subkey: "Software\SDG\Kyoo\Settings"; ValueType: string; ValueName: "DataDir"; ValueData: "{code:GetDataDir}" + +[UninstallDelete] +Type: filesandordirs; Name: "{code:GetDataDir}" + +[Icons] +Name: "{autoprograms}\Kyoo"; Filename: "{app}\Kyoo.Host.WindowsTrait.exe" +Name: "{autoprograms}\Kyoo (Console)"; Filename: "{app}\Kyoo.Host.Console.exe" +Name: "{autodesktop}\Kyoo"; Filename: "{app}\Kyoo.Host.WindowsTrait.exe"; Tasks: desktopicon +Name: "{autostartup}\Kyoo"; Filename: "{app}\Kyoo.Host.WindowsTrait.exe"; Tasks: startupShortcut + +[Run] +Filename: "{app}\Kyoo.Host.WindowsTrait.exe"; Description: "{cm:LaunchProgram,Kyoo}"; Flags: nowait postinstall skipifsilent + +[Code] +var + DataDirPage: TInputDirWizardPage; + +procedure InitializeWizard; +begin + DataDirPage := CreateInputDirPage(wpSelectDir, + 'Choose Data Location', 'Choose the folder in which to install the Kyoo data', + 'The installer will set the following folder for Kyoo. To install in a different folder, click Browse and select another folder.' + + 'Please make sure the folder exists and is accessible. Do not choose the server install folder. Click Next to continue.', + False, ''); + DataDirPage.Add(''); + DataDirPage.Values[0] := GetPreviousData('DataDir', 'C:\ProgramData\Kyoo'); +end; + +function GetDataDir(Param: String): String; +begin + Result := DataDirPage.Values[0]; +end; \ No newline at end of file diff --git a/deployment/kyoo.install b/deployment/kyoo.install deleted file mode 100644 index 080047de..00000000 --- a/deployment/kyoo.install +++ /dev/null @@ -1,11 +0,0 @@ -post_install() { - sudo -u postgres psql <<- "EOF" - DO $$ - BEGIN - CREATE ROLE kyoo WITH CREATEDB LOGIN PASSWORD 'kyooPassword'; - EXCEPTION WHEN DUPLICATE_OBJECT THEN - RAISE NOTICE 'not creating role kyoo -- it already exists'; - END - $$; - EOF -} \ No newline at end of file diff --git a/deployment/kyoo.service b/deployment/kyoo.service index 277c26ca..121ffc9d 100644 --- a/deployment/kyoo.service +++ b/deployment/kyoo.service @@ -5,8 +5,8 @@ After=network.target [Service] User=kyoo -WorkingDirectory=/var/lib/kyoo -ExecStart=/usr/lib/kyoo/Kyoo +Environment=KYOO_DATADIR=/var/lib/kyoo +ExecStart=/usr/lib/kyoo/Kyoo.Host.Console Restart=on-abort TimeoutSec=20 diff --git a/deployment/kyoo.spec b/deployment/kyoo.spec index 6cf1c4a2..b59e907e 100644 --- a/deployment/kyoo.spec +++ b/deployment/kyoo.spec @@ -7,7 +7,7 @@ Summary: A media browser URL: https://github.com/AnonymusRaccoon/Kyoo License: GPL-3.0 BuildArch: x86_64 -Requires: postgresql-server ffmpeg-devel +Requires: ffmpeg-devel AutoReqProv: no %description @@ -24,17 +24,3 @@ rm -rf %{buildroot} /usr/lib/systemd/system/* /usr/lib/sysusers.d/kyoo.conf /usr/lib/tmpfiles.d/kyoo.conf - -%post -sudo postgresql-setup --initdb 2> /dev/null || true -sudo systemctl start postgresql -sudo -u postgres psql << "EOF" -DO $$ -BEGIN - CREATE ROLE kyoo WITH CREATEDB LOGIN PASSWORD 'kyooPassword'; - EXCEPTION WHEN DUPLICATE_OBJECT THEN - RAISE NOTICE 'not creating role kyoo -- it already exists'; -END -$$; -EOF - diff --git a/deployment/postinst b/deployment/postinst deleted file mode 100644 index cdf42470..00000000 --- a/deployment/postinst +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -set -e - -sudo -u postgres psql << "EOF" -DO $$ -BEGIN - CREATE ROLE kyoo WITH CREATEDB LOGIN PASSWORD 'kyooPassword'; - EXCEPTION WHEN DUPLICATE_OBJECT THEN - RAISE NOTICE 'not creating role kyoo -- it already exists'; -END -$$; -EOF - -systemd-sysusers -systemd-tmpfiles --create diff --git a/tests/Kyoo.Tests/Database/RepositoryActivator.cs b/tests/Kyoo.Tests/Database/RepositoryActivator.cs index 92addd86..267bafb7 100644 --- a/tests/Kyoo.Tests/Database/RepositoryActivator.cs +++ b/tests/Kyoo.Tests/Database/RepositoryActivator.cs @@ -2,7 +2,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; -using Kyoo.Controllers; +using Kyoo.Core.Controllers; using Kyoo.Database; using Xunit.Abstractions; diff --git a/tests/Kyoo.Tests/Database/SpecificTests/LibraryTests.cs b/tests/Kyoo.Tests/Database/SpecificTests/LibraryTests.cs index 20b7defe..a1a3d131 100644 --- a/tests/Kyoo.Tests/Database/SpecificTests/LibraryTests.cs +++ b/tests/Kyoo.Tests/Database/SpecificTests/LibraryTests.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Database; +using Kyoo.Utils; using Microsoft.EntityFrameworkCore; using Xunit; using Xunit.Abstractions; diff --git a/tests/Kyoo.Tests/Database/SpecificTests/ShowTests.cs b/tests/Kyoo.Tests/Database/SpecificTests/ShowTests.cs index c46aaa26..b502e125 100644 --- a/tests/Kyoo.Tests/Database/SpecificTests/ShowTests.cs +++ b/tests/Kyoo.Tests/Database/SpecificTests/ShowTests.cs @@ -6,6 +6,7 @@ using FluentAssertions; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Database; +using Kyoo.Utils; using Microsoft.EntityFrameworkCore; using Xunit; using Xunit.Abstractions; diff --git a/tests/Kyoo.Tests/Identifier/IdentifierTests.cs b/tests/Kyoo.Tests/Identifier/IdentifierTests.cs index 93f6c345..3ab526d6 100644 --- a/tests/Kyoo.Tests/Identifier/IdentifierTests.cs +++ b/tests/Kyoo.Tests/Identifier/IdentifierTests.cs @@ -2,8 +2,8 @@ using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Exceptions; -using Kyoo.Controllers; -using Kyoo.Models.Options; +using Kyoo.Core.Controllers; +using Kyoo.Core.Models.Options; using Microsoft.Extensions.Options; using Moq; using Xunit; diff --git a/tests/Kyoo.Tests/Identifier/ProviderTests.cs b/tests/Kyoo.Tests/Identifier/ProviderTests.cs index 0d9eb34a..384e6b79 100644 --- a/tests/Kyoo.Tests/Identifier/ProviderTests.cs +++ b/tests/Kyoo.Tests/Identifier/ProviderTests.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Threading.Tasks; using Kyoo.Abstractions.Controllers; using Kyoo.Abstractions.Models; -using Kyoo.Controllers; +using Kyoo.Core.Controllers; using Microsoft.Extensions.Logging; using Moq; using Xunit; diff --git a/tests/Kyoo.Tests/Kyoo.Tests.csproj b/tests/Kyoo.Tests/Kyoo.Tests.csproj index 7568e9d5..02627f91 100644 --- a/tests/Kyoo.Tests/Kyoo.Tests.csproj +++ b/tests/Kyoo.Tests/Kyoo.Tests.csproj @@ -34,7 +34,7 @@ - + diff --git a/tests/Kyoo.Tests/Utility/EnumerableTests.cs b/tests/Kyoo.Tests/Utility/EnumerableTests.cs index c03efa06..627de26b 100644 --- a/tests/Kyoo.Tests/Utility/EnumerableTests.cs +++ b/tests/Kyoo.Tests/Utility/EnumerableTests.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Kyoo.Utils; using Xunit; namespace Kyoo.Tests.Utility diff --git a/tests/Kyoo.Tests/Utility/MergerTests.cs b/tests/Kyoo.Tests/Utility/MergerTests.cs index a378ebb7..2765c7e2 100644 --- a/tests/Kyoo.Tests/Utility/MergerTests.cs +++ b/tests/Kyoo.Tests/Utility/MergerTests.cs @@ -5,6 +5,7 @@ using System.Linq; using JetBrains.Annotations; using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models.Attributes; +using Kyoo.Utils; using Xunit; namespace Kyoo.Tests.Utility diff --git a/tests/Kyoo.Tests/Utility/TaskTests.cs b/tests/Kyoo.Tests/Utility/TaskTests.cs index 3bcd723f..47cbbf69 100644 --- a/tests/Kyoo.Tests/Utility/TaskTests.cs +++ b/tests/Kyoo.Tests/Utility/TaskTests.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using Kyoo.Utils; using Xunit; namespace Kyoo.Tests.Utility diff --git a/tests/Kyoo.Tests/Utility/UtilityTests.cs b/tests/Kyoo.Tests/Utility/UtilityTests.cs index 5c01069c..262337d0 100644 --- a/tests/Kyoo.Tests/Utility/UtilityTests.cs +++ b/tests/Kyoo.Tests/Utility/UtilityTests.cs @@ -2,9 +2,10 @@ using System; using System.Linq.Expressions; using System.Reflection; using Kyoo.Abstractions.Models; +using Kyoo.Utils; using Xunit; -using Utils = Kyoo.Utility; +using KUtility = Kyoo.Utils.Utility; namespace Kyoo.Tests.Utility { @@ -16,12 +17,12 @@ namespace Kyoo.Tests.Utility Expression> member = x => x.ID; Expression> memberCast = x => x.ID; - Assert.False(Utils.IsPropertyExpression(null)); - Assert.True(Utils.IsPropertyExpression(member)); - Assert.True(Utils.IsPropertyExpression(memberCast)); + Assert.False(KUtility.IsPropertyExpression(null)); + Assert.True(KUtility.IsPropertyExpression(member)); + Assert.True(KUtility.IsPropertyExpression(memberCast)); Expression> call = x => x.GetID("test"); - Assert.False(Utils.IsPropertyExpression(call)); + Assert.False(KUtility.IsPropertyExpression(call)); } [Fact] @@ -30,15 +31,15 @@ namespace Kyoo.Tests.Utility Expression> member = x => x.ID; Expression> memberCast = x => x.ID; - Assert.Equal("ID", Utils.GetPropertyName(member)); - Assert.Equal("ID", Utils.GetPropertyName(memberCast)); - Assert.Throws(() => Utils.GetPropertyName(null)); + Assert.Equal("ID", KUtility.GetPropertyName(member)); + Assert.Equal("ID", KUtility.GetPropertyName(memberCast)); + Assert.Throws(() => KUtility.GetPropertyName(null)); } [Fact] public void GetMethodTest() { - MethodInfo method = Utils.GetMethod(typeof(UtilityTests), + MethodInfo method = KUtility.GetMethod(typeof(UtilityTests), BindingFlags.Instance | BindingFlags.Public, nameof(GetMethodTest), Array.Empty(), @@ -49,17 +50,17 @@ namespace Kyoo.Tests.Utility [Fact] public void GetMethodInvalidGenericsTest() { - Assert.Throws(() => Utils.GetMethod(typeof(UtilityTests), + Assert.Throws(() => KUtility.GetMethod(typeof(UtilityTests), BindingFlags.Instance | BindingFlags.Public, nameof(GetMethodTest), - new [] { typeof(Utils) }, + new [] { typeof(KUtility) }, Array.Empty())); } [Fact] public void GetMethodInvalidParamsTest() { - Assert.Throws(() => Utils.GetMethod(typeof(UtilityTests), + Assert.Throws(() => KUtility.GetMethod(typeof(UtilityTests), BindingFlags.Instance | BindingFlags.Public, nameof(GetMethodTest), Array.Empty(), @@ -69,7 +70,7 @@ namespace Kyoo.Tests.Utility [Fact] public void GetMethodTest2() { - MethodInfo method = Utils.GetMethod(typeof(Merger), + MethodInfo method = KUtility.GetMethod(typeof(Merger), BindingFlags.Static | BindingFlags.Public, nameof(Merger.MergeLists), new [] { typeof(string) },