[titleFromFilename] various fixes (#104)

This commit is contained in:
bnkai 2022-11-18 22:03:06 +02:00 committed by GitHub
parent d77a76fa7a
commit b1018e6cb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 17 deletions

View File

@ -1,7 +1,15 @@
import json
import sys
import requests
def exit_plugin(msg=None, err=None):
if msg is None and err is None:
msg = "plugin ended"
output_json = {"output": msg, "error": err}
print(json.dumps(output_json))
sys.exit()
def doRequest(query, variables=None, port=9999, session=None, scheme="http", raise_exception=True):
# Session cookie for authentication
graphql_port = port
@ -27,7 +35,7 @@ def doRequest(query, variables=None, port=9999, session=None, scheme="http", rai
try:
response = requests.post(graphql_url, json=json,headers=graphql_headers, cookies=graphql_cookies, timeout=20)
except Exception as e:
exit_plugin(err="f[FATAL] Exception with GraphQL request. {e}")
exit_plugin(err=f"[FATAL] Exception with GraphQL request. {e}")
if response.status_code == 200:
result = response.json()
if result.get("error"):
@ -88,3 +96,4 @@ def get_api_version(port, session, scheme):
"""
result = doRequest(query=query, port=port, session=session, scheme=scheme)
return result.get('systemStatus')

View File

@ -4,22 +4,13 @@ import sys
import time
import config
import log
#import log
import graphql
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:
msg = "plugin ended"
output_json = {"output": msg, "error": err}
print(json.dumps(output_json))
sys.exit()
FRAGMENT = json.loads(sys.stdin.read())
#log.LogDebug(json.dumps(FRAGMENT))
FRAGMENT_SERVER = FRAGMENT["server_connection"]
@ -28,7 +19,7 @@ FRAGMENT_SCENE_ID = FRAGMENT["args"].get("hookContext")
if FRAGMENT_SCENE_ID:
scene_id = FRAGMENT_SCENE_ID["id"]
else:
exit_plugin("No ID found")
graphql.exit_plugin("No ID found")
graphql_port = FRAGMENT_SERVER['Port']
graphql_scheme = FRAGMENT_SERVER['Scheme']
@ -50,12 +41,12 @@ if api_version > API_VERSION_BF_FILES: # only needed for versions after files r
if len(files_base["files"]) > 0:
basename = files_base["files"][0].get("basename")
else:
exit_plugin(
graphql.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
graphql.exit_plugin("No basename found") # file-less scene
if config.STRIP_EXT:
basename = os.path.splitext(basename)[0]
@ -70,9 +61,9 @@ while i >= 0:
session=graphql_session,
scheme=graphql_scheme)
if updated_scene:
exit_plugin(
graphql.exit_plugin(
f"Scene title updated after {MAX_RETRY_COUNT - i} tries. Title:{updated_scene.get('title')}"
)
time.sleep(SLEEP_RETRY)
exit_plugin("Error updating scene")
graphql.exit_plugin("Error updating scene")

View File

@ -1,7 +1,7 @@
name: titleFromFilename
description: Set a scene's title from it's filename
url: https://github.com/stashapp/CommunityScripts
version: 1.1
version: 1.2
exec:
- python
- "{pluginDir}/titleFromFilename.py"