forked from Github/Axter-Stash
First draft 0.1
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
# RenameFileName:
|
# RenameFile:
|
||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
|
||||||
`pip install stashapp-tools`
|
`pip install stashapp-tools`
|
||||||
`pip install pyYAML`
|
`pip install pyYAML`
|
||||||
|
|
||||||
### Using RenameFileName
|
### Using RenameFile
|
||||||
`*Note: Changes are made when a scene edit is saved.`
|
`*Note: Changes are made when a scene edit is saved.`
|
||||||
Renames video (scene) file names when the user edits the [Title] field located in the scene [Edit] tab.
|
Renames video (scene) file names when the user edits the [Title] field located in the scene [Edit] tab.
|
||||||
The file is renamed after user clicks save button.
|
The file is renamed after user clicks save button.
|
||||||
Tags are appended to the file name if the tag does not already exist in the original file name.When you have installed the `RenameFileName` plugin, hop into your plugins directory, RenameFileName folder > open renamefilename_settings.py with your favorite code/text editor and you'll see this:
|
Tags are appended to the file name if the tag does not already exist in the original file name.When you have installed the `RenameFile` plugin, hop into your plugins directory, RenameFile folder > open renamefile_settings.py with your favorite code/text editor and you'll see this:
|
||||||
Features are configurable using the renamefilename_settings.py.
|
Features are configurable using the renamefile_settings.py.
|
||||||
Note: On Windows OS, the file can not be renamed while it's playing. Refresh the URL to allow file release and rename.
|
Note: On Windows OS, the file can not be renamed while it's playing. Refresh the URL to allow file release and rename.
|
||||||
Binary file not shown.
13136
plugins/RenameFile/renamefile.log
Normal file
13136
plugins/RenameFile/renamefile.log
Normal file
File diff suppressed because it is too large
Load Diff
@@ -5,21 +5,23 @@ import shutil
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
# This is a Stash plugin which allows users to rename the video (scene) file name by editing the [Title] field located in the scene [Edit] tab.
|
||||||
|
|
||||||
# Importing stashapi.log as log for critical events
|
# Importing stashapi.log as log for critical events
|
||||||
import stashapi.log as log
|
import stashapi.log as log
|
||||||
|
|
||||||
# Import settings from renamefilename_settings.py
|
# Import settings from renamefile_settings.py
|
||||||
from renamefilename_settings import config
|
from renamefile_settings import config
|
||||||
|
|
||||||
# Get the directory of the script
|
# Get the directory of the script
|
||||||
script_dir = Path(__file__).resolve().parent
|
script_dir = Path(__file__).resolve().parent
|
||||||
|
|
||||||
# Configure logging for your script
|
# Configure logging for your script
|
||||||
log_file_path = script_dir / 'renamefilename.log'
|
log_file_path = script_dir / 'renamefile.log'
|
||||||
logging.basicConfig(filename=log_file_path, level=logging.INFO, format='%(asctime)s - %(message)s')
|
logging.basicConfig(filename=log_file_path, level=logging.INFO, format='%(asctime)s - %(message)s')
|
||||||
logger = logging.getLogger('renamefilename')
|
logger = logging.getLogger('renamefile')
|
||||||
|
|
||||||
endpoint = config.get("graphql_endpoint") # GraphQL endpoint; Update via renamefilename_settings.py
|
endpoint = config.get("graphql_endpoint") # GraphQL endpoint; Update via renamefile_settings.py
|
||||||
|
|
||||||
# GraphQL query to fetch all scenes
|
# GraphQL query to fetch all scenes
|
||||||
query_all_scenes = """
|
query_all_scenes = """
|
||||||
@@ -59,7 +61,7 @@ def form_filename(original_file_stem, scene_details, wrapper_styles, separator,
|
|||||||
tag_keys_added = 0
|
tag_keys_added = 0
|
||||||
default_title = ''
|
default_title = ''
|
||||||
if_notitle_use_org_filename = config["if_notitle_use_org_filename"]
|
if_notitle_use_org_filename = config["if_notitle_use_org_filename"]
|
||||||
add_tag_if_not_in_name = config["add_tag_if_not_in_name"]
|
exclude_tag_if_in_name = config["exclude_tag_if_in_name"]
|
||||||
if if_notitle_use_org_filename:
|
if if_notitle_use_org_filename:
|
||||||
default_title = original_file_stem
|
default_title = original_file_stem
|
||||||
|
|
||||||
@@ -138,7 +140,7 @@ def form_filename(original_file_stem, scene_details, wrapper_styles, separator,
|
|||||||
elif key == 'tags':
|
elif key == 'tags':
|
||||||
tags = [tag.get('name', '') for tag in scene_details.get('tags', [])]
|
tags = [tag.get('name', '') for tag in scene_details.get('tags', [])]
|
||||||
for tag_name in tags:
|
for tag_name in tags:
|
||||||
if not add_tag_if_not_in_name or tag_name.lower() not in original_file_stem.lower():
|
if not exclude_tag_if_in_name or tag_name.lower() not in original_file_stem.lower():
|
||||||
add_tag(tag_name)
|
add_tag(tag_name)
|
||||||
|
|
||||||
new_filename = separator.join(filename_parts).replace('--', '-')
|
new_filename = separator.join(filename_parts).replace('--', '-')
|
||||||
@@ -304,6 +306,7 @@ def rename_scene(scene_id, wrapper_styles, separator, key_order, stash_directory
|
|||||||
metadata_scan_path = original_parent_directory
|
metadata_scan_path = original_parent_directory
|
||||||
perform_metadata_scan(metadata_scan_path)
|
perform_metadata_scan(metadata_scan_path)
|
||||||
|
|
||||||
|
# ToDo: Add logic to the below code section so it checks base file length and checks folder length, instead of lumping them altogether.
|
||||||
# Current DB schema allows file folder max length to be 255, and max base filename to be 255
|
# Current DB schema allows file folder max length to be 255, and max base filename to be 255
|
||||||
max_filename_length = int(config["max_filename_length"])
|
max_filename_length = int(config["max_filename_length"])
|
||||||
if len(new_filename) > max_filename_length:
|
if len(new_filename) > max_filename_length:
|
||||||
@@ -338,10 +341,10 @@ wrapper_styles = config["wrapper_styles"]
|
|||||||
separator = config["separator"]
|
separator = config["separator"]
|
||||||
key_order = config["key_order"]
|
key_order = config["key_order"]
|
||||||
|
|
||||||
# Read stash directory from renamefilename_settings.py
|
# Read stash directory from renamefile_settings.py
|
||||||
stash_directory = config.get('stash_directory', '')
|
stash_directory = config.get('stash_directory', '')
|
||||||
|
|
||||||
# Extract rename_files and move_files settings from renamefilename_settings.py
|
# Extract rename_files and move_files settings from renamefile_settings.py
|
||||||
rename_files_setting = config["rename_files"]
|
rename_files_setting = config["rename_files"]
|
||||||
move_files_setting = config["move_files"]
|
move_files_setting = config["move_files"]
|
||||||
|
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
name: RenameFileName
|
name: RenameFile
|
||||||
description: "Renames video (scene) file names when the user edits the [Title] field located in the scene [Edit] tab.
|
description: "Renames video (scene) file names when the user edits the [Title] field located in the scene [Edit] tab.
|
||||||
The file is renamed after user clicks save button.
|
The file is renamed after user clicks save button.
|
||||||
Tags are appended to the file name if the tag does not already exist in the original file name.
|
Tags are appended to the file name if the tag does not already exist in the original file name.
|
||||||
Features are configurable using the renamefilename_settings.py.
|
Features are configurable using the renamefile_settings.py.
|
||||||
Note: On Windows OS, the file can not be renamed while it's playing. Refresh the URL to allow file release and rename."
|
Note: On Windows OS, the file can not be renamed while it's playing. Refresh the URL to allow file release and rename."
|
||||||
version: 0.1
|
version: 0.1
|
||||||
url: https://github.com/David-Maisonave/Axter-Stash
|
url: https://github.com/David-Maisonave/Axter-Stash
|
||||||
exec:
|
exec:
|
||||||
- python
|
- python
|
||||||
- "{pluginDir}/renamefilename.py"
|
- "{pluginDir}/renamefile.py"
|
||||||
interface: raw
|
interface: raw
|
||||||
hooks:
|
hooks:
|
||||||
- name: RenameFiles
|
- name: RenameFiles
|
||||||
@@ -28,7 +28,6 @@ config = {
|
|||||||
"frame_rate",
|
"frame_rate",
|
||||||
"tags"
|
"tags"
|
||||||
],
|
],
|
||||||
# Define keys to exclude from the formed filename
|
|
||||||
# Specify keys to exclude from the filename formation process. (ie. "exclude_keys": ["studio", "date"],)
|
# Specify keys to exclude from the filename formation process. (ie. "exclude_keys": ["studio", "date"],)
|
||||||
"exclude_keys": ["studio", "performers", "date", "height", "video_codec", "frame_rate"],
|
"exclude_keys": ["studio", "performers", "date", "height", "video_codec", "frame_rate"],
|
||||||
# Define whether files should be moved when renaming
|
# Define whether files should be moved when renaming
|
||||||
@@ -39,16 +38,14 @@ config = {
|
|||||||
"dry_run": False,
|
"dry_run": False,
|
||||||
# Define whether the original file name should be used if title is empty
|
# Define whether the original file name should be used if title is empty
|
||||||
"if_notitle_use_org_filename": True,
|
"if_notitle_use_org_filename": True,
|
||||||
# Define whether to add tag only if tag is not in file name
|
# Define whether to exclude the tag if the tag is already in the file name
|
||||||
"add_tag_if_not_in_name": True,
|
"exclude_tag_if_in_name": True, # Warning: If set to False, could end up having duplicate tags in file name
|
||||||
# Define whether to rename all files missing tag names, or only the latest scene having an update
|
|
||||||
# "rename_all_files": True,
|
|
||||||
# Define the maximum number of tag keys to include in the filename (None for no limit)
|
# Define the maximum number of tag keys to include in the filename (None for no limit)
|
||||||
"max_tag_keys": 12,
|
"max_tag_keys": 12,
|
||||||
# Current Stash DB schema only allows maximum base file name length to be 255
|
# Current Stash DB schema only allows maximum base file name length to be 255
|
||||||
"max_filename_length": 255,
|
"max_filename_length": 255,
|
||||||
"max_filefolder_length": 255, # For future useage
|
# "max_filefolder_length": 255, # For future useage
|
||||||
"max_filebase_length": 255, # For future useage
|
# "max_filebase_length": 255, # For future useage
|
||||||
# GraphQL endpoint
|
# GraphQL endpoint
|
||||||
"graphql_endpoint": "http://localhost:9999/graphql", # Update with your endpoint
|
"graphql_endpoint": "http://localhost:9999/graphql", # Update with your endpoint
|
||||||
# Define a whitelist of allowed tags or (None to allow all tags)
|
# Define a whitelist of allowed tags or (None to allow all tags)
|
||||||
Reference in New Issue
Block a user