stashapp / CommunityScripts

This is a public repository containing plugin and utility scripts created by the Stash Community.
https://docs.stashapp.cc/add-ons/
GNU Affero General Public License v3.0
191 stars 147 forks source link

[renamerOnUpdate][Feature] Remove Non Ascii/Emojis #452

Open C-BoT-AU opened 1 month ago

C-BoT-AU commented 1 month ago

I have been having some issues with emoji's and similar characters in filenames on my system. I usually search these out using a regex search for [^\x20-\x7E\n\t\r] so wanted to include that in the renamerOnUpdate script to remove. Unfortunately, after numerous ways of trying to add it to the removecharac_Filename variable, I gave up and inserted it into the main renamerOnUpdate.py at line 942:

    # Remove illegal character for Windows
    new_filename = re.sub('[\\/:"*?<>|]+', "", new_filename)
    new_filename = re.sub(r"[^\x20-\x7E\n\t\r]+", "", new_filename) # Remove non Ascii characters

There may be a cleaner/better way to do this, or to include it in the removecharac_Filename variable, but for now this was the simplest way I could think of. It could be standardised by adding a removeNonAscii TRUE/FALSE variable to the config that then embeds this rename in another if statement.

I'm unsure if the if MODULE_UNIDECODE and UNICODE_USE: at line 947 is meant to do this or something else. The warnings made me not try it.