Skip to content

Commit

Permalink
Merge pull request #204 from scruffynerf/RoUStopgap
Browse files Browse the repository at this point in the history
v2.5.0 - limited changes to work with Stash v24 - STOPGAP RELEASE
  • Loading branch information
scruffynerf authored Jan 1, 2024
2 parents bf62a6c + be5a4dc commit 32369d1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
16 changes: 13 additions & 3 deletions plugins/renamerOnUpdate/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# *renamerOnUpdate*
Using metadata from your Stash to rename/move your file.

# WARNING - This is a stopgap release
It is labeled 2.5.0, to fill the gap until v3.0 is released
It is NOT heavily tested, with the bare minimum needed to work with Stash v24
Version 3 is a major rewrite, but since it's not quite ready, pushing 2.5.0 seems necessary
It worked for me, using my old config, and I got no errors during my limited tests.
YOU HAVE BEEN WARNED - any potential data loss is on you.
BEFORE YOU USE IT TO MOVE/RENAME ANYTHING CRITICAL, test it yourself.
I still suggest you wait for v3, but... if you can't, this is now out.

All credit to Belley for all of his work over the years... and v3 is coming soon

## Table of Contents

- [*renamerOnUpdate*](#renameronupdate)
Expand Down Expand Up @@ -33,10 +44,9 @@ Using metadata from your Stash to rename/move your file.
- [*performer_limit*](#performer_limit)

# Requirement
- Stash (v0.15+)
- Python 3.6+ (Tested on Python v3.9.1 64bit, Win10)
- Stash (v0.24+)
- Python 3.6+ (Tested LIGHTLY on Python v3.11 Linux)
- Request Module (https://pypi.org/project/requests/)
- Tested on Windows 10/Synology/docker.

# Installation

Expand Down
35 changes: 18 additions & 17 deletions plugins/renamerOnUpdate/renamerOnUpdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,9 @@ def graphql_getScene(scene_id):
}
fragment SceneData on Scene {
id
oshash
checksum
title
date
rating
rating100
stash_ids {
endpoint
stash_id
Expand All @@ -133,7 +131,7 @@ def graphql_getScene(scene_id):
name
gender
favorite
rating
rating100
stash_ids{
endpoint
stash_id
Expand Down Expand Up @@ -168,11 +166,9 @@ def graphql_findScene(perPage, direc="DESC") -> dict:
}
fragment SlimSceneData on Scene {
id
oshash
checksum
title
date
rating
rating100
organized
stash_ids {
endpoint
Expand All @@ -196,7 +192,7 @@ def graphql_findScene(perPage, direc="DESC") -> dict:
name
gender
favorite
rating
rating100
stash_ids{
endpoint
stash_id
Expand Down Expand Up @@ -467,7 +463,7 @@ def extract_info(scene: dict, template: None):
# note: basename contains the extension
scene_information['current_filename'] = os.path.basename(scene_information['current_path'])
scene_information['current_directory'] = os.path.dirname(scene_information['current_path'])
scene_information['oshash'] = scene['oshash']
scene_information['oshash'] = scene.get("oshash")
scene_information['checksum'] = scene.get("checksum")
scene_information['studio_code'] = scene.get("code")

Expand Down Expand Up @@ -506,8 +502,8 @@ def extract_info(scene: dict, template: None):
scene_information['duration'] = str(scene_information['duration'])

# Grab Rating
if scene.get("rating"):
scene_information['rating'] = RATING_FORMAT.format(scene['rating'])
if scene.get("rating100"):
scene_information['rating'] = RATING_FORMAT.format(scene['rating100'])

# Grab Performer
scene_information['performer_path'] = None
Expand All @@ -527,10 +523,10 @@ def extract_info(scene: dict, template: None):
if "inverse_performer" in template["path"]["option"]:
perf["name"] = re.sub(r"([a-zA-Z]+)(\s)([a-zA-Z]+)", r"\3 \1", perf["name"])
perf_list.append(perf['name'])
if perf.get('rating'):
if perf_rating.get(str(perf['rating'])) is None:
perf_rating[str(perf['rating'])] = []
perf_rating[str(perf['rating'])].append(perf['name'])
if perf.get('rating100'):
if perf_rating.get(str(perf['rating100'])) is None:
perf_rating[str(perf['rating100'])] = []
perf_rating[str(perf['rating100'])].append(perf['name'])
else:
perf_rating["0"].append(perf['name'])
if perf.get('favorite'):
Expand Down Expand Up @@ -630,7 +626,7 @@ def extract_info(scene: dict, template: None):
scene_information['tags'] = TAGS_SPLITCHAR.join(tag_list)

# Grab Height (720p,1080p,4k...)
scene_information['bitrate'] = str(round(int(scene['file']['bitrate']) / 1000000, 2))
scene_information['bit_rate'] = str(round(int(scene['file']['bit_rate']) / 1000000, 2))
scene_information['resolution'] = 'SD'
scene_information['height'] = f"{scene['file']['height']}p"
if scene['file']['height'] >= 720:
Expand Down Expand Up @@ -1068,10 +1064,12 @@ def renamer(scene_id, db_conn=None):
stash_scene["oshash"] = f["oshash"]
if f.get("md5"):
stash_scene["checksum"] = f["md5"]
if f.get("checksum"):
stash_scene["checksum"] = f["checksum"]
stash_scene["path"] = scene_file["path"]
stash_scene["file"] = scene_file
if scene_file.get("bit_rate"):
stash_scene["file"]["bitrate"] = scene_file["bit_rate"]
stash_scene["file"]["bit_rate"] = scene_file["bit_rate"]
if scene_file.get("frame_rate"):
stash_scene["file"]["framerate"] = scene_file["frame_rate"]

Expand Down Expand Up @@ -1318,6 +1316,9 @@ def exit_plugin(msg=None, err=None):
frame_rate
duration
bit_rate
phash: fingerprint(type: "phash")
oshash: fingerprint(type: "oshash")
checksum: fingerprint(type: "checksum")
fingerprints {
type
value
Expand Down
2 changes: 1 addition & 1 deletion plugins/renamerOnUpdate/renamerOnUpdate.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: renamerOnUpdate
description: Rename/move filename based on a template.
url: https://github.com/stashapp/CommunityScripts
version: 2.4.4
version: 2.5.0
exec:
- python
- "{pluginDir}/renamerOnUpdate.py"
Expand Down

0 comments on commit 32369d1

Please sign in to comment.