Skip to content

Update renamerOnUpdate#20

Merged
WithoutPants merged 14 commits intostashapp:mainfrom
Belleyy:patch-9
Nov 2, 2021
Merged

Update renamerOnUpdate#20
WithoutPants merged 14 commits intostashapp:mainfrom
Belleyy:patch-9

Conversation

@Belleyy
Copy link
Copy Markdown
Contributor

@Belleyy Belleyy commented Oct 26, 2021

  • Adding config, no longer need to edit the python directly
  • Option:
    • Ignore male performer.
    • Allow the use of a different separator for Performer instead of space currently.
    • Only rename Organized scene; (Only rename organized ones #17)
    • Other things, look the config.
  • More Field:
    • $video_codec
    • $audio_codec
    • $studio_family
    • $resolution
    • $year

Edit: Close #18 (My update include the config). Thanks to jthrow0451 for the idea :)

@bnkai
Copy link
Copy Markdown
Collaborator

bnkai commented Oct 26, 2021

* Can trigger fake update on your scene to trigger the plugin. 

Just a warning for this functionality. Trigerring the above will make all the post update plugins run. I don't think there are [m]any atm :-) but it could be an issue later on. I think you should warn users or even better defer that to a separate tasks plugins as that can run without triggering anything since your changes are directly to the db and not through stash.

Comment thread plugins/renamerOnUpdate/README.md Outdated
Comment thread plugins/renamerOnUpdate/README.md Outdated
Comment thread plugins/renamerOnUpdate/README.md Outdated
> Note: The priority is Tag > Studio > Default

If you only want change 1 tag:
The config will be:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configuration sample: ?
Not sure for this one....

Comment thread plugins/renamerOnUpdate/README.md Outdated
Comment thread plugins/renamerOnUpdate/README.md Outdated
Comment thread plugins/renamerOnUpdate/README.md Outdated
Comment thread plugins/renamerOnUpdate/config.py Outdated
Comment thread plugins/renamerOnUpdate/config.py Outdated
Comment thread plugins/renamerOnUpdate/config.py Outdated
Comment thread plugins/renamerOnUpdate/config.py Outdated
Comment thread plugins/renamerOnUpdate/config.py Outdated
Comment thread plugins/renamerOnUpdate/config.py Outdated
Comment thread plugins/renamerOnUpdate/config.py Outdated
Comment thread plugins/renamerOnUpdate/config.py Outdated
Comment thread plugins/renamerOnUpdate/renamerOnUpdate.yml Outdated
Also adding warning for unidecode module if non latin
@Belleyy Belleyy marked this pull request as ready for review October 27, 2021 14:58
Comment thread plugins/renamerOnUpdate/renamerOnUpdate.py Outdated
@bnkai
Copy link
Copy Markdown
Collaborator

bnkai commented Nov 1, 2021

Fixed some typos and removed unneeded parts from the queries ( i dont think i broke anything from a few tests i did)
Seems to work ok

diff --git a/plugins/renamerOnUpdate/renamerOnUpdate.py b/plugins/renamerOnUpdate/renamerOnUpdate.py
index 5a8beb9..e4105f8 100644
--- a/plugins/renamerOnUpdate/renamerOnUpdate.py
+++ b/plugins/renamerOnUpdate/renamerOnUpdate.py
@@ -37,9 +37,9 @@ if FRAGMENT_SCENE_ID:
 PLUGIN_ARGS = FRAGMENT['args'].get("mode")
 
 if PLUGIN_ARGS:
-    log.LogDebug("--Starting Plugin 'Renammer'--")
+    log.LogDebug("--Starting Plugin 'Renamer'--")
 else:
-    log.LogDebug("--Starting Hook 'Renammer'--")
+    log.LogDebug("--Starting Hook 'Renamer'--")
 
 #log.LogDebug("{}".format(FRAGMENT))
 
@@ -94,37 +94,19 @@ def graphql_getScene(scene_id):
     }
     fragment SceneData on Scene {
         id
-        checksum
-        oshash
         title
-        details
-        url
         date
-        rating
-        o_counter
         organized
         path
-        phash
-        interactive
         file {
-            size
-            duration
             video_codec
             audio_codec
             width
             height
-            framerate
-            bitrate
         }
         studio {
             ...SlimStudioData
         }
-        movies {
-            movie {
-            ...MovieData
-            }
-            scene_index
-        }
         tags {
             ...SlimTagData
         }
@@ -139,23 +121,7 @@ def graphql_getScene(scene_id):
             id
             name
         }
