mirror of
https://github.com/stashapp/CommunityScripts.git
synced 2026-02-05 04:45:09 -06:00
[titleFromFilename] Retry update requests (#91)
This commit is contained in:
parent
c8b5c7dd24
commit
2b1998a2f1
@ -1,12 +1,16 @@
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
import config
|
||||
import log
|
||||
import graphql
|
||||
|
||||
API_VERSION_BF_FILES = 31 # APP/DB Schema version prior to files refactor PR
|
||||
API_VERSION_BF_FILES = 31 # APP/DB Schema version prior to files refactor PR
|
||||
MAX_RETRY_COUNT = 25
|
||||
SLEEP_RETRY = 0.5
|
||||
|
||||
|
||||
def exit_plugin(msg=None, err=None):
|
||||
if msg is None and err is None:
|
||||
@ -15,6 +19,7 @@ def exit_plugin(msg=None, err=None):
|
||||
print(json.dumps(output_json))
|
||||
sys.exit()
|
||||
|
||||
|
||||
FRAGMENT = json.loads(sys.stdin.read())
|
||||
#log.LogDebug(json.dumps(FRAGMENT))
|
||||
FRAGMENT_SERVER = FRAGMENT["server_connection"]
|
||||
@ -25,30 +30,49 @@ if FRAGMENT_SCENE_ID:
|
||||
else:
|
||||
exit_plugin("No ID found")
|
||||
|
||||
|
||||
graphql_port = FRAGMENT_SERVER['Port']
|
||||
graphql_scheme = FRAGMENT_SERVER['Scheme']
|
||||
graphql_session = FRAGMENT_SERVER.get('SessionCookie').get('Value')
|
||||
|
||||
system_status = graphql.get_api_version(port=graphql_port, session=graphql_session, scheme=graphql_scheme)
|
||||
system_status = graphql.get_api_version(port=graphql_port,
|
||||
session=graphql_session,
|
||||
scheme=graphql_scheme)
|
||||
|
||||
api_version = system_status.get("appSchema")
|
||||
|
||||
basename = None
|
||||
|
||||
if api_version > API_VERSION_BF_FILES: # only needed for versions after files refactor
|
||||
files_base = graphql.get_scene_base(scene_id=scene_id, port=graphql_port, session=graphql_session, scheme=graphql_scheme)
|
||||
if api_version > API_VERSION_BF_FILES: # only needed for versions after files refactor
|
||||
files_base = graphql.get_scene_base(scene_id=scene_id,
|
||||
port=graphql_port,
|
||||
session=graphql_session,
|
||||
scheme=graphql_scheme)
|
||||
if len(files_base["files"]) > 0:
|
||||
basename = files_base["files"][0].get("basename")
|
||||
else:
|
||||
exit_plugin(f"Stash with API version:{api_version} is not supported. You need at least {API_VERSION_BF_FILES}")
|
||||
exit_plugin(
|
||||
f"Stash with API version:{api_version} is not supported. You need at least {API_VERSION_BF_FILES}"
|
||||
)
|
||||
|
||||
if basename is None:
|
||||
exit_plugin("No basename found") # file-less scene
|
||||
exit_plugin("No basename found") # file-less scene
|
||||
|
||||
if config.STRIP_EXT:
|
||||
if config.STRIP_EXT:
|
||||
basename = os.path.splitext(basename)[0]
|
||||
|
||||
updated_scene = graphql.update_scene_title(scene_id, basename, port=graphql_port, session=graphql_session, scheme=graphql_scheme)
|
||||
i = MAX_RETRY_COUNT
|
||||
while i >= 0:
|
||||
#log.LogDebug(f"TitleFromFilename: Retry attempt {i}")
|
||||
i -= 1
|
||||
updated_scene = graphql.update_scene_title(scene_id,
|
||||
basename,
|
||||
port=graphql_port,
|
||||
session=graphql_session,
|
||||
scheme=graphql_scheme)
|
||||
if updated_scene:
|
||||
exit_plugin(
|
||||
f"Scene title updated after {MAX_RETRY_COUNT - i} tries. Title:{updated_scene.get('title')}"
|
||||
)
|
||||
time.sleep(SLEEP_RETRY)
|
||||
|
||||
exit_plugin(f"Scene title updated. Title:{updated_scene.get('title')}")
|
||||
exit_plugin("Error updating scene")
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
name: titleFromFilename
|
||||
description: Set a scene's title from it's filename
|
||||
url: https://github.com/stashapp/CommunityScripts
|
||||
version: 1.0
|
||||
version: 1.1
|
||||
exec:
|
||||
- python
|
||||
- "{pluginDir}/titleFromFilename.py"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user