diff --git a/AUTHORS.md b/AUTHORS.md index ad32290a..b97c1dee 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -1,4 +1,4 @@ # Authors Ordered by the date of the first commit. -* Zoe Roux ([@AnonymusRaccoon](http://github.com/AnonymusRaccoon)) +* Zoe Roux ([@zoriya](http://github.com/zoriya)) diff --git a/back/src/Kyoo.Core/CoreModule.cs b/back/src/Kyoo.Core/CoreModule.cs index a3ec6761..ee512dce 100644 --- a/back/src/Kyoo.Core/CoreModule.cs +++ b/back/src/Kyoo.Core/CoreModule.cs @@ -84,6 +84,7 @@ namespace Kyoo.Core builder.RegisterTask(); builder.RegisterTask(); builder.RegisterTask(); + builder.RegisterTask(); static bool DatabaseIsPresent(IComponentRegistryBuilder x) => x.IsRegistered(new TypedService(typeof(DatabaseContext))); diff --git a/back/src/Kyoo.Core/Tasks/LibraryCreator.cs b/back/src/Kyoo.Core/Tasks/LibraryCreator.cs new file mode 100644 index 00000000..2dcd6250 --- /dev/null +++ b/back/src/Kyoo.Core/Tasks/LibraryCreator.cs @@ -0,0 +1,97 @@ +// Kyoo - A portable and vast media library solution. +// Copyright (c) Kyoo. +// +// See AUTHORS.md and LICENSE file in the project root for full license information. +// +// Kyoo is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// any later version. +// +// Kyoo is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Kyoo. If not, see . + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Kyoo.Abstractions.Controllers; +using Kyoo.Abstractions.Models; +using Kyoo.Abstractions.Models.Attributes; +using Kyoo.Utils; +using Microsoft.Extensions.Logging; + +namespace Kyoo.Core.Tasks +{ + /// + /// A task to add new video files. + /// + [TaskMetadata("library-creator", "Create libraries", "Create libraries on the library root folder.", + RunOnStartup = true, Priority = 500)] + public class LibraryCreator : ITask + { + /// + /// The library manager used to get libraries and providers to use. + /// + private readonly ILibraryManager _libraryManager; + + /// + /// A task manager used to create sub tasks for each episode to add to the database. + /// + private readonly ITaskManager _taskManager; + + /// + /// The logger used to inform the current status to the console. + /// + private readonly ILogger _logger; + + /// + /// Create a new . + /// + /// The library manager to retrieve existing episodes/library/tracks + /// The task manager used to start . + /// The logger used print messages. + public LibraryCreator(ILibraryManager libraryManager, + ITaskManager taskManager, + ILogger logger) + { + _libraryManager = libraryManager; + _taskManager = taskManager; + _logger = logger; + } + + /// + public TaskParameters GetParameters() + { + return new(); + } + + /// + public async Task Run(TaskParameters arguments, IProgress progress, CancellationToken cancellationToken) + { + ICollection providers = await _libraryManager.GetAll(); + ICollection existings = (await _libraryManager.GetAll()).SelectMany(x => x.Paths).ToArray(); + IEnumerable newLibraries = Directory.GetDirectories(Environment.GetEnvironmentVariable("LIBRARY_ROOT") ?? "/video") + .Where(x => !existings.Contains(x)) + .Select(x => new Library + { + Slug = Utility.ToSlug(Path.GetFileName(x)), + Name = Path.GetFileName(x), + Paths = new string[] { x }, + Providers = providers, + }); + + foreach (Library library in newLibraries) + { + await _libraryManager.Create(library); + } + } + } +} diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index f63740f3..ef30fa2f 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -2,7 +2,7 @@ version: "3.8" services: back: - build: + build: context: ./back dockerfile: Dockerfile.dev ports: @@ -16,6 +16,7 @@ services: - DATABASE__CONFIGURATIONS__POSTGRES__PASSWORD=${POSTGRES_PASSWORD} - TVDB__APIKEY=${TVDB__APIKEY} - THEMOVIEDB__APIKEY=${THEMOVIEDB__APIKEY} + - LIBRARY_ROOT=/video depends_on: - postgres volumes: @@ -24,7 +25,7 @@ services: - kyoo:/var/lib/kyoo - ./video:/video front: - build: + build: context: ./front dockerfile: Dockerfile.dev volumes: @@ -67,4 +68,3 @@ services: volumes: kyoo: db: - diff --git a/docker-compose.yml b/docker-compose.yml index aa80901c..566d0e27 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,7 @@ services: - DATABASE__CONFIGURATIONS__POSTGRES__DATABASE=${POSTGRES_DB} - TVDB__APIKEY=${TVDB__APIKEY} - THEMOVIEDB__APIKEY=${THEMOVIEDB__APIKEY} + - LIBRARY_ROOT=/video depends_on: - postgres volumes: @@ -52,4 +53,3 @@ services: volumes: kyoo: db: -