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
|
'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):
|
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 = [
|
stash_paths = [
|
||||||
f'/data/videodownloader/{basename}',
|
f'/data/videodownloader/{basename}',
|
||||||
|
f'/data/downloads/{basename}',
|
||||||
f'/data/{basename}'
|
f'/data/{basename}'
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -244,8 +254,10 @@ def query_stash_single(file_name, file_path=None, item_type='smb', stash_url=Non
|
|||||||
id
|
id
|
||||||
title
|
title
|
||||||
performers {{
|
performers {{
|
||||||
|
id
|
||||||
name
|
name
|
||||||
gender
|
gender
|
||||||
|
image_path
|
||||||
}}
|
}}
|
||||||
studio {{
|
studio {{
|
||||||
name
|
name
|
||||||
@@ -264,39 +276,45 @@ def query_stash_single(file_name, file_path=None, item_type='smb', stash_url=Non
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# 2. Basename search in Stash
|
# 2. Cleaned Title / Keyword search in Stash (especially effective for torrent names)
|
||||||
stem = os.path.splitext(basename)[0]
|
cleaned_title = clean_torrent_title_for_stash(raw_name)
|
||||||
q = f'''
|
search_queries = [cleaned_title[:40], os.path.splitext(basename)[0][:35]]
|
||||||
{{
|
for sq in search_queries:
|
||||||
findScenes(filter: {{q: {json.dumps(stem[:35])}, per_page: 3}}) {{
|
if not sq or len(sq) < 3:
|
||||||
scenes {{
|
continue
|
||||||
id
|
q = f'''
|
||||||
title
|
{{
|
||||||
files {{
|
findScenes(filter: {{q: {json.dumps(sq)}, per_page: 3}}) {{
|
||||||
basename
|
scenes {{
|
||||||
}}
|
id
|
||||||
performers {{
|
title
|
||||||
name
|
files {{
|
||||||
gender
|
basename
|
||||||
}}
|
}}
|
||||||
studio {{
|
performers {{
|
||||||
name
|
id
|
||||||
|
name
|
||||||
|
gender
|
||||||
|
image_path
|
||||||
|
}}
|
||||||
|
studio {{
|
||||||
|
name
|
||||||
|
}}
|
||||||
|
}}
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
}}
|
'''
|
||||||
}}
|
try:
|
||||||
'''
|
res = execute_stash_graphql(q, stash_url, timeout=3)
|
||||||
try:
|
scenes = res.get('data', {}).get('findScenes', {}).get('scenes', [])
|
||||||
res = execute_stash_graphql(q, stash_url, timeout=3)
|
if scenes:
|
||||||
scenes = res.get('data', {}).get('findScenes', {}).get('scenes', [])
|
for s in scenes:
|
||||||
if scenes:
|
if s.get('performers'):
|
||||||
for s in scenes:
|
parsed = parse_stash_scene_data(s, 'title_match')
|
||||||
if s.get('performers'):
|
if parsed:
|
||||||
parsed = parse_stash_scene_data(s, 'fuzzy_match')
|
return parsed
|
||||||
if parsed:
|
except Exception:
|
||||||
return parsed
|
pass
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user