### Stash Plugin Installation Guide (Bash)
Source: https://context7.com/stashapp/communityscripts/llms.txt
Standard procedure for installing Stash plugins, covering Python dependency installation using pip and the correct directory structure for placing plugin folders within the Stash plugins directory.
```bash
# 1. Install Python dependencies (for Python plugins)
pip install stashapp-tools --upgrade
pip install requests
pip install Send2Trash # For file deletion plugins
# Or use requirements.txt if provided
pip install -r requirements.txt
# 2. Create plugin folder in Stash plugins directory
# Windows: C:\Users\{username}\.stash\plugins\{PluginName}
# Linux: ~/.stash/plugins/{PluginName}
```
--------------------------------
### Running FileMonitor as Standalone Script (Bash)
Source: https://context7.com/stashapp/communityscripts/llms.txt
This section provides command-line examples for running the FileMonitor script. It covers starting monitoring with a Stash URL, using an API key for authentication, stopping the monitoring process, restarting it as a Stash task, and configuring Docker support with a docker-compose file.
```bash
# Running FileMonitor as standalone script
# Start monitoring with Stash URL
python filemonitor.py --url http://localhost:9999
# With API key for password-protected Stash
python filemonitor.py --url http://localhost:9999 --apikey "your_api_key_here"
# Stop monitoring
python filemonitor.py --stop
# Restart monitoring as Stash task
python filemonitor.py --restart
# Docker support - pass docker-compose file for path mapping
python filemonitor.py --url http://localhost:9999 \
--docker "/path/to/docker-compose.yml" \
--apikey "your_api_key_here"
```
--------------------------------
### Install Python Dependencies
Source: https://github.com/stashapp/communityscripts/blob/main/scripts/stash-watcher/README.md
Installs project dependencies listed in the 'requirements.txt' file using pip. Ensure you have a virtual environment activated before running this command.
```bash
pip install -r requirements.txt
```
--------------------------------
### Install Dependencies using pip
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/FileMonitor/README.md
Lists the commands to install necessary Python packages for the Stash App community scripts. 'schedule' is required for the scheduler feature.
```bash
pip install -r requirements.txt
# Or manually:
pip install stashapp-tools --upgrade
pip install requests
pip install watchdog
pip install schedule
pip install pyyaml
```
--------------------------------
### Define Game Start JSON Structure
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/chooseYourAdventurePlayer/README.md
This JSON structure defines the properties for a '0.json' file, which serves as the starting point for games in StashApp. It includes fields for game identification, display titles, optional map details, navigation pointers, and user choices.
```json
{
"id": "0",
"type": null,
"title": "Game Start",
"map": {
"title": "Demo",
"description": "Your are viewing a demo of the Choose Your Adventure Player"
},
"mapItem": [
{
"choice_id": "TBD",
"title": "TBD",
"picture": null
}
],
"skipto": "2",
"choices": [
{
"description": "Good Choice",
"id": "1a",
"type": "",
"photo": null
},
{
"description": "Bad Choice",
"id": "1b",
"type": "",
"photo": null
}
],
"resource": {
"resolved_content": "Scene0.mp4"
}
}
```
--------------------------------
### Basic Path-Based Configuration
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/defaultDataForPath/README.md
This example shows a simple configuration object that applies a specific studio and tag to files located in defined paths. The 'name' field is optional and used for organization. If 'paths' is omitted, no files are matched unless 'children' are used.
```javascript
var jsonData = [
{
"name": "OPTIONAL NAME - NOT USED IN SCRIPT",
"paths": [
"C:\\Users\\UserName\\Desktop\\NOTPORN\\Brazzers",
"D:\\SecretStorage\\Porn\\Brazzers"
],
"studio": "Brazzers",
"tags": [
"Default_Data_For_Path_Tagged"
]
}
];
```
--------------------------------
### Theme Manifest Example (Theme-Pulsar.yml)
Source: https://context7.com/stashapp/communityscripts/llms.txt
Example of a theme manifest file for Stash, defining theme name, version, and associated CSS files. This file acts as a descriptor for custom themes.
```yaml
name: Theme - Pulsar
description: Plex Theme for Stash by Fonzie 2020-21
version: 1.8.1
url: https://discourse.stashapp.cc/t/pulsar/1429
ui:
css:
- Theme-Pulsar.css
```
--------------------------------
### nfoSceneParser.json Regex Configuration Example
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/nfoSceneParser/README.md
This JSON configuration file defines a regular expression pattern for parsing media file names or paths. It includes optional 'splitter' and 'scope' attributes to refine how the regex is applied and how matched data is processed.
```json
{
"regex": "^(?
.+?)\\s*\\(\\d{4}\\)",
"splitter": ",",
"scope": "filename"
}
```
--------------------------------
### Hierarchical Configuration with Inheritance
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/defaultDataForPath/README.md
This example demonstrates a hierarchical configuration structure where parent objects define settings (like studio or tags) that are inherited by their children. This allows for more organized and efficient configuration by avoiding repetition. If a parent object also has a 'paths' value, those settings apply directly to files in that path, overriding child inheritance for that specific path.
```javascript
var jsonData = [
{
"name": "Default Tag - Matches all scanned files",
"paths": [
""
],
"tags": [
"ORGANIZED - Unorganized"
]
},
{
"name": "Instagram Root",
"studio": "Instagram",
"children": [
{
"name": "Celebrities",
"tags": [
"PERFORMER - Celebrity"
],
"children": [
{
"name": "Kim Kardashian",
"paths": [
"C:\\Users\\UserName\\Desktop\\Instagram\\kimkardashian"
],
"performers": [
"Kim Kardashian"
],
"tags": [
"PERFORMER - Armenian",
"PERFORMER - Big Ass"
]
},
{
"name": "Katy Perry",
"paths": [
"C:\\Users\\UserName\\Desktop\\Instagram\\katyperry"
],
"performers": [
"Katy Perry"
],
"tags": [
"PERFORMER - Caucasian,
"PERFORMER - Big Tits"
]
}
]
},
{
"name": "Pornstars",
"tags": [
"PERFORMER - Pornstar
],
"children": [
{
"name": "Alexis Fawx",
"paths": [
"C:\\Users\\UserName\\Desktop\\Instagram\\alexisfawx"
],
"performers": [
"Alexis Fawx"
],
"tags": [
"PERFORMER - Caucasian",
"PERFORMER - Fake Tits"
]
}
]
}
]
}
```
--------------------------------
### Hot Cards Configuration Examples (Stash UI)
Source: https://context7.com/stashapp/communityscripts/llms.txt
Examples of configuring 'Hot Cards' in the Stash UI for visual highlighting. These configurations use tag or rating criteria combined with styling and gradient options.
```yaml
# Hot Cards configuration format in Stash UI
# Format: [criterion]_[value]_[style]_[gradient-opts]_[hover-opts]_[card-opts]
# Simple tag-based gold styling
t_123_gold
# Rating-based with custom threshold
r_4_hot
# Fixed color with hover effect
r_4_white__#5ff1a1_false
# Multi-tag with different styles
t_111,116,78,87/105_pink,red,white/orange,white_/,70deg,4s alternate infinite
# Rating tiers with style presets
r_5/4.2/3.7_gold/hot/default___//,50
# Animated gradient
_67_pink,red,yellow,green,blue_,30deg,5s ease infinite_red,1s ease-in-out infinite_,100
```
--------------------------------
### DupFileManager Configuration Example (Python)
Source: https://context7.com/stashapp/communityscripts/llms.txt
This Python dictionary defines the configuration settings for the DupFileManager script. It includes preferences for tagging duplicates, path handling, comparison criteria, codec ranking, and deletion behavior. These settings control how the script identifies and manages duplicate files.
```python
config = {
# Tag used to mark duplicates for deletion
"DupFileTag": "DuplicateMarkForDeletion",
# Path preferences for duplicate resolution
# Files in whitelist paths are never deleted
# Files in blacklist paths are preferred deletion candidates
"listSeparator": ",",
# Comparison preferences
"favorLongerFileName": True,
"favorLargerFileSize": True,
"favorHighBitRate": True,
"favorHigherFrameRate": True,
"favorCodecRanking": True,
# Codec ranking by efficiency (first = best)
"codecRankingSet1": [
"h266", "vvc", "av1", "h265", "hevc",
"vp9", "h264", "avc", "vp8", "mpeg4"
],
# Processing options
"permanentlyDelete": False, # Move to trash instead
"cleanAfterDel": True, # Run cleanup after deletion
"skipIfTagged": False, # Process already-tagged scenes
# Threshold for significant duration difference
"significantTimeDiff": 0.90, # 90% threshold
}
```
--------------------------------
### Install DupFileManager Plugin for Stash
Source: https://context7.com/stashapp/communityscripts/llms.txt
This script installs the DupFileManager plugin by creating a directory and copying plugin files into the Stash plugins folder. It assumes the plugin files are located in the 'plugins/DupFileManager/' directory.
```bash
mkdir -p ~/.stash/plugins/DupFileManager
cp -r plugins/DupFileManager/* ~/.stash/plugins/DupFileManager/
```
--------------------------------
### Scene Metadata from Scene NFO Example
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/nfoSceneParser/README.md
This XML snippet illustrates the structure of an NFO file for an individual scene, utilizing the `` tag to associate it with a larger movie or collection. It includes tags for scene title, plot, cover art, studio, and set information.
```xml
BestSceneEver
Scene of the century
https://scene_cover.jpg
Best studio ever
My Movie Title
2
```
--------------------------------
### Custom Icon Definition Example (JavaScript)
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/externalLinksEnhanced/README.md
An example of how to define a custom icon for an external link within the plugin's configuration. This JSON structure specifies the site name, the icon file to use, and the addresses associated with the site for link detection.
```javascript
{
name: "sitename",
icon: "myicon.png",
addresses: ["mysitename.com"]
}
```
--------------------------------
### JavaScript Example: Specific Studio Folders with Scenes
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/pathParser/README.md
This JavaScript example demonstrates a Path Parser rule for matching specific studio folders and extracting the filename as the scene title. It uses an array pattern to match multiple studio names and a null pattern for the filename. The '#0' and '#1' syntax references captured groups from the patterns.
```javascript
{
name: 'Studio/Scene',
pattern: [
['Specific Studio', 'Another Studio'], // A specific studio name
null // Any filename
],
fields: {
title: '#1', // 1 refers to the second pattern (filename)
studio: '#0' // 0 refers to the first pattern (folder)
}
}
```
--------------------------------
### Path Parser Configuration Examples (JavaScript)
Source: https://context7.com/stashapp/communityscripts/llms.txt
Defines rules for parsing file paths to extract scene metadata. Supports simple string matching, regex patterns, and custom JavaScript functions for complex parsing logic. Outputs are mapped to fields like title, studio, and performers.
```javascript
// pathParser_config.js - Rule configuration examples
const rules = [
// Simple studio/scene pattern
{
name: 'Studio/Scene',
pattern: [
['Specific Studio', 'Another Studio'], // Match specific studios
null // Any filename
],
fields: {
title: '#1', // Use filename (index 1)
studio: '#0' // Use folder name (index 0)
}
},
// Regex pattern for movie with year
{
name: 'Studio/Movie (YEAR)/Scene - Episode #',
pattern: [
null, // Any studio folder
/(.+) \(\d{4}\)/, // Movie Title (2022)
/(.+) - Episode (\d+)/ // Scene - Episode 1
],
fields: {
title: '#2', // Scene title from filename
studio: '#0', // Studio from first folder
movie_title: '#1', // Movie title from regex group
scene_index: '#3' // Episode number from regex group
}
},
// Function-based pattern for complex parsing
{
name: 'Studio/Scene.Performers.S##E##',
pattern: [
null,
function (path) {
var parts = path.split('.');
var performers = parts[1].split('&')
.map(p => p.trim())
.join(',');
var series = /S(\d{2})E(\d{2})/ .exec(parts[2]);
return [parts[0], performers, parseInt(series[1]), parseInt(series[2])];
}
],
fields: {
title: '#1',
studio: '#0',
performers: '#2',
movie_title: '#1 - Season #3',
scene_index: '#4'
}
}
];
// Example input: X:\Prime\The Boys.Karl Urban & Jack Quaid.S06E09.mp4
// Output:
// title: "The Boys"
// studio: "Prime"
// performers: "Karl Urban,Jack Quaid"
// movie_title: "The Boys - Season 6"
// scene_index: "9"
```
--------------------------------
### Configure Multiple Stash Docker Instances in filemonitor_config.py
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/FileMonitor/README.md
This Python code snippet demonstrates how to configure the 'dockers' field in the filemonitor_config.py file to manage multiple Stash Docker instances. It includes examples for basic configuration, multiple bind mounts, and instances requiring an API key. Each entry requires GQL URL, apiKey, and bindMounts.
```python
# Docker notification from host machine
"dockers": [
# A simple basic example with only one bind mount path.
{"GQL":"http://localhost:9995", "apiKey":"", "bindMounts":[{r"C:\\Video":"/mnt/Video"}]},
# Example having 8 bind mount paths.
{"GQL":"http://localhost:9997", "apiKey":"", "bindMounts":[
{r"C:\\Users\\admin3\\AppData\\Local\\Docker\\wsl\\ManyMnt\\data":"/data"},
{r"C:\\Users\\admin3\\Videos":"/external"},
{r"C:\\Users\\admin3\\Pictures":"/external2"},
{r"C:\\Users\\admin3\\Downloads":"/external3"},
{r"E:\\Downloads":"/external4"},
{r"E:\\Celeb":"/external5"},
{r"F:\\Hentai":"/external6"},
{r"Z:\\Temp":"/external7"},
]
},
# Example using the apiKey for a password configured Stash installation.
{"GQL":"http://localhost:9994", "apiKey":"eyJhb3676zgdUzI1NiIsInR5cCI6IwfXVCJ9.ewJ1aWQiOiJheHRlweIsInN1YiI6IkFQSUtleSIsImlhdewrweczNDU0MDk3N30.4nZVLk3xikjJZfZ0JTPA_Fic8JvFx3DZe5U21Zasdag", "bindMounts":[
{r"C:\\Users\\admin3\\AppData\\Local\\Docker\\wsl\\MyStashContainer\\data":"/data"},
{r"C:\\Vid":"/mnt/Vid"},
{r"C:\\Users\\admin3\\Downloads":"/mnt/Downloads"},
]
},
],
```
--------------------------------
### Movie Metadata from folder.nfo Example
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/nfoSceneParser/README.md
This XML snippet demonstrates the structure of a folder.nfo file, used to define metadata for all scene files within the same directory. It includes tags for movie title, plot, cover art, studio, and director.
```xml
My Movie Title
You have to see it to believe it...
https://front_cover.jpg
https://back_cover.jpg
Best studio ever
Georges Lucas
```
--------------------------------
### Install Python Requirements for Stash Plugin
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/PlexSync/README.md
Installs necessary Python packages for the Stash plugin. It can install requirements from a local file or globally. Ensure you have Python 3 and pip installed.
```bash
python3 -m pip install -r requirements.txt -t .
python3 -m pip install stashapi unidecode requests
```
--------------------------------
### nfoSceneParser.json Configuration Example
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/nfoSceneParser/README.md
This JSON configuration defines the regular expression and settings for parsing movie file paths and names. It uses capturing groups to extract specific metadata like movie, studio, performers, and title from file paths.
```json
{
"regex": "^.*[/\\](?P.*?)[/\](?P.*?) - (?P.*?) - (?P.*?)[-]+.*\\.mp4$",
"splitter": ", ",
"scope": "path"
}
```
--------------------------------
### Running Stash Watcher (Bash)
Source: https://context7.com/stashapp/communityscripts/llms.txt
Commands to run the Stash Watcher service directly using Python virtual environments and pip, or via Docker Compose. It covers dependency installation and execution.
```bash
# Running Stash Watcher directly
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python watcher.py config.toml
# Running with Docker Compose
# docker-compose.yml
version: "3.4"
services:
stash-watcher:
container_name: stash-watcher
build: ./stash-watcher
volumes:
- ./config.toml:/config.toml:ro
- /path/to/media:/data:ro
restart: unless-stopped
```
--------------------------------
### Build and Run Stash Watcher with Docker Compose
Source: https://github.com/stashapp/communityscripts/blob/main/scripts/stash-watcher/README.md
Builds the Docker image for Stash Watcher and starts the service in detached mode using Docker Compose. This command assumes a 'docker-compose.yml' file is present in the current directory.
```bash
docker compose up -d --build
```
--------------------------------
### Configure Local VLM Endpoint (Python)
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/AHavenVLMConnector/README.md
Example configuration for a local VLM endpoint using LM Studio. This Python dictionary specifies the base URL, API key (if required), a name for the endpoint, its processing weight, and whether it serves as a fallback. It's crucial for setting up communication with local VLM services.
```python
{
"base_url": "http://localhost:1234/v1", # LM Studio default
"api_key": "", # API key not required
"name": "lm-studio-local",
"weight": 5,
"is_fallback": False
}
```
--------------------------------
### JavaScript Example: Studio with Movie Sub-folder and Scenes
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/pathParser/README.md
This JavaScript example shows a Path Parser rule for complex file paths including studio, movie sub-folder (with year), and scene information. It utilizes regular expressions to capture movie titles and scene details, referencing captured groups using '#index' in the fields to update scene metadata.
```javascript
{
name: 'Studio/Movie (YEAR)/Scene - Scene #',
pattern: [
null, // Any studio name
/(.+) \(\d{4}\)/, // A sub-folder with 'Movie Title (2022)'
/(.+) - \w+ ({d})/,
],
fields: {
title: '#2',
studio: '#0',
movie_title: '#1',
scene_index: '#3'
}
}
```
--------------------------------
### Ensure Python Package Import with Version Constraint
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/PythonDepManager/README.md
Ensures a Python package is installed and available for import, with support for specific version constraints. This function handles checking for existing installations and installing new packages if necessary. It can be used for basic imports or with custom import names.
```python
from PythonDepManager import ensure_import
# Install and import a package with specific version
ensure_import("requests==2.26.0")
# Afterwards imports will use only the requested versions
import requests
```
```python
from PythonDepManager import ensure_import
# Define a minimum version to use. This will either use any cached version
# which matches or install the latest
ensure_import("requests>=2.26.0")
```
```python
from PythonDepManager import ensure_import
# Install beautifulsoup4 but import as bs4
ensure_import("bs4:beautifulsoup4==4.9.3")
```
```python
from PythonDepManager import ensure_import
# Install stashapp-tools but import as stashapi
ensure_import("stashapi:stashapp-tools==0.2.58")
```
```python
from PythonDepManager import ensure_import
# Install from a Git repository
ensure_import("stashapi@git+https://github.com/user/repo.git")
# Install specific branch/tag
ensure_import("stashapi@git+https://github.com/user/repo.git@main")
# Install specific commit
ensure_import("stashapi@git+https://github.com/user/repo.git@ad483dc")
```
```python
from PythonDepManager import ensure_import
ensure_import(
"requests",
"bs4:beautifulsoup4==4.9.3",
"stashapi:stashapp-tools==0.2.58",
"someothermodule>=0.1",
)
```
--------------------------------
### Get Plugin Configuration with CommunityScripts
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/CommunityScriptsUILibrary/README.md
Retrieves a plugin's configuration from the server using GraphQL. It allows specifying a fallback value if the configuration is not found. Returns the plugin's configuration object.
```javascript
/**
* Get configuration of a plugin from the server via GraphQL
* @param {string} pluginId - The ID of the plugin as it is registered in the server
* @param {*}= fallback - Fallback value if the configuration is not found. Defaults to an empty object
* @returns {Object} - The configuration object of the plugin as it is stored in the server
*
* @example
* // set default config
* const defaultConfig = { enabled: true, theme: 'light' };
* // fetch config from the server
* const config = await getConfiguration('CommunityScriptsUIPlugin', defaultConfig);
* // config = { theme: 'dark' }
* // merge fetched with default config
* const pluginConfig = {
* ...defaultConfig,
* ...config
* };
* // pluginConfig = { enabled: true, theme: 'dark' }
* }
*/
```
--------------------------------
### Install Python Libraries for Star Identifier
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/starIdentifier/README.md
Installs the necessary Python libraries for the Star Identifier script, including numpy, dlib, and face_recognition. These libraries are essential for the facial recognition functionality.
```bash
pip install numpy dlib face_recognition
```
--------------------------------
### Timestamp Trade Python Plugin Tasks
Source: https://context7.com/stashapp/communityscripts/llms.txt
Describes the available tasks for the Timestamp Trade plugin in Stash, used for synchronizing scene markers with XBVR via the timestamp.trade API. It outlines requirements and installation steps.
```python
# timestampTrade tasks available in Stash:
#
# Submit - Submit markers for all scenes that have markers
# Sync - Fetch markers for all scenes with a StashDB ID
# Post update hook - Automatically fetch markers when scene is updated
# Requirements:
# - Scene must have a StashDB ID for fetching markers
# - StashDB ID recommended (but not required) for submitting markers
# Installation:
# 1. Copy timestampTrade directory to Stash plugins folder
# 2. Reload plugins in Settings > Plugins
# 3. Tasks appear in Settings > Tasks > Plugin Tasks
```
--------------------------------
### Define Tags for Analysis (Python)
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/AHavenVLMConnector/README.md
A Python list defining specific tags to be used for content analysis. This configuration allows users to specify keywords or concepts relevant to their media, guiding the VLM in its tagging process. The VLM will attempt to identify and associate these tags with the analyzed content.
```python
"tag_list": [
"Basketball point", "Foul", "Break-away", "Turnover"
]
```
--------------------------------
### FileMonitor Task Scheduler Configuration (Python)
Source: https://context7.com/stashapp/communityscripts/llms.txt
This Python list defines the configuration for FileMonitor's task scheduler. It specifies various tasks like 'Auto Tag', 'Optimise Database', 'Scan', and backup operations, along with their scheduling parameters such as weekday, time, and monthly recurrence. It also includes examples for plugin tasks and frequency-based checks.
```python
# filemonitor_config.py - Task scheduler configuration
"task_scheduler": [
# Daily tasks - use 'every' or list all weekdays
{"task": "Auto Tag",
"weekday": "every",
"time": "05:00"},
{"task": "Optimise Database",
"weekday": "monday,tuesday,wednesday,thursday,friday",
"time": "07:00"},
# Weekly tasks - specify single weekday
{"task": "Scan",
"weekday": "saturday",
"time": "03:00"},
{"task": "Generate",
"weekday": "saturday",
"time": "04:00"},
{"task": "Clean",
"weekday": "saturday",
"time": "04:30"},
{"task": "Clean Generated Files",
"weekday": "saturday",
"time": "05:00"},
# Monthly tasks - add 'monthly' field (1-4 for week of month)
{"task": "Backup",
"weekday": "sunday",
"time": "01:00",
"monthly": 2}, # 2nd Sunday of month
# Plugin tasks - use plugin ID and optional taskName
{"task": "DupFileManager",
"taskName": "Delete Duplicates",
"validateDir": "DupFileManager",
"weekday": "sunday",
"time": "02:00",
"monthly": 2},
# Frequency-based tasks (hours/minutes)
{"task": "CheckStashIsRunning",
"minutes": 5}, # Check every 5 minutes
{"task": "Auto Tag",
"hours": 24}, # Run every 24 hours
]
```
--------------------------------
### Configure Stash API Key and GraphQL URL
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/DupFileManager/advance_options.html
This JavaScript code snippet configures the API key and GraphQL URL for interacting with Stash. It retrieves these values from URL parameters or uses default values. The API key is essential for authenticated requests to Stash installations with password protection. The GraphQL URL specifies the endpoint for Stash's GraphQL API.
```javascript
var apiKey = ""; // For Stash installations with a password setup, populate this variable with the apiKey found in Stash->Settings->Security->[API Key]; ----- Or pass in the apiKey at the URL command line. Example: advance_options.html?apiKey=12345G4igiJdgssdgiwqInh5cCI6IkprewJ9hgdsfhgfdhd&GQL=http://localhost:9999/graphql
var GraphQl_URL = "http://localhost:9999/graphql"; // For Stash installations with non-standard ports or URL's, populate this variable with actual URL; ----- Or pass in the URL at the command line using GQL param. Example: advance_options.html?GQL=http://localhost:9900/graphql
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get("apiKey") != null && urlParams.get("apiKey") !== "") apiKey = urlParams.get("apiKey");
if (urlParams.get("GQL") != null && urlParams.get("GQL") !== "") GraphQl_URL = urlParams.get("GQL");
console.log(urlParams);
console.log("GQL = " + GraphQl_URL);
console.log("Key = " + apiKey);
```
--------------------------------
### Python: Filter Scene Renaming by Path
Source: https://github.com/stashapp/communityscripts/blob/main/scripts/Sqlite_Renamer/README.md
This Python example shows how to limit the scope of the `edit_db` function to scenes located within a specific directory path. It constructs a SQLite WHERE clause to filter by path and then applies the filename template.
```python
option_sqlite_query = "WHERE path LIKE 'E:\\Film\\R18\\%'"
edit_db("$date $performer - $title [$studio]",option_sqlite_query)
```
--------------------------------
### Implement Multi-Scene Choices with Fragments
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/chooseYourAdventurePlayer/README.md
This JSON structure demonstrates how to implement multi-scene choices using the 'fragments' property, which replaces the single 'resource' property. Each fragment can contain multiple actions, allowing for more complex user interactions and repeatable scene elements.
```json
{
"id": "2",
"type": null,
"title": "Action choice",
"fragments": [
{
"id": "frag-a",
"photo": {
"id": "frag-a_photo",
"content": "frag-a.jpg"
},
"video": {
"id": "frag-a_video",
"resolved_content": "Scene2A.mp4"
},
"actions": [
{
"id": "frag-a-action-a",
"photo": {
"id": "frag-a-action-a_photo",
"content": "frag-a-action-a.jpg"
},
"video": {
"id": "frag-a-action-a_video",
"resolved_content": "Scene2A-1.mp4"
},
"title": "TBD"
},
{
"id": "frag-a-action-b",
"photo": {
"id": "frag-a-action-b_photo",
"content": "frag-a-action-b.jpg"
},
"video": {
"id": "frag-a-action-b_video",
"resolved_content": "Scene2A-1.mp4"
},
"title": "TBD"
}
],
"title": "TBD"
},
{
"id": "frag-b",
"photo": {
"id": "frag-b_photo",
"content": "frag-b.jpg"
},
"video": {
"id": "frag-b_video",
"resolved_content": "Scene2B.mp4"
},
"actions": null,
"title": "TBA",
"subtitles": "Scene3-08"
}
],
"skipto": null,
"choices": [
{
"description": null,
"id": "2-e",
"type": "end",
"photo": "TBD"
}
],
"resource": {
"id": "empty",
"resolved_content": null
}
}
```
--------------------------------
### Configure Task Scheduler in Python
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/FileMonitor/README.md
This Python code snippet demonstrates how to configure the `task_scheduler` section within the `filemonitor_config.py` file. It shows various scheduling options including daily, weekly, and monthly tasks, as well as tasks that depend on specific plugins. The configuration uses a list of dictionaries, where each dictionary defines a task with its name, scheduling parameters (weekday, time, monthly), and optional task-specific fields.
```python
"task_scheduler": [
# To create a daily task, include each day of the week for the weekday field or "every"
# Optional field for task "Auto Tag" is 'paths'. For detail usage, see example #A3: in filemonitor_task_examples.py
{"task" : "Auto Tag", "weekday" : "monday,tuesday,wednesday,thursday,friday,saturday,sunday", "time" : "05:00"}, # Auto Tag -> [Auto Tag] (Daily at 6AM)
# Task "Create Tags" is a plugin task. Optional fields are taskName and validateDir field. For detail usage, see examples #B1, #B2, #B3, and #B4 in filemonitor_task_examples.py
{"task" : "pathParser", "taskName" : "Create Tags", "validateDir" : "pathParser",
"weekday" : "every", "time" : "05:30"}, # [Plugin Tasks] -> [Path Parser] -> [Create Tags] (Daily at 5AM) : This task requires plugin [Path Parser]
# The following task runs plugin DupFileManager (tag_duplicates_task) if the plugin is installed. The task runs in the background because of "taskQue" : False
{"task" : "DupFileManager", "taskMode" : "tag_duplicates_task", "validateDir" : "DupFileManager", "taskQue" : False,
"weekday" : "every", "time" : "02:30"}, # [Plugin Tasks] -> DupFileManager -> [Delete Duplicates] (Daily at 2:30AM)
{"task" : "Optimise Database", "weekday" : "monday,tuesday,wednesday,thursday,friday", "time" : "07:00"}, # Maintenance -> [Optimise Database] (Every weekday at 7AM)
# The following tasks are scheduled weekly
# Optional field for task "Scan", "Auto Tag", and "Clean" is 'paths'. For detail usage, see examples #A3: in filemonitor_task_examples.py
{"task" : "Scan", "weekday" : "saturday", "time" : "03:00"}, # Library -> [Scan] (Weekly) (Every saturday at 3AM)
{"task" : "Auto Tag", "weekday" : "saturday", "time" : "03:30"}, # Auto Tag -> [Auto Tag] (Weekly) (Every saturday at 3:30AM)
{"task" : "Generate", "weekday" : "saturday", "time" : "04:00"}, # Generated Content-> [Generate] (Every saturday at 4AM)
{"task" : "Clean", "weekday" : "saturday", "time" : "04:30"}, # Maintenance -> [Clean] (Every saturday at 4:30AM)
{"task" : "Clean Generated Files", "weekday" : "saturday", "time" : "05:00"}, # Maintenance -> [Clean Generated Files] (Every saturday at 5AM)
{"task" : "Optimise Database", "weekday" : "saturday", "time" : "05:30"}, # Maintenance -> [Optimise Database] (Every saturday at 5:30AM)
# To perform a task monthly, specify the day of the month as in the weekly schedule format, and add a monthly field.
# The monthly field value must be 1, 2, 3, or 4.
# 1 = 1st specified weekday of the month. Example 1st monday.
# 2 = 2nd specified weekday of the month. Example 2nd monday of the month.
# 3 = 3rd specified weekday of the month.
# 4 = 4th specified weekday of the month.
# The Backup task is scheduled monthly
# Optional field for task "Backup" is maxBackup. For detail usage, see example #A5 in filemonitor_task_examples.py
{"task" : "Backup", "weekday" : "sunday", "time" : "01:00", "monthly" : 2}, # Backup -> [Backup] 2nd sunday of the month at 1AM (01:00)
# The following task requires plugin DupFileManager and UI option [Delete Duplicate Scheduler] enabled.
{"task" : "DupFileManager", "taskName" : "Delete Duplicates", "validateDir" : "DupFileManager",
"weekday" : "sunday", "time" : "02:00", "monthly" : 2}, # [Plugin Tasks] -> DupFileManager -> [Delete Duplicates] 2nd sunday of the month at 2AM (02:00)
# The [CheckStashIsRunning] task checks if Stash is running. If not running, it will start up stash.
# This task only works if FileMonitor is started as a service or in command line mode.
# Optional fields are 'command' and 'RunAfter'. For detail usage, see examples #C1 and #C2 in filemonitor_task_examples.py
{"task" : "CheckStashIsRunning", "minutes" :5} # Checks every 5 minutes
],
```
--------------------------------
### Monthly Task Scheduling (Weekday Based)
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/FileMonitor/README.md
Sets up a task to run on a specific occurrence of a weekday within a month (e.g., the 3rd Sunday). Requires 'weekday', 'time', and 'monthly' fields.
```json
{
"task" : "Backup",
"weekday" : "sunday",
"time" : "01:00",
"monthly" : 3
},
{
"task" : "Clean",
"weekday" : "saturday",
"time" : "14:00",
"monthly" : 1
}
```
--------------------------------
### Create Python Virtual Environment
Source: https://github.com/stashapp/communityscripts/blob/main/scripts/stash-watcher/README.md
Creates and activates a Python virtual environment for managing project dependencies. This is an optional but recommended step for isolating project environments.
```bash
python -m venv venv
. venv/bin/activate
```
--------------------------------
### Run FileMonitor with Docker and API Key
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/FileMonitor/README.md
This command executes the FileMonitor script externally for a Dockerized Stash instance. It requires the Stash URL, the path to the docker-compose.yml file, and an API key for authentication if Stash Docker is password-protected. The docker-compose.yml file is crucial for mapping host paths to Docker paths.
```bash
python filemonitor.py --url http://localhost:9999 --docker "C:\Users\MyUser\AppData\Local\Docker\wsl\Stash27.2\docker-compose.yml" --apikey "zNDU0MDk3N30.4nZVLk3xikjJZfZ0JTPA_Fic8JveycCI6IkpXVCJ9.eyJ1aWQiOiJheHRlJhbGciOiJIUzI1NiIsInR5I6IkFQSUtleSIsImlhdCI6MTcFx3DZe5U21ZDcC3c"
```
--------------------------------
### Minute-Based Plugin Task Scheduling (Frequency Based)
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/FileMonitor/README.md
Schedules a specific plugin task to run at a defined interval in minutes. Requires 'pluginId', 'minutes', and 'task' fields.
```json
{
"task" : "Create Tags",
"pluginId" : "pathParser",
"minutes" : 30
}
```
--------------------------------
### Sample Theme CSS (Theme-Pulsar.css)
Source: https://context7.com/stashapp/communityscripts/llms.txt
A sample CSS file demonstrating basic theme styling for Stash. It defines root variables for colors and applies them to body and card elements.
```css
/* Theme-Pulsar.css - Sample theme CSS structure */
:root {
--background-color: #1a1a2e;
--card-background: #16213e;
--text-color: #eaeaea;
--accent-color: #e94560;
--border-color: #0f3460;
}
body {
background-color: var(--background-color);
color: var(--text-color);
}
.card {
background-color: var(--card-background);
border: 1px solid var(--border-color);
border-radius: 8px;
}
.btn-primary {
background-color: var(--accent-color);
border: none;
}
```
--------------------------------
### Hourly Task Scheduling (Frequency Based)
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/FileMonitor/README.md
Configures a task to run at a specified interval in hours. The 'hours' value must be greater than zero.
```json
{
"task" : "Auto Tag",
"hours" : 24
}
```
--------------------------------
### Set Video Processing Settings (Python)
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/AHavenVLMConnector/README.md
Python variables to control video processing parameters. `VIDEO_FRAME_INTERVAL` determines the frequency of frame analysis, while `CONCURRENT_TASK_LIMIT` sets the maximum number of simultaneous processing tasks. These settings help optimize performance based on available hardware resources.
```python
VIDEO_FRAME_INTERVAL = 2.0 # Process every 2 seconds
CONCURRENT_TASK_LIMIT = 8 # Adjust based on local hardware
```
--------------------------------
### Daily Task Scheduling (Weekday Based)
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/FileMonitor/README.md
Configures a task to run every day of the week at a specified time. The 'weekday' field can list all days or use the keyword 'every'.
```json
{
"task" : "Optimise Database",
"weekday" : "monday,tuesday,wednesday,thursday,friday,saturday,sunday",
"time" : "06:00"
},
{
"task" : "Optimise Database",
"weekday" : "every",
"time" : "14:00"
}
```
--------------------------------
### Weekly Task Scheduling (Weekday Based)
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/FileMonitor/README.md
Schedules a task to run on a specific day of the week at a given time. Requires 'weekday' and 'time' fields.
```json
{
"task" : "Generate",
"weekday" : "monday",
"time" : "09:00"
}
```
--------------------------------
### Execute Stash Watcher with Python
Source: https://github.com/stashapp/communityscripts/blob/main/scripts/stash-watcher/README.md
Runs the Stash Watcher script directly using Python. It requires the path to the configuration file as an argument. This method is suitable for direct execution on a system.
```bash
python watcher.py path_to_config.toml
```
--------------------------------
### Run FileMonitor with Docker
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/FileMonitor/README.md
This command executes the FileMonitor script externally for a Dockerized Stash instance. It requires the Stash URL and the path to the docker-compose.yml file. The docker-compose.yml file is essential for FileMonitor to determine the host path mapped to the Docker path.
```bash
python filemonitor.py --url http://localhost:9999 --docker "C:\Users\MyUser\AppData\Local\Docker\wsl\Stash27.2\docker-compose.yml"
```
--------------------------------
### Plugin Task Configuration
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/FileMonitor/README.md
Defines a task that utilizes a plugin. The 'pluginId' is typically the script's filename without the extension. Optional fields like 'taskName', 'taskMode', 'validateDir', and 'taskQue' can modify task behavior.
```json
{
"task" : "YourPluginTask",
"pluginId" : "your_plugin_script",
"taskName" : "specificTask",
"validateDir" : "/path/to/plugin/subdir",
"taskQue" : true,
"taskMode" : "run"
}
```
--------------------------------
### Run DupFileManager Plugin Operation via AJAX
Source: https://github.com/stashapp/communityscripts/blob/main/plugins/DupFileManager/advance_options.html
This JavaScript function, `RunPluginDupFileManager`, executes operations for the DupFileManager plugin using AJAX. It sends POST requests to the Stash GraphQL endpoint with specified modes and parameters. The function handles API key authentication, logs request details, and processes the AJAX response, including error handling and success notifications for report generation.
```javascript
function RunPluginDupFileManager( Mode, Param = 0, Async = false, TagOnlyScenes = false ) {
$("html").addClass("wait");
$("body").css("cursor", "progress");
if (TagOnlyScenes) Param += ":TagOnlyScenes";
console.log( "GraphQl_URL = " + GraphQl_URL + "; Mode = " + Mode + "; Param = " + Param );
if (apiKey !== "") {
console.log("Using apiKey = " + apiKey);
$.ajaxSetup({
beforeSend: function (xhr) {
xhr.setRequestHeader("apiKey", apiKey);
},
});
}
$.ajax({
method: "POST",
url: GraphQl_URL,
contentType: "application/json",
dataType: "text",
cache: Async,
async: Async,
data: JSON.stringify({
query: `mutation RunPluginOperation($plugin_id:ID!,$args:Map!){runPluginOperation(plugin_id:$plugin_id,args:$args)}`,
variables: {
plugin_id: "DupFileManager",
args: {
Target: Param,
mode: Mode
},
},
}),
success: function (result) {
$("html").removeClass("wait");
$("body").css("cursor", "default");
if (result.startsWith('{"errors"')) {
console.log("Ajax FAILED with result = " + result);
if (result.indexOf('{"runPluginOperation":null}') > 0) alert( "Stash RunPluginOperation failed with possible source code error.\nCheck Stash logging for details.\n\nResults = " + result );
else alert( "Stash RunPluginOperation failed with result = " + result );
return;
}
console.log("Ajax success with result = " + result);
if ( Mode === "tag_duplicates_task" || Mode === "create_duplicate_report_task" ) {
if (result.indexOf("Report complete") == -1) alert( "Stash RunPluginOperation returned unexpected results.\nNot sure if report completed successfully.\n\nResults = " + result );
else $( "Report complete. Click on OK to open report in browser.
" ).confirm(function (e) {
if (e.response) {
var reportUrl = window.location.href;
reportUrl = reportUrl.replace( "advance_options.html", "report/DuplicateTagScenes.html" );
console.log("reportUrl = " + reportUrl);
window.open(reportUrl, "_blank");
}
});
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log( "Ajax failed with Status: " + textStatus + "; Error: " + errorThrown );
$("html").removeClass("wait");
$("body").css("cursor", "default");
},
});
console.log("Setting default cursor");
}
```