CommunityScripts icon indicating copy to clipboard operation
CommunityScripts copied to clipboard

[renamerOnUpdate] Consolidate similar elements; Call replace_words and field_replacer elements earlier in the sanitization process

Open echo6ix opened this issue 2 years ago • 1 comments

There are similar elements such as filename_splitchar, field_whitespaceSeperator, removecharac_Filename, and prepositions_list that are all essentially replacing a string pattern with a string replacement. Conceptually, these things could be done with both replace_words and field_replacer, but both of the latter elements seem to be called late in the filename sanitization process.

Since this plugin can be a bit confusing with all the elements, we can simplify it by purging similar elements in favor of replace_words and field_replacer.

replace_words = {

    #Replacement for field_whitespaceSeperator
    "\s+": ["-", "regex"],

    #Replacement for removecharac_Filename
    "(`|~|!|@|#|$|%|^|&|*|\(|\)|+|=|\[|\]|{|}|\<|\>|,|;|:|\"|\'|)": ["", "regex"],

    #Replace slashes with dash
    "(\\|\/)": ["-", "regex"]
}

I also think it would be more robust to make field_replacer use regex like the replace_words function. As a consequence now elements like prepositions_list would also become unnecessary,

# Exammple usage:
# "$field": {"regex": "pattern", "replacement"},
# "$field": {"word": "pattern", "replacement"},

field_replacer = {

    #Replacement for prepositions_list
    "$title": {"regex": "^(A|An|The) ", ""}
}

echo6ix avatar Feb 26 '23 19:02 echo6ix

Also, if this is desirable I would leave the above example regex in the config by default (but commented), since "features" would be be removed, so users could easily add the functionality back if they wanted.

replace_words = {

    #Replacement for field_whitespaceSeperator
    #"\s+": ["-", "regex"],

    #Replacement for removecharac_Filename
    #"(`|~|!|@|#|$|%|^|&|*|\(|\)|+|=|\[|\]|{|}|\<|\>|,|;|:|\"|\'|)": ["", "regex"],

}

field_replacer = {

    #Replacement for prepositions_list
    #"$title": {"regex": "^(A|An|The) ", ""}
}

echo6ix avatar Feb 26 '23 19:02 echo6ix