diff --git a/Kyoo.sln b/Kyoo.sln index 39241918..73bcb2bd 100644 --- a/Kyoo.sln +++ b/Kyoo.sln @@ -37,7 +37,7 @@ Global {E5EFA4B2-F09D-4C4F-83DD-A436CD60BB77}.Debug|x64.Build.0 = Debug|x64 {E5EFA4B2-F09D-4C4F-83DD-A436CD60BB77}.Debug|x86.ActiveCfg = Debug|Win32 {E5EFA4B2-F09D-4C4F-83DD-A436CD60BB77}.Debug|x86.Build.0 = Debug|Win32 - {E5EFA4B2-F09D-4C4F-83DD-A436CD60BB77}.Release|Any CPU.ActiveCfg = Release|Win32 + {E5EFA4B2-F09D-4C4F-83DD-A436CD60BB77}.Release|Any CPU.ActiveCfg = Release|x64 {E5EFA4B2-F09D-4C4F-83DD-A436CD60BB77}.Release|x64.ActiveCfg = Release|x64 {E5EFA4B2-F09D-4C4F-83DD-A436CD60BB77}.Release|x64.Build.0 = Release|x64 {E5EFA4B2-F09D-4C4F-83DD-A436CD60BB77}.Release|x86.ActiveCfg = Release|Win32 diff --git a/Kyoo/ClientApp/angular.json b/Kyoo/ClientApp/angular.json index 0f2046fc..806ebe16 100644 --- a/Kyoo/ClientApp/angular.json +++ b/Kyoo/ClientApp/angular.json @@ -17,7 +17,7 @@ "build": { "builder": "@angular-devkit/build-angular:browser", "options": { - "outputPath": "dist/Kyoo", + "outputPath": "dist", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", diff --git a/Kyoo/Controllers/AdminController.cs b/Kyoo/Controllers/AdminController.cs new file mode 100644 index 00000000..a3f5b8c0 --- /dev/null +++ b/Kyoo/Controllers/AdminController.cs @@ -0,0 +1,29 @@ +using Kyoo.InternalAPI; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Kyoo.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class AdminController : ControllerBase + { + private readonly ICrawler crawler; + + public AdminController(ICrawler crawler) + { + this.crawler = crawler; + } + + [HttpGet("scan/{watch}")] + public IActionResult ScanLibrary(bool watch) + { + crawler.Start(watch); + + return Ok("Scanning"); + } + } +} diff --git a/Kyoo/Controllers/ThumbnailController.cs b/Kyoo/Controllers/ThumbnailController.cs index e250a1f7..60d1099c 100644 --- a/Kyoo/Controllers/ThumbnailController.cs +++ b/Kyoo/Controllers/ThumbnailController.cs @@ -79,7 +79,8 @@ namespace Kyoo.Controllers if (path == null) return NotFound(); - string thumb = Path.ChangeExtension(path, "jpg"); + //string thumb = Path.ChangeExtension(path, "jpg"); + string thumb = path.Replace(Path.GetExtension(path), "-thumb.jpg"); if (System.IO.File.Exists(thumb)) return new PhysicalFileResult(thumb, "image/jpg"); diff --git a/Kyoo/InternalAPI/Crawler/Crawler.cs b/Kyoo/InternalAPI/Crawler/Crawler.cs index f2339fe6..ee429c6d 100644 --- a/Kyoo/InternalAPI/Crawler/Crawler.cs +++ b/Kyoo/InternalAPI/Crawler/Crawler.cs @@ -11,8 +11,10 @@ using System.Threading.Tasks; namespace Kyoo.InternalAPI { - public class Crawler : IHostedService + public class Crawler : ICrawler { + private readonly CancellationTokenSource cancellation; + private readonly IConfiguration config; private readonly ILibraryManager libraryManager; private readonly IMetadataProvider metadataProvider; @@ -24,31 +26,43 @@ namespace Kyoo.InternalAPI this.libraryManager = libraryManager; this.metadataProvider = metadataProvider; this.transcoder = transcoder; + + cancellation = new CancellationTokenSource(); } - public Task StartAsync(CancellationToken cancellationToken) + public Task Start(bool watch) + { + return StartAsync(watch, cancellation.Token); + } + + private Task StartAsync(bool watch, CancellationToken cancellationToken) { Debug.WriteLine("&Crawler started"); string[] paths = config.GetSection("libraryPaths").Get(); foreach (string path in paths) { - Scan(path); - Watch(path, cancellationToken); + Scan(path, cancellationToken); + + if(watch) + Watch(path, cancellationToken); } - while (!cancellationToken.IsCancellationRequested) ; + while (!cancellationToken.IsCancellationRequested); Debug.WriteLine("&Crawler stopped"); return null; } - public async void Scan(string folderPath) + public async void Scan(string folderPath, CancellationToken cancellationToken) { string[] files = Directory.GetFiles(folderPath, "*", SearchOption.AllDirectories); foreach (string file in files) { + if (cancellationToken.IsCancellationRequested) + return; + if (IsVideo(file)) await TryRegisterEpisode(file); } @@ -75,7 +89,7 @@ namespace Kyoo.InternalAPI watcher.EnableRaisingEvents = true; - while (!cancellationToken.IsCancellationRequested) ; + while (!cancellationToken.IsCancellationRequested); } } @@ -217,8 +231,9 @@ namespace Kyoo.InternalAPI } - public Task StopAsync(CancellationToken cancellationToken) + public Task StopAsync() { + cancellation.Cancel(); return null; } } diff --git a/Kyoo/InternalAPI/Crawler/ICrawler.cs b/Kyoo/InternalAPI/Crawler/ICrawler.cs new file mode 100644 index 00000000..30514f7f --- /dev/null +++ b/Kyoo/InternalAPI/Crawler/ICrawler.cs @@ -0,0 +1,12 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace Kyoo.InternalAPI +{ + public interface ICrawler + { + Task Start(bool watch); + + Task StopAsync(); + } +} diff --git a/Kyoo/InternalAPI/LibraryManager/LibraryManager.cs b/Kyoo/InternalAPI/LibraryManager/LibraryManager.cs index 93c30cb9..4c195731 100644 --- a/Kyoo/InternalAPI/LibraryManager/LibraryManager.cs +++ b/Kyoo/InternalAPI/LibraryManager/LibraryManager.cs @@ -661,13 +661,16 @@ namespace Kyoo.InternalAPI cmd.CommandText = "SELECT LAST_INSERT_ROWID()"; long showID = (long)cmd.ExecuteScalar(); - cmd.CommandText = "INSERT INTO genresLinks (genreID, showID) VALUES($genreID, $showID);"; - foreach (Genre genre in show.Genres) + if (show.Genres != null) { - long genreID = GetOrCreateGenre(genre); - cmd.Parameters.AddWithValue("$genreID", genreID); - cmd.Parameters.AddWithValue("$showID", showID); - cmd.ExecuteNonQuery(); + cmd.CommandText = "INSERT INTO genresLinks (genreID, showID) VALUES($genreID, $showID);"; + foreach (Genre genre in show.Genres) + { + long genreID = GetOrCreateGenre(genre); + cmd.Parameters.AddWithValue("$genreID", genreID); + cmd.Parameters.AddWithValue("$showID", showID); + cmd.ExecuteNonQuery(); + } } if(show.studio != null) diff --git a/Kyoo/InternalAPI/MetadataProvider/ProviderHelper.cs b/Kyoo/InternalAPI/MetadataProvider/ProviderHelper.cs index 1dc538b8..48f47f38 100644 --- a/Kyoo/InternalAPI/MetadataProvider/ProviderHelper.cs +++ b/Kyoo/InternalAPI/MetadataProvider/ProviderHelper.cs @@ -11,7 +11,7 @@ namespace Kyoo.InternalAPI.MetadataProvider public string GetID(string externalIDs) { - if (externalIDs.Contains(Provider)) + if (externalIDs?.Contains(Provider) == true) { int startIndex = externalIDs.IndexOf(Provider) + Provider.Length + 1; //The + 1 is for the '=' return externalIDs.Substring(startIndex, externalIDs.IndexOf('|', startIndex) - startIndex); diff --git a/Kyoo/InternalAPI/MetadataProvider/ProviderManager.cs b/Kyoo/InternalAPI/MetadataProvider/ProviderManager.cs index 1a73ab64..1cfff6dd 100644 --- a/Kyoo/InternalAPI/MetadataProvider/ProviderManager.cs +++ b/Kyoo/InternalAPI/MetadataProvider/ProviderManager.cs @@ -74,7 +74,7 @@ namespace Kyoo.InternalAPI public Episode Merge(IEnumerable episodes) { - return episodes.FirstOrDefault(); + return episodes.FirstOrDefault(); //Should do something if the return is null; } //For all the following methods, it should use all providers and merge the data. diff --git a/Kyoo/Kyoo.csproj b/Kyoo/Kyoo.csproj index 5479cc8b..2c8b180e 100644 --- a/Kyoo/Kyoo.csproj +++ b/Kyoo/Kyoo.csproj @@ -13,6 +13,7 @@ SDG Anonymus-Raccoon https://github.com/AnonymusRaccoon/Kyoo + Kyoo.Program diff --git a/Kyoo/Program.cs b/Kyoo/Program.cs index df75a2f9..b9c0869b 100644 --- a/Kyoo/Program.cs +++ b/Kyoo/Program.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using System.IO; namespace Kyoo diff --git a/Kyoo/Startup.cs b/Kyoo/Startup.cs index c579657f..9b5ae401 100644 --- a/Kyoo/Startup.cs +++ b/Kyoo/Startup.cs @@ -4,7 +4,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SpaServices.AngularCli; -using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System.Web.Http; @@ -36,7 +35,7 @@ namespace Kyoo services.AddSingleton(); //Services used to get informations about files and register them - services.AddHostedService(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); } @@ -54,7 +53,7 @@ namespace Kyoo app.UseHsts(); } - app.UseHttpsRedirection(); + //app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); diff --git a/Kyoo/Transcoder/Kyoo.Transcoder.dll b/Kyoo/Transcoder/Kyoo.Transcoder.dll index e29ec11e..8528a0a1 100644 Binary files a/Kyoo/Transcoder/Kyoo.Transcoder.dll and b/Kyoo/Transcoder/Kyoo.Transcoder.dll differ diff --git a/Kyoo/appsettings.json b/Kyoo/appsettings.json index def9159a..8109e4f0 100644 --- a/Kyoo/appsettings.json +++ b/Kyoo/appsettings.json @@ -1,4 +1,5 @@ { + "https_port": 44300, "Logging": { "LogLevel": { "Default": "Warning"