Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f02547c0e3 | ||
|
|
61e93b5b24 | ||
|
|
f88daf4955 | ||
|
|
93c667422f |
@@ -47,7 +47,7 @@ Einige Beispiele findet ihr unter Features.
|
|||||||
| Korrekte Suche und Erkennung von Titel mit Umlauten | ✓ |
|
| Korrekte Suche und Erkennung von Titel mit Umlauten | ✓ |
|
||||||
| Anfragen-Caching für 5 Minuten zur Reduzierung der API-Zugriffe | ✓ |
|
| Anfragen-Caching für 5 Minuten zur Reduzierung der API-Zugriffe | ✓ |
|
||||||
| Usenet (newznab) Support |✓|
|
| Usenet (newznab) Support |✓|
|
||||||
| Torrent Support | Vorerst nicht geplant |
|
| Torrent (torznab) Support |✓|
|
||||||
| Radarr Support | Geplant |
|
| Radarr Support | Geplant |
|
||||||
| Prowlarr Unterstützung für "DE" SceneNZBs Kategorien | Geplant |
|
| Prowlarr Unterstützung für "DE" SceneNZBs Kategorien | Geplant |
|
||||||
| Unterstützung weiterer Sprachen neben Deutsch | Geplant |
|
| Unterstützung weiterer Sprachen neben Deutsch | Geplant |
|
||||||
|
|||||||
@@ -96,30 +96,51 @@ namespace UmlautAdaptarr.Services
|
|||||||
// Use the first few characters of the normalized title for cache prefix search
|
// Use the first few characters of the normalized title for cache prefix search
|
||||||
var cacheSearchPrefix = normalizedTitle[..Math.Min(VARIATION_LOOKUP_CACHE_LENGTH, normalizedTitle.Length)];
|
var cacheSearchPrefix = normalizedTitle[..Math.Min(VARIATION_LOOKUP_CACHE_LENGTH, normalizedTitle.Length)];
|
||||||
|
|
||||||
|
SearchItem? bestSearchItemMatch = null;
|
||||||
|
var bestVariationMatchLength = 0;
|
||||||
|
HashSet<string> checkedSearchItems = [];
|
||||||
|
|
||||||
if (VariationIndex.TryGetValue(cacheSearchPrefix, out var cacheKeys))
|
if (VariationIndex.TryGetValue(cacheSearchPrefix, out var cacheKeys))
|
||||||
{
|
{
|
||||||
foreach (var cacheKey in cacheKeys)
|
foreach (var cacheKey in cacheKeys)
|
||||||
{
|
{
|
||||||
if (cache.TryGetValue(cacheKey, out SearchItem? item))
|
if (cache.TryGetValue(cacheKey, out SearchItem? item))
|
||||||
{
|
{
|
||||||
if (item?.MediaType != mediaType)
|
if (item == null || item.MediaType != mediaType)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var searchItemIdentifier = $"{item.MediaType}_{item.ExternalId}";
|
||||||
|
|
||||||
|
if (checkedSearchItems.Contains(searchItemIdentifier))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
checkedSearchItems.Add(searchItemIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
// After finding a potential item, compare normalizedTitle with each German title variation
|
// After finding a potential item, compare normalizedTitle with each German title variation
|
||||||
foreach (var variation in item?.TitleMatchVariations ?? [])
|
foreach (var variation in item.TitleMatchVariations ?? [])
|
||||||
{
|
{
|
||||||
var normalizedVariation = variation.RemoveAccentButKeepGermanUmlauts().ToLower();
|
var normalizedVariation = variation.RemoveAccentButKeepGermanUmlauts().ToLower();
|
||||||
if (normalizedTitle.StartsWith(variation, StringComparison.OrdinalIgnoreCase))
|
if (normalizedTitle.StartsWith(variation, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return item;
|
// If we find a variation match that is "longer" then most likely that one is correct and the earlier match was wrong (if it was from another searchItem)
|
||||||
|
if (variation.Length > bestVariationMatchLength)
|
||||||
|
{
|
||||||
|
bestSearchItemMatch = item;
|
||||||
|
bestVariationMatchLength = variation.Length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return bestSearchItemMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SearchItem? GetSearchItemByExternalId(string mediaType, string externalId)
|
public SearchItem? GetSearchItemByExternalId(string mediaType, string externalId)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ namespace UmlautAdaptarr.Services
|
|||||||
private readonly ILogger<ProxyService> _logger;
|
private readonly ILogger<ProxyService> _logger;
|
||||||
private readonly IMemoryCache _cache;
|
private readonly IMemoryCache _cache;
|
||||||
private static readonly ConcurrentDictionary<string, DateTimeOffset> _lastRequestTimes = new();
|
private static readonly ConcurrentDictionary<string, DateTimeOffset> _lastRequestTimes = new();
|
||||||
|
private static readonly TimeSpan MINIMUM_DELAY_FOR_SAME_HOST = new(0, 0, 0, 1);
|
||||||
|
|
||||||
public ProxyService(IHttpClientFactory clientFactory, IConfiguration configuration, ILogger<ProxyService> logger, IMemoryCache cache)
|
public ProxyService(IHttpClientFactory clientFactory, IConfiguration configuration, ILogger<ProxyService> logger, IMemoryCache cache)
|
||||||
{
|
{
|
||||||
@@ -26,9 +27,9 @@ namespace UmlautAdaptarr.Services
|
|||||||
if (_lastRequestTimes.TryGetValue(host, out var lastRequestTime))
|
if (_lastRequestTimes.TryGetValue(host, out var lastRequestTime))
|
||||||
{
|
{
|
||||||
var timeSinceLastRequest = DateTimeOffset.Now - lastRequestTime;
|
var timeSinceLastRequest = DateTimeOffset.Now - lastRequestTime;
|
||||||
if (timeSinceLastRequest < TimeSpan.FromMilliseconds(1500))
|
if (timeSinceLastRequest < MINIMUM_DELAY_FOR_SAME_HOST)
|
||||||
{
|
{
|
||||||
await Task.Delay(TimeSpan.FromMilliseconds(1500) - timeSinceLastRequest);
|
await Task.Delay(MINIMUM_DELAY_FOR_SAME_HOST - timeSinceLastRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_lastRequestTimes[host] = DateTimeOffset.Now;
|
_lastRequestTimes[host] = DateTimeOffset.Now;
|
||||||
|
|||||||
Reference in New Issue
Block a user