-        details
-        rating
-        aliases
-    }
-    fragment MovieData on Movie {
-        id
-        checksum
-        name
         aliases
-        date
-        rating
-        director
-        studio {
-            ...SlimStudioData
-        }
-        synopsis
-        url
     }
     fragment SlimTagData on Tag {
         id
@@ -164,32 +130,8 @@ def graphql_getScene(scene_id):
     }
     fragment PerformerData on Performer {
         id
-        checksum
         name
-        url
-        gender
-        twitter
-        instagram
-        birthdate
-        ethnicity
-        country
-        eye_color
-        height
-        measurements
-        fake_tits
-        career_length
-        tattoos
-        piercings
         aliases
-        favorite
-        tags {
-            ...SlimTagData
-        }
-        rating
-        details
-        death_date
-        hair_color
-        weight
     }
     """
     variables = {
@@ -225,39 +167,14 @@ def graphql_findScene(perPage,direc="DESC"):
     }
     fragment SlimSceneData on Scene {
         id
-        checksum
-        oshash
         title
-        details
-        url
         date
-        rating
-        o_counter
         organized
         path
-        phash
-        interactive
-        scene_markers {
-            id
-            title
-            seconds
-        }
-        galleries {
-            id
-            path
-            title
-        }
         studio {
             id
             name
         }
-        movies {
-            movie {
-                id
-                name
-            }
-            scene_index
-        }
         tags {
             id
             name
@@ -265,8 +182,6 @@ def graphql_findScene(perPage,direc="DESC"):
         performers {
             id
             name
-            gender
-            favorite
         }
     }
     """
@@ -490,10 +405,10 @@ else:
 # Replace the old filename by the new in the filepath
 new_path = current_path.rstrip(current_filename) + new_filename
 
-# Trying to prevent error with long path for Win10
+# Trying to prevent error with long paths for Win10
 # https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd
 if len(new_path) > 240:
-    log.LogWarning("The Path is too long ({})...".format(len(new_path)))
+    log.LogWarning("Resulting Path is too long ({})...".format(len(new_path)))
     for word in ORDER_SHORTFIELD:
         if word not in filename_template:
             continue
@@ -505,13 +420,13 @@ if len(new_path) > 240:
             log.LogInfo("Reduced filename to: {}".format(new_filename))
             break
     if len(new_path) > 240:
-        exit_plugin(err="Can't manage to reduce the path, operation aborted.")
+        exit_plugin(err="Can't shorten path, operation aborted.")
 
 #log.LogDebug("Filename: {} -> {}".format(current_filename,new_filename))
 #log.LogDebug("Path: {} -> {}".format(current_path,new_path))
 
 if (new_path == current_path):
-    exit_plugin("Filename already correct. ({})".format(current_filename))
+    exit_plugin("Filename already ok. ({})".format(current_filename))
 
 if ALT_DIFF_DISPLAY:
     find_diff_text(current_filename,new_filename)
