Match Jellyfin punctuation variants using provider metadata and strict fallback
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import re
|
||||
from typing import Any, Dict, Optional
|
||||
import httpx
|
||||
import time
|
||||
@@ -192,15 +193,27 @@ class JellyfinClient(ApiClient):
|
||||
"SearchTerm": term,
|
||||
"IncludeItemTypes": ",".join(item_types or []),
|
||||
"Recursive": "true",
|
||||
"Fields": "Path,MediaSources",
|
||||
"Fields": "Path,MediaSources,ProviderIds,OriginalTitle,SortName",
|
||||
"Limit": limit,
|
||||
}
|
||||
headers = self._emby_headers()
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10.0) as client:
|
||||
response = await client.get(url, headers=headers, params=params)
|
||||
response.raise_for_status()
|
||||
result = response.json()
|
||||
normalized = ' '.join(re.sub(r"[^\w\s]", ' ', term, flags=re.UNICODE).split())
|
||||
terms = list(dict.fromkeys([term, normalized]))
|
||||
if normalized != term and normalized.split():
|
||||
terms.append(max(normalized.split(), key=len))
|
||||
items = {}
|
||||
for search_term in dict.fromkeys(terms):
|
||||
if not search_term:
|
||||
continue
|
||||
response = await client.get(url, headers=headers, params={**params, "SearchTerm": search_term})
|
||||
response.raise_for_status()
|
||||
payload = response.json()
|
||||
for item in payload.get('Items', []):
|
||||
if isinstance(item, dict) and item.get('Id'):
|
||||
items[item['Id']] = item
|
||||
result = {'Items': list(items.values()), 'TotalRecordCount': len(items)}
|
||||
duration_ms = round((time.perf_counter() - started_at) * 1000, 2)
|
||||
finish_remote_call(
|
||||
operation_event_id,
|
||||
|
||||
Reference in New Issue
Block a user