Workflow to check JS and PY code format (#242)

* fix css files
* create workflow
* format code using prettier
* black ignore 3rd party folder
* format py code using black
* black exclude option in workflow
* Don't format workflow files
* Add contributing instructions to readme
---------
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
Raghavan
2024-02-07 04:55:44 +05:30
committed by GitHub
parent 1c6875f746
commit 228c294ffa
87 changed files with 42300 additions and 30749 deletions

View File

@@ -5,73 +5,72 @@ import json
import base64
try:
import stashapi.log as log
from stashapi.tools import file_to_base64
from stashapi.stashapp import StashInterface
import stashapi.log as log
from stashapi.tools import file_to_base64
from stashapi.stashapp import StashInterface
except ModuleNotFoundError:
print("You need to install the stashapi module. (pip install stashapp-tools)",
file=sys.stderr)
print(
"You need to install the stashapi module. (pip install stashapp-tools)",
file=sys.stderr,
)
MANUAL_ROOT = None # /some/other/path to override scanning all stashes
cover_pattern = r"(?:thumb|poster|cover)\.(?:jpg|png)"
MANUAL_ROOT = None # /some/other/path to override scanning all stashes
cover_pattern = r'(?:thumb|poster|cover)\.(?:jpg|png)'
def main():
global stash, mode_arg
json_input = json.loads(sys.stdin.read())
global stash, mode_arg
json_input = json.loads(sys.stdin.read())
stash = StashInterface(json_input["server_connection"])
mode_arg = json_input['args']['mode']
stash = StashInterface(json_input["server_connection"])
mode_arg = json_input["args"]["mode"]
try:
if MANUAL_ROOT:
scan(MANUAL_ROOT, handle_cover)
else:
for stash_path in get_stash_paths():
scan(stash_path, handle_cover)
except Exception as e:
log.error(e)
try:
if MANUAL_ROOT:
scan(MANUAL_ROOT, handle_cover)
else:
for stash_path in get_stash_paths():
scan(stash_path, handle_cover)
except Exception as e:
log.error(e)
out = json.dumps({"output": "ok"})
print( out + "\n")
out = json.dumps({"output": "ok"})
print(out + "\n")
def handle_cover(path, file):
filepath = os.path.join(path, file)
filepath = os.path.join(path, file)
b64img = file_to_base64(filepath)
if not b64img:
log.warning(f"Could not parse {filepath} to b64image")
return
b64img = file_to_base64(filepath)
if not b64img:
log.warning(f"Could not parse {filepath} to b64image")
return
scenes = stash.find_scenes(
f={"path": {"modifier": "INCLUDES", "value": f'{path}"'}}, fragment="id"
)
scenes = stash.find_scenes(f={
"path": {
"modifier": "INCLUDES",
"value": f"{path}\""
}
}, fragment="id")
log.info(f'Found Cover: {[int(s["id"]) for s in scenes]}|{filepath}')
log.info(f'Found Cover: {[int(s["id"]) for s in scenes]}|{filepath}')
if mode_arg == "set_cover":
for scene in scenes:
stash.update_scene({"id": scene["id"], "cover_image": b64img})
log.info(f"Applied cover to {len(scenes)} scenes")
if mode_arg == "set_cover":
for scene in scenes:
stash.update_scene({
"id": scene["id"],
"cover_image": b64img
})
log.info(f'Applied cover to {len(scenes)} scenes')
def get_stash_paths():
config = stash.get_configuration("general { stashes { path excludeVideo } }")
stashes = config["configuration"]["general"]["stashes"]
return [s["path"] for s in stashes if not s["excludeVideo"]]
config = stash.get_configuration("general { stashes { path excludeVideo } }")
stashes = config["configuration"]["general"]["stashes"]
return [s["path"] for s in stashes if not s["excludeVideo"]]
def scan(ROOT_PATH, _callback):
log.info(f'Scanning {ROOT_PATH}')
for root, dirs, files in os.walk(ROOT_PATH):
for file in files:
if re.match(cover_pattern, file, re.IGNORECASE):
_callback(root, file)
log.info(f"Scanning {ROOT_PATH}")
for root, dirs, files in os.walk(ROOT_PATH):
for file in files:
if re.match(cover_pattern, file, re.IGNORECASE):
_callback(root, file)
if __name__ == '__main__':
main()
if __name__ == "__main__":
main()

View File

@@ -1,4 +1,4 @@
name: Set Scene Cover
name: Set Scene Cover
description: searches Stash for Scenes with a cover image in the same folder and sets the cover image in stash to that image
version: 0.4
url: https://github.com/stg-annon/CommunityScripts/tree/main/plugins/setSceneCoverFromFile
@@ -14,4 +14,4 @@ tasks:
- name: Set Cover
description: searches for cover images and sets any stash scene found in the same dir to that image
defaultArgs:
mode: set_cover
mode: set_cover