@@ -533,14 +448,14 @@ cursor.execute("SELECT id FROM scenes WHERE path LIKE ? AND NOT id=?;", ["%" + f
 dupl_check = cursor.fetchall()
 if len(dupl_check) > 0:
     for dupl_row in dupl_check:
-        log.LogError("Same path: [{}]".format(dupl_row[0]))
+        log.LogError("Identical path: [{}]".format(dupl_row[0]))
     exit_plugin(err="Duplicate path detected, check log!")
 
 cursor.execute("SELECT id FROM scenes WHERE path LIKE ? AND NOT id=?;", ["%" + new_filename, FRAGMENT_SCENE_ID])
 dupl_check = cursor.fetchall()
 if len(dupl_check) > 0:
     for dupl_row in dupl_check:
-        log.LogInfo("Same filename: [{}]".format(dupl_row[0]))
+        log.LogInfo("Duplicate filename: [{}]".format(dupl_row[0]))
 
 # OS Rename
 if (os.path.isfile(current_path) == True):
@@ -548,20 +463,20 @@ if (os.path.isfile(current_path) == True):
         os.rename(current_path, new_path)
     except PermissionError as err:
         if "[WinError 32]" in str(err) and MODULE_PSUTIL:
-            log.LogWarning("A process use this file, trying to find it (Probably FFMPEG)")
-            # Find what process access the file, it's ffmpeg for sure...
+            log.LogWarning("A process is using this file (Probably FFMPEG), trying to find it ...")
+            # Find which process accesses the file, it's ffmpeg for sure...
             process_use = has_handle(current_path, PROCESS_ALLRESULT)
             if process_use:
                 # Terminate the process then try again to rename
-                log.LogDebug("Process that use this file: {}".format(process_use))
+                log.LogDebug("Process that uses this file: {}".format(process_use))
                 if PROCESS_KILL:
                     p = psutil.Process(process_use.pid)
                     p.terminate()
                     p.wait(10)
-                    # If we don't manage to close it, this will create a error again.
+                    # If process is not terminated, this will create an error again.
                     os.rename(current_path, new_path)
                 else:
-                    exit_plugin(err="A process prevent editing the file.")
+                    exit_plugin(err="A process prevents renaming the file.")
         else:
             log.LogError(err)
             sys.exit()
@@ -572,9 +487,9 @@ if (os.path.isfile(current_path) == True):
                 f.write("{}|{}|{}\n".format(FRAGMENT_SCENE_ID, current_path, new_path))
     else:
         # I don't think it's possible. 
-        exit_plugin(err="[OS] File failed to rename ? {}".format(new_path))
+        exit_plugin(err="[OS] Failed to rename the file ? {}".format(new_path))
 else:
-    exit_plugin(err="[OS] File don't exist in your Disk/Drive ({})".format(current_path))
+    exit_plugin(err="[OS] File doesn't exist in your Disk/Drive ({})".format(current_path))
 
 # Database rename
 cursor.execute("UPDATE scenes SET path=? WHERE id=?;", [new_path, FRAGMENT_SCENE_ID])

review by Bnkai
@WithoutPants WithoutPants merged commit 975d179 into stashapp:main Nov 2, 2021
@Tscherno
Copy link
Copy Markdown
Contributor

Tscherno commented Nov 9, 2021

Hmh somehow it gives me a strange error:
021-11-09 19:51:14Error error executing post hooks: error running plugin: fork/exec /root/.stash/plugins/renamerOnUpdate/root/.stash/plugins/renamerOnUpdate/root/.stash/plugins/renamerOnUpdate/root/.stash/plugins/renamerOnUpdate/python: no such file or directory

@Belleyy Belleyy deleted the patch-9 branch September 15, 2022 15:48
Stash-KennyG pushed a commit to Stash-KennyG/CommunityScripts that referenced this pull request Apr 8, 2026
* Create config.py

* Update renamerOnUpdate.yml

* Update renamerOnUpdate.py

* Update README.md

* Update README.md

* Update config.py

* correct by Bnkai

* Update config.py

Also adding warning for unidecode module if non latin

* removing task

* removing task

* remove task from readme

* using len instead of removing 1 character

* Update renamerOnUpdate.py

* Update renamerOnUpdate.py

review by Bnkai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants