8 Commits

Author SHA1 Message Date
pcjones
f02547c0e3 Merge branch 'master' of https://github.com/PCJones/UmlautAdaptarr 2024-03-15 18:25:08 +01:00
pcjones
61e93b5b24 Enhance searchitem matching 2024-03-15 18:24:39 +01:00
pcjones
f88daf4955 Lower minimum delay between requests to 1 second 2024-03-08 10:00:29 +01:00
Jonas F
93c667422f Update README.md 2024-03-06 20:03:16 +01:00
Jonas F
e1978d869c Merge pull request #12 from PCJones/develop
v0.4
2024-03-06 20:00:05 +01:00
pcjones
cfdfa89009 Merge branch 'develop' 2024-03-06 19:52:19 +01:00
pcjones
9bee42d7dd Detect media Type by category ID 2024-03-06 19:52:07 +01:00
pcjones
797ff2b97e Fix searchItem title not being logged 2024-03-01 12:53:47 +01:00
5 changed files with 36 additions and 14 deletions

View File

@@ -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 |

View File

@@ -98,7 +98,7 @@ namespace UmlautAdaptarr.Providers
mediaType: _mediaType mediaType: _mediaType
); );
logger.LogInformation($"Successfully fetched show {searchItem} from Sonarr."); logger.LogInformation($"Successfully fetched show {searchItem.Title} from Sonarr.");
return searchItem; return searchItem;
} }
} }
@@ -156,7 +156,7 @@ namespace UmlautAdaptarr.Providers
mediaType: _mediaType mediaType: _mediaType
); );
logger.LogInformation($"Successfully fetched show {searchItem} from Sonarr."); logger.LogInformation($"Successfully fetched show {searchItem.Title} from Sonarr.");
return searchItem; return searchItem;
} }
catch (Exception ex) catch (Exception ex)

View File

@@ -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)

View File

@@ -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;

View File

@@ -262,23 +262,23 @@ namespace UmlautAdaptarr.Services
return null; return null;
} }
if (category.StartsWith("EBook", StringComparison.OrdinalIgnoreCase) || category.StartsWith("Book", StringComparison.OrdinalIgnoreCase)) if (category == "7000" || category.StartsWith("EBook", StringComparison.OrdinalIgnoreCase) || category.StartsWith("Book", StringComparison.OrdinalIgnoreCase))
{ {
return "book"; return "book";
} }
else if (category.StartsWith("Movies", StringComparison.OrdinalIgnoreCase)) else if (category == "2000" || category.StartsWith("Movies", StringComparison.OrdinalIgnoreCase))
{ {
return "movies"; return "movies";
} }
else if (category.StartsWith("TV", StringComparison.OrdinalIgnoreCase)) else if (category == "5000" || category.StartsWith("TV", StringComparison.OrdinalIgnoreCase))
{ {
return "tv"; return "tv";
} }
else if (category.Contains("Audiobook", StringComparison.OrdinalIgnoreCase)) else if (category == "3030" || category.Contains("Audiobook", StringComparison.OrdinalIgnoreCase))
{ {
return "book"; return "book";
} }
else if (category.StartsWith("Audio")) else if (category == "3000" || category.StartsWith("Audio"))
{ {
return "audio"; return "audio";
} }