Belleyy / Stash-Renamer-Python

Use your database (Sqlite) to rename file. Made for Stash.
10 stars 2 forks source link
database python

:exclamation: MOVED TO https://github.com/stashapp/CommunityScripts :exclamation:

SQLITE Renamer for Stash

Using metadata from your database (SQLITE) to rename your file.

:exclamation: Important :exclamation:

By doing this, you will make definitive change to your Database and Files!

(You can have a logfile (USING_LOG), so you can probably revert everything...)

Requirement

Usage

First Run

Set USE_DRY to True (Line 11), by doing this nothing will be changed.

You can uncomment the break (Line 232), so it will stop after the first file.

Filename template

Available: $date $performer $title $studio $height

The script will replace these field with the data from the database. Exemple: Template Result
$title Her Fantasy Ball.mp4
$title $height Her Fantasy Ball 1080p.mp4
$date $title 2016-12-29 Her Fantasy Ball.mp4
$date $performer - $title [$studio] 2016-12-29 Eva Lovia - Her Fantasy Ball [Sneaky Sex].mp4

Note:

Change scenes by tags

If you want differents formats by tags. Create a dict with tag (The name of the tag in Stash) & filename (Filename template)

tags_dict = {
    '1': {
        'tag': '1. JAV',
        'filename': '$title'
    },
    '2': {
        'tag': '1. Anime',
        'filename': '$date $title'
    }
}

for _, dict_section in tags_dict.items():
    tag_name = dict_section.get("tag")
    filename_template = dict_section.get("filename")
    id_tags = gettingTagsID(tag_name)
    if id_tags is not None:
        id_scene = get_SceneID_fromTags(id_tags)
        option_sqlite_query = "WHERE id in ({})".format(id_scene)
        edit_db(filename_template,option_sqlite_query)
        print("====================")

If you only want change 1 tag:

id_tags = gettingTagsID('1. JAV')
if id_tags is not None:
    id_scene = get_SceneID_fromTags(id_tags)
    option_sqlite_query = "WHERE id in ({})".format(id_scene)
    edit_db("$date $performer - $title [$studio]",option_sqlite_query)

Change all scenes

edit_db("$date $performer - $title [$studio]")

Optional SQLITE

If you only want change a specific path, use the second parameter to edit_db(), it will add it to the sqlite query. (Documentation ?)

Exemple (Only take file that have the path E:\\Film\\R18):

option_sqlite_query = "WHERE path LIKE 'E:\\Film\\R18\\%'"
edit_db("$date $performer - $title [$studio]",option_sqlite_query)