mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Registering shows before episodes to prevent duplicates
This commit is contained in:
parent
33d9c5d9b4
commit
80389790dd
@ -31,7 +31,7 @@ namespace Kyoo.Controllers
|
|||||||
public async Task<IEnumerable<string>> GetPossibleParameters()
|
public async Task<IEnumerable<string>> GetPossibleParameters()
|
||||||
{
|
{
|
||||||
using IServiceScope serviceScope = _serviceProvider.CreateScope();
|
using IServiceScope serviceScope = _serviceProvider.CreateScope();
|
||||||
ILibraryManager libraryManager = serviceScope.ServiceProvider.GetService<ILibraryManager>();
|
await using ILibraryManager libraryManager = serviceScope.ServiceProvider.GetService<ILibraryManager>();
|
||||||
return (await libraryManager.GetLibraries()).Select(x => x.Slug);
|
return (await libraryManager.GetLibraries()).Select(x => x.Slug);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,10 +82,10 @@ namespace Kyoo.Controllers
|
|||||||
private Task Scan(Library library, IEnumerable<Episode> episodes, CancellationToken cancellationToken)
|
private Task Scan(Library library, IEnumerable<Episode> episodes, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Scanning library {library.Name} at {string.Join(", ", library.Paths)}.");
|
Console.WriteLine($"Scanning library {library.Name} at {string.Join(", ", library.Paths)}.");
|
||||||
return Task.WhenAll(library.Paths.Select(path =>
|
return Task.WhenAll(library.Paths.Select(async path =>
|
||||||
{
|
{
|
||||||
if (cancellationToken.IsCancellationRequested)
|
if (cancellationToken.IsCancellationRequested)
|
||||||
return Task.CompletedTask;
|
return;
|
||||||
|
|
||||||
string[] files;
|
string[] files;
|
||||||
try
|
try
|
||||||
@ -94,35 +94,39 @@ namespace Kyoo.Controllers
|
|||||||
}
|
}
|
||||||
catch (DirectoryNotFoundException)
|
catch (DirectoryNotFoundException)
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine($"The library's directory {path} could not be found (library slug: {library.Slug})");
|
await Console.Error.WriteLineAsync($"The library's directory {path} could not be found (library slug: {library.Slug})");
|
||||||
return Task.CompletedTask;
|
return;
|
||||||
}
|
}
|
||||||
catch (PathTooLongException)
|
catch (PathTooLongException)
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine($"The library's directory {path} is too long for this system. (library slug: {library.Slug})");
|
await Console.Error.WriteLineAsync($"The library's directory {path} is too long for this system. (library slug: {library.Slug})");
|
||||||
return Task.CompletedTask;
|
return;
|
||||||
}
|
}
|
||||||
catch (ArgumentException)
|
catch (ArgumentException)
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine($"The library's directory {path} is invalid. (library slug: {library.Slug})");
|
await Console.Error.WriteLineAsync($"The library's directory {path} is invalid. (library slug: {library.Slug})");
|
||||||
return Task.CompletedTask;
|
return;
|
||||||
}
|
}
|
||||||
catch (UnauthorizedAccessException)
|
catch (UnauthorizedAccessException)
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine($"Permission denied: can't access library's directory at {path}. (library slug: {library.Slug})");
|
await Console.Error.WriteLineAsync($"Permission denied: can't access library's directory at {path}. (library slug: {library.Slug})");
|
||||||
return Task.CompletedTask;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Should register shows first to prevent all tasks of a same show to register it 150+ times.
|
List<IGrouping<string, string>> shows = files
|
||||||
|
.Where(x => IsVideo(x) && episodes.All(y => y.Path != x))
|
||||||
|
.GroupBy(Path.GetDirectoryName)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
return Task.WhenAll(files.Select(file =>
|
await Task.WhenAll(shows
|
||||||
{
|
.Select(x => x.First())
|
||||||
if (!IsVideo(file) || episodes.Any(x => x.Path == file))
|
.Select(x => RegisterFile(x, x.Substring(path.Length), library, cancellationToken))
|
||||||
return Task.CompletedTask;
|
.ToArray());
|
||||||
string relativePath = file.Substring(path.Length);
|
|
||||||
return RegisterFile(file, relativePath, library, cancellationToken);
|
|
||||||
}).ToArray());
|
|
||||||
|
|
||||||
|
await Task.WhenAll(shows
|
||||||
|
.SelectMany(x => x.Skip(1))
|
||||||
|
.Select(x => RegisterFile(x, x.Substring(path.Length), library, cancellationToken))
|
||||||
|
.ToArray());
|
||||||
}).ToArray());
|
}).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,12 +8,13 @@
|
|||||||
"Default": "Warning",
|
"Default": "Warning",
|
||||||
"Microsoft": "Warning",
|
"Microsoft": "Warning",
|
||||||
"Microsoft.Hosting.Lifetime": "Information",
|
"Microsoft.Hosting.Lifetime": "Information",
|
||||||
"Microsoft.EntityFrameworkCore.DbUpdateException": "None"
|
"Microsoft.EntityFrameworkCore.DbUpdateException": "None",
|
||||||
|
"Microsoft.EntityFrameworkCore.Update": "None"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"Database": "Server=127.0.0.1; Port=5432; Database=kyooDB; User Id=kyoo; Password=kyooPassword; Pooling=true;"
|
"Database": "Server=127.0.0.1; Port=5432; Database=kyooDB; User Id=kyoo; Password=kyooPassword; Pooling=true; MaxPoolSize=60;"
|
||||||
},
|
},
|
||||||
|
|
||||||
"scheduledTasks": {
|
"scheduledTasks": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user