mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
Improve producer matching - Add tissue service
Tissue service will sanitize the existign database of ingested torrents by matching existing titles with new banned word lists. Now with added kleenex
This commit is contained in:
14
src/tissue/Features/Wordlists/IWordCollections.cs
Normal file
14
src/tissue/Features/Wordlists/IWordCollections.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace Tissue.Features.Wordlists;
|
||||
|
||||
public interface IWordCollections
|
||||
{
|
||||
HashSet<string> AdultWords { get; }
|
||||
|
||||
HashSet<string> AdultCompoundPhrases { get; }
|
||||
|
||||
HashSet<string> Jav { get; }
|
||||
|
||||
HashSet<string> AdultStars { get; }
|
||||
|
||||
Task LoadAsync();
|
||||
}
|
||||
20
src/tissue/Features/Wordlists/PopulationService.cs
Normal file
20
src/tissue/Features/Wordlists/PopulationService.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace Tissue.Features.Wordlists;
|
||||
|
||||
public class PopulationService(IWordCollections wordCollections, ILogger<PopulationService> logger) : IHostedService
|
||||
{
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
logger.LogInformation("Loading word collections...");
|
||||
|
||||
await wordCollections.LoadAsync();
|
||||
|
||||
logger.LogInformation("Adult Words Count: {Count}", wordCollections.AdultWords.Count);
|
||||
logger.LogInformation("Adult Compound Phrases Count: {Count}", wordCollections.AdultCompoundPhrases.Count);
|
||||
logger.LogInformation("Jav Count: {Count}", wordCollections.Jav.Count);
|
||||
logger.LogInformation("Adult Stars Count: {Count}", wordCollections.AdultStars.Count);
|
||||
|
||||
logger.LogInformation("Word collections loaded.");
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
}
|
||||
12
src/tissue/Features/Wordlists/ServiceCollectionExtensions.cs
Normal file
12
src/tissue/Features/Wordlists/ServiceCollectionExtensions.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Tissue.Features.Wordlists;
|
||||
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection RegisterWordCollections(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IWordCollections, WordCollections>();
|
||||
services.AddHostedService<PopulationService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
55
src/tissue/Features/Wordlists/WordCollections.cs
Normal file
55
src/tissue/Features/Wordlists/WordCollections.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
namespace Tissue.Features.Wordlists;
|
||||
|
||||
public class WordCollections : IWordCollections
|
||||
{
|
||||
private const string AdultWordsFile = "adult-words.txt";
|
||||
private const string AdultCompoundPhrasesFile = "adult-compound-words.txt";
|
||||
private const string AdultStarsFile = "adult-stars.txt";
|
||||
private const string JavFile = "jav.txt";
|
||||
|
||||
public HashSet<string> AdultWords { get; private set; } = [];
|
||||
public HashSet<string> AdultCompoundPhrases { get; private set; } = [];
|
||||
|
||||
public HashSet<string> AdultStars { get; private set; } = [];
|
||||
|
||||
public HashSet<string> Jav { get; private set; } = [];
|
||||
|
||||
public async Task LoadAsync()
|
||||
{
|
||||
var loaderTasks = new List<Task>
|
||||
{
|
||||
LoadAdultWords(),
|
||||
LoadAdultCompounds(),
|
||||
LoadJav(),
|
||||
LoadAdultStars(),
|
||||
};
|
||||
|
||||
await Task.WhenAll(loaderTasks);
|
||||
}
|
||||
|
||||
private async Task LoadAdultCompounds()
|
||||
{
|
||||
var adultCompoundWords = await File.ReadAllLinesAsync(GetPath(AdultCompoundPhrasesFile));
|
||||
AdultCompoundPhrases = [..adultCompoundWords];
|
||||
}
|
||||
|
||||
private async Task LoadAdultWords()
|
||||
{
|
||||
var adultWords = await File.ReadAllLinesAsync(GetPath(AdultWordsFile));
|
||||
AdultWords = [..adultWords];
|
||||
}
|
||||
|
||||
private async Task LoadJav()
|
||||
{
|
||||
var jav = await File.ReadAllLinesAsync(GetPath(JavFile));
|
||||
Jav = [..jav];
|
||||
}
|
||||
|
||||
private async Task LoadAdultStars()
|
||||
{
|
||||
var adultStars = await File.ReadAllLinesAsync(GetPath(AdultStarsFile));
|
||||
AdultStars = [..adultStars];
|
||||
}
|
||||
|
||||
private static string GetPath(string fileName) => Path.Combine(AppContext.BaseDirectory, "Data", fileName);
|
||||
}
|
||||
Reference in New Issue
Block a user