From 8243d14caecdfe17b9c383446d675649ff981078 Mon Sep 17 00:00:00 2001 From: Tweeticoats Date: Thu, 11 Jan 2024 21:07:02 +1030 Subject: [PATCH 1/3] Adding miscTags plugin, this plugin parses the file name and adds vr related tags for stash-vr-companion. --- plugins/miscTags/miscTags.py | 154 ++++++++++++++++++++++++++++++++++ plugins/miscTags/miscTags.yml | 31 +++++++ 2 files changed, 185 insertions(+) create mode 100644 plugins/miscTags/miscTags.py create mode 100644 plugins/miscTags/miscTags.yml diff --git a/plugins/miscTags/miscTags.py b/plugins/miscTags/miscTags.py new file mode 100644 index 00000000..3f47cf50 --- /dev/null +++ b/plugins/miscTags/miscTags.py @@ -0,0 +1,154 @@ +import stashapi.log as log +from stashapi.stashapp import StashInterface +import sys +import json +import time + + +per_page = 100 +skip_tag='[MiscTags: Skip]' + +# Defaults if nothing has changed in the stash ui +settings={ + 'addStashVrCompanionTags':False, + 'addVrTags':False, + 'flatStudio':'' + } + +VRCTags={ + 'flat':{'VRCTags':['FLAT'],'projTags':[]}, + '180_mono':{'VRCTags':['DOME','MONO'],'projTags':['180°']}, + '360_mono':{'VRCTags':['SPHERE','MONO'],'projTags':['360°']}, + '180_sbs':{'VRCTags':['DOME','SBS'],'projTags':['180°']}, + 'LR_180':{'VRCTags':['DOME','SBS'],'projTags':['180°']}, + '180_lr': {'VRCTags':['DOME', 'SBS'],'projTags':['180°']}, + '180_3dh_lr': {'VRCTags': ['DOME', 'SBS'], 'projTags': ['180°']}, + '360_tb':{'VRCTags':['SPHERE','SBS'],'projTags':['360°']}, + 'mkx200':{'VRCTags':['MKX200','FISHEYE','SBS'],'projTags':['220°']}, + 'mkx220':{'VRCTags':['MKX220','FISHEYE','SBS'],'projTags':['220°']}, + 'vrca220': {'VRCTags':['VRCA220', 'FISHEYE', 'SBS'],'projTags':['220°']}, + 'rf52':{'VRCTags':['RF52','FISHEYE', 'SBS'],'projTags':['190°']}, + 'fisheye190': {'VRCTags':['RF52', 'FISHEYE', 'SBS'],'projTags':['190°']}, + 'passthrough':{'VRCTags':[],'projTags':['Augmented Reality']}, + '8k': {'VRCTags': [], 'projTags': ['8K']}, + '7k': {'VRCTags': [], 'projTags': ['7K']}, + '6k': {'VRCTags': [], 'projTags': ['6K']}, + '5k': {'VRCTags': [], 'projTags': ['5K']}, + } +tags_cache={} + +def processScene(scene): + log.debug('processing scene: %s' % (scene['id'],)) + # if the scene has [MiscTags: Skip] then skip it + if skip_tag not in tags_cache: + tags_cache[skip_tag]=stash.find_tag(skip_tag, create=True).get("id") + if tags_cache[skip_tag] not in [x['id'] for x in scene['tags']]: + tags=[] + if settings['addStashVrCompanionTags']: + processStashVRCompanionTags(scene,tags) + log.debug(tags) + if settings['addVrTags']: + processVRTags(scene,tags) + if len(settings['flatStudio']) > 0: + processFlatStudio(scene,tags) + + if len(tags) > 0: + log.debug('processing scene %s, checking if tags need to be added: %s' % (scene['title'],tags,)) + # start with the existing tag id's, then look up the new tag id's and create if needed + new_scene = {'id': scene['id'], 'tag_ids': [x['id'] for x in scene['tags']]} + update=False + for t in tags: + if t not in tags_cache: + tags_cache[t]=stash.find_tag(t, create=True).get("id") + update=True + if tags_cache[t] not in new_scene['tag_ids']: + new_scene['tag_ids'].append(tags_cache[t]) + update=True + if update: + log.info('Adding tags to scene: %s, tags: %s' % (scene['title'], tags,)) + stash.update_scene(new_scene) + else: + log.debug('no update') + else: + log.debug('skipping scene') + + +def processStashVRCompanionTags(scene,tags): + found=False + for f in scene['files']: + for k,v in VRCTags.items(): + if k in f['basename'].lower(): + tags.extend(v['VRCTags']) + found=True + if found: + tags.append('export_deovr') + return None + +def processVRTags(scene,tags): + found=False + for f in scene['files']: + for k,v in VRCTags.items(): + if k in f['basename'].lower(): + tags.extend(v['projTags']) + found=True + if found: + if 'vrTag' in stash.get_configuration()['ui']: + vr_tag=stash.get_configuration()['ui']['vrTag'] + if vr_tag: + tags.append(vr_tag) + else: + tags.append('VR') + else: + tags.append('VR') + return None + +def processFlatStudio(scene,tags): + log.debug(scene) + if scene['studio']: + if scene['studio']['id'] in [x.strip() for x in settings['flatStudio'].split(',')]: + if 'export_deovr' not in tags: + tags.append('export_deovr') + + tags.append('FLAT') + log.debug(tags) + +def processScenes(): + log.info('Getting scene count') + if skip_tag not in tags_cache: + tags_cache[skip_tag]=stash.find_tag(skip_tag, create=True).get("id") + count=stash.find_scenes(f={"tags":{"depth":0,"excludes":[tags_cache[skip_tag]],"modifier":"INCLUDES_ALL","value":[]}},filter={"per_page": 1},get_count=True)[0] + log.info(str(count)+' scenes to process.') + i=0 + for r in range(1,int(count/per_page)+2): + log.info('adding tags to scenes: %s - %s %0.1f%%' % ((r - 1) * per_page,r * per_page,(i/count)*100,)) + scenes=stash.find_scenes(f={"tags":{"depth":0,"excludes":[tags_cache[skip_tag]],"modifier":"INCLUDES_ALL","value":[]}},filter={"page":r,"per_page": per_page}) + for s in scenes: + processScene(s) + i=i+1 + log.progress((i/count)) + time.sleep(1) + + +json_input = json.loads(sys.stdin.read()) + +FRAGMENT_SERVER = json_input["server_connection"] +stash = StashInterface(FRAGMENT_SERVER) +config=stash.get_configuration()['plugins'] +if 'misc-tags' in config: + settings.update(config['misc-tags']) +log.info('config: %s ' % (settings,)) + +if 'mode' in json_input['args']: + PLUGIN_ARGS = json_input['args']["mode"] + if 'processScenes' in PLUGIN_ARGS: + processScenes() + elif 'test' in PLUGIN_ARGS: + log.debug(stash.get_configuration()['ui']['vrTag']) + + + +elif 'hookContext' in json_input['args']: + id=json_input['args']['hookContext']['id'] + if json_input['args']['hookContext']['type']=='Scene.Update.Post': + scene=stash.find_scene(id) + processScene(scene) \ No newline at end of file diff --git a/plugins/miscTags/miscTags.yml b/plugins/miscTags/miscTags.yml new file mode 100644 index 00000000..6e7da599 --- /dev/null +++ b/plugins/miscTags/miscTags.yml @@ -0,0 +1,31 @@ +name: Misc Tags +description: Add extra tags for VR and other ues +version: 0.2 +url: https://github.com/stashapp/CommunityScripts/ +exec: + - python + - "{pluginDir}/miscTags.py" +interface: raw +settings: + addStashVRCompanionTags: + displayName: Add tags for stash-vr-companion + description: Add tags useful for stash-vr-companion, export_deovr, DOME, SBS, VR based on filename string + type: BOOLEAN + addVRTags: + displayName: Add VR related tags + description: Add projection based tags 180°, 200°, VR + type: BOOLEAN + flatStudio: + displayName: 2d Studio for stash-vr-companion + description: Comma seperated list of studio number in your instance to tag with export_devor,FLAT for use with stash-vr-companion + type: STRING +hooks: + - name: process Scene + description: Makes Markers checking against timestamp.trade + triggeredBy: + - Scene.Update.Post +tasks: + - name: 'process all' + description: Submit markers to timestamp.trade + defaultArgs: + mode: processScenes From 36b5ad44757cdec35816ed40e71a54267c63c945 Mon Sep 17 00:00:00 2001 From: Tweeticoats <60335703+Tweeticoats@users.noreply.github.com> Date: Fri, 19 Jan 2024 21:35:06 +1030 Subject: [PATCH 2/3] Update miscTags.yml Fix description --- plugins/miscTags/miscTags.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/miscTags/miscTags.yml b/plugins/miscTags/miscTags.yml index 6e7da599..3bc8f0ad 100644 --- a/plugins/miscTags/miscTags.yml +++ b/plugins/miscTags/miscTags.yml @@ -26,6 +26,6 @@ hooks: - Scene.Update.Post tasks: - name: 'process all' - description: Submit markers to timestamp.trade + description: Process all scenes and add extra tags if configured defaultArgs: mode: processScenes From 810b9db274261f52cb0416ae909b5d409e63b41d Mon Sep 17 00:00:00 2001 From: Tweeticoats <60335703+Tweeticoats@users.noreply.github.com> Date: Fri, 19 Jan 2024 21:42:31 +1030 Subject: [PATCH 3/3] Update miscTags.py Fix bug if vr tag has not been configured --- plugins/miscTags/miscTags.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/miscTags/miscTags.py b/plugins/miscTags/miscTags.py index 3f47cf50..4bea8eff 100644 --- a/plugins/miscTags/miscTags.py +++ b/plugins/miscTags/miscTags.py @@ -93,11 +93,15 @@ def processVRTags(scene,tags): found=True if found: if 'vrTag' in stash.get_configuration()['ui']: - vr_tag=stash.get_configuration()['ui']['vrTag'] - if vr_tag: - tags.append(vr_tag) - else: - tags.append('VR') + if 'vrTag' in stash.get_configuration()['ui']: + vr_tag=stash.get_configuration()['ui']['vrTag'] + if vr_tag: + tags.append(vr_tag) + else: + tags.append('VR') + else: + tags.append('VR') + else: tags.append('VR') return None @@ -142,8 +146,6 @@ def processScenes(): PLUGIN_ARGS = json_input['args']["mode"] if 'processScenes' in PLUGIN_ARGS: processScenes() - elif 'test' in PLUGIN_ARGS: - log.debug(stash.get_configuration()['ui']['vrTag']) @@ -151,4 +153,4 @@ def processScenes(): id=json_input['args']['hookContext']['id'] if json_input['args']['hookContext']['type']=='Scene.Update.Post': scene=stash.find_scene(id) - processScene(scene) \ No newline at end of file + processScene(scene)