Skip to content

Commit b14e196

Browse files
authored
Merge pull request #445 from skier233/fixtimestampbug
[AI Tagger] Fix zip issues and timestamp issues
2 parents b02d5c2 + 628d0e7 commit b14e196

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

plugins/AITagger/ai_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def process_images_async(image_paths, threshold=config.IMAGE_THRESHOLD, re
3838
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=config.SERVER_TIMEOUT)) as session:
3939
return await post_api_async(session, 'process_images/', {"paths": image_paths, "threshold": threshold, "return_confidence": return_confidence})
4040

41-
async def process_video_async(video_path, frame_interval=config.FRAME_INTERVAL,threshold=config.AI_VIDEO_THRESHOLD, return_confidence=True ,vr_video=False):
41+
async def process_video_async(video_path, vr_video=False, frame_interval=config.FRAME_INTERVAL,threshold=config.AI_VIDEO_THRESHOLD, return_confidence=True):
4242
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=config.SERVER_TIMEOUT)) as session:
4343
return await post_api_async(session, 'process_video/', {"path": video_path, "frame_interval": frame_interval, "threshold": threshold, "return_confidence": return_confidence, "vr_video": vr_video})
4444

plugins/AITagger/ai_tagger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ async def __tag_scene(scene):
246246
vr_video = media_handler.is_vr_scene(scene.get('tags'))
247247
if vr_video:
248248
log.info(f"Processing VR video {scenePath}")
249-
server_result = await ai_server.process_video_async(mutated_path, vr_video)
249+
server_result = await ai_server.process_video_async(video_path=mutated_path, vr_video=vr_video)
250250
if server_result is None:
251251
log.error("Server returned no results")
252252
media_handler.add_error_scene(sceneId)

plugins/AITagger/ai_tagger.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: AI Tagger
22
description: Tag videos and Images with Locally hosted AI using Skier's Patreon AI models
3-
version: 1.7
3+
version: 1.8
44
url: https://github.com/stashapp/CommunityScripts/tree/main/plugins/AITagger
55
exec:
66
- python

plugins/AITagger/media_handler.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def initialize(connection):
4343
# ----------------- Tag Methods -----------------
4444

4545

46-
tag_categories = ["actions", "bodyparts"]
46+
tag_categories = ["actions", "bodyparts", "bdsm", "clothing", "describingperson", "environment", "describingbody", "describingimage", "describingscene", "sextoys"]
4747

4848
def get_all_tags_from_server_result(result):
4949
alltags = []
@@ -91,7 +91,11 @@ def remove_tagme_tags_from_images(image_ids):
9191
def add_tags_to_image(image_id, tag_ids):
9292
stash.update_images({"ids": [image_id], "tag_ids": {"ids": tag_ids, "mode": "ADD"}})
9393

94+
worker_counter = 0
95+
9496
def get_image_paths_and_ids(images):
97+
global worker_counter
98+
counter_updated = False
9599
imagePaths = []
96100
imageIds = []
97101
temp_files = []
@@ -100,14 +104,25 @@ def get_image_paths_and_ids(images):
100104
imagePath = image['files'][0]['path']
101105
imageId = image['id']
102106
if '.zip' in imagePath:
107+
if not counter_updated:
108+
worker_counter += 1
109+
counter_updated = True
103110
zip_index = imagePath.index('.zip') + 4
104111
zip_path, img_path = imagePath[:zip_index], imagePath[zip_index+1:].replace('\\', '/')
112+
113+
# Create a unique temporary directory for this worker
114+
temp_dir = os.path.join(config.temp_image_dir, f"worker_{worker_counter}")
115+
os.makedirs(temp_dir, exist_ok=True)
116+
117+
temp_path = os.path.join(temp_dir, img_path)
118+
os.makedirs(os.path.dirname(temp_path), exist_ok=True)
119+
105120
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
106-
temp_path = os.path.join(config.temp_image_dir, img_path)
107-
os.makedirs(os.path.dirname(temp_path), exist_ok=True)
108-
zip_ref.extract(img_path, config.temp_image_dir)
121+
zip_ref.extract(img_path, temp_dir)
109122
imagePath = os.path.abspath(os.path.normpath(temp_path))
110-
temp_files.append(imagePath)
123+
124+
temp_files.append(temp_path)
125+
temp_files.append(temp_dir) # Ensure the temp directory is also added to temp_files
111126
imagePaths.append(imagePath)
112127
imageIds.append(imageId)
113128
except IndexError:

0 commit comments

Comments
 (0)