Add title and path cleaning for qBittorrent torrent performer lookup in Stash
This commit is contained in:
@@ -228,10 +228,20 @@ def parse_stash_scene_data(scene, match_strategy='exact_path'):
|
||||
'matchStrategy': match_strategy
|
||||
}
|
||||
|
||||
def clean_torrent_title_for_stash(raw_title):
|
||||
t = re.sub(r'\.(mp4|mkv|avi|mov|wmv|ts|flv)$', '', raw_title or '', flags=re.IGNORECASE)
|
||||
t = re.sub(r'\[.*?\]|\(.*?\)', ' ', t)
|
||||
t = re.sub(r'\b(1080p|720p|2160p|4k|hd|hevc|x265|x264|rarbg|yify|vixen|brazzers|puretaboo|brattysis|team.skeet)\b', ' ', t, flags=re.IGNORECASE)
|
||||
t = re.sub(r'[\.\-_]+', ' ', t)
|
||||
return ' '.join(t.split())
|
||||
|
||||
def query_stash_single(file_name, file_path=None, item_type='smb', stash_url=None):
|
||||
basename = os.path.basename(file_path or file_name)
|
||||
raw_name = file_name or os.path.basename(file_path or '')
|
||||
basename = os.path.basename(file_path or file_name or '')
|
||||
|
||||
stash_paths = [
|
||||
f'/data/videodownloader/{basename}',
|
||||
f'/data/downloads/{basename}',
|
||||
f'/data/{basename}'
|
||||
]
|
||||
|
||||
@@ -244,8 +254,10 @@ def query_stash_single(file_name, file_path=None, item_type='smb', stash_url=Non
|
||||
id
|
||||
title
|
||||
performers {{
|
||||
id
|
||||
name
|
||||
gender
|
||||
image_path
|
||||
}}
|
||||
studio {{
|
||||
name
|
||||
@@ -264,11 +276,15 @@ def query_stash_single(file_name, file_path=None, item_type='smb', stash_url=Non
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 2. Basename search in Stash
|
||||
stem = os.path.splitext(basename)[0]
|
||||
# 2. Cleaned Title / Keyword search in Stash (especially effective for torrent names)
|
||||
cleaned_title = clean_torrent_title_for_stash(raw_name)
|
||||
search_queries = [cleaned_title[:40], os.path.splitext(basename)[0][:35]]
|
||||
for sq in search_queries:
|
||||
if not sq or len(sq) < 3:
|
||||
continue
|
||||
q = f'''
|
||||
{{
|
||||
findScenes(filter: {{q: {json.dumps(stem[:35])}, per_page: 3}}) {{
|
||||
findScenes(filter: {{q: {json.dumps(sq)}, per_page: 3}}) {{
|
||||
scenes {{
|
||||
id
|
||||
title
|
||||
@@ -276,8 +292,10 @@ def query_stash_single(file_name, file_path=None, item_type='smb', stash_url=Non
|
||||
basename
|
||||
}}
|
||||
performers {{
|
||||
id
|
||||
name
|
||||
gender
|
||||
image_path
|
||||
}}
|
||||
studio {{
|
||||
name
|
||||
@@ -292,7 +310,7 @@ def query_stash_single(file_name, file_path=None, item_type='smb', stash_url=Non
|
||||
if scenes:
|
||||
for s in scenes:
|
||||
if s.get('performers'):
|
||||
parsed = parse_stash_scene_data(s, 'fuzzy_match')
|
||||
parsed = parse_stash_scene_data(s, 'title_match')
|
||||
if parsed:
|
||||
return parsed
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user