From 3e26a114dad9485bae69c13dffbe617515be6cab Mon Sep 17 00:00:00 2001 From: o-fl0w Date: Mon, 26 Sep 2022 01:36:55 +0200 Subject: [PATCH 1/3] titleDiff plugin: Tag Scenes where title differs from filename --- plugins/titleDiff/README.md | 7 ++++ plugins/titleDiff/titleDiff.js | 73 +++++++++++++++++++++++++++++++++ plugins/titleDiff/titleDiff.yml | 12 ++++++ 3 files changed, 92 insertions(+) create mode 100644 plugins/titleDiff/README.md create mode 100644 plugins/titleDiff/titleDiff.js create mode 100644 plugins/titleDiff/titleDiff.yml diff --git a/plugins/titleDiff/README.md b/plugins/titleDiff/README.md new file mode 100644 index 00000000..044c1dfd --- /dev/null +++ b/plugins/titleDiff/README.md @@ -0,0 +1,7 @@ +# Title Diff +Compare scene title to filename (with and without extension) and if they differ tag the scene with a special tag. +The tag will be created if not found. + +# Configuration +Set `TAG_NAME` in `titleDiff.js` to change name of the tag used to tag scenes. +Defaults to `_titleDiff` \ No newline at end of file diff --git a/plugins/titleDiff/titleDiff.js b/plugins/titleDiff/titleDiff.js new file mode 100644 index 00000000..ecdbff1d --- /dev/null +++ b/plugins/titleDiff/titleDiff.js @@ -0,0 +1,73 @@ +var TAG_NAME = "_titleDiff" // Name of tag to set when scene title differs from filename, will create if not found + + +function main() { + switch (input.Args.mode) { + case "diff": + diff() + } +} + +function diff() { + log.Info("diff: Begin diff title/filename") + var sceneIds = findDiffingScenes() + var tagId = getOrCreateTag() + var n = setTag(sceneIds, [tagId]) + + log.Info("diff: Number of scenes found with differing title/filename: " + n) +} + +function findDiffingScenes() { + var query = "{findScenes(filter:{per_page:-1}){scenes{id title path}}}" + var result = gql.Do(query) + if (result.findScenes == null) { + log.Info("diff: No scenes found") + return + } + var scenes = result.findScenes.scenes + var diffs = [] + for (var i = 0; i < scenes.length; i++) { + var filename = scenes[i].path.split(/.*[\/|\\]/)[1]; + var filenameNoExt = filename.replace(/\.[^/.]+$/, "") + if (scenes[i].title !== filename && scenes[i].title !== filenameNoExt) { + log.Debug("diff: Id=" + scenes[i].id + " Title='" + scenes[i].title + "' Filename='" + filename + "'") + diffs.push(scenes[i].id) + } + } + return diffs +} + +function getOrCreateTag() { + var query = "query FindTag($name: String!){\ + findTags(tag_filter:{name:{value:$name, modifier:EQUALS}}){tags{id}}}" + + var result = gql.Do(query, {name: TAG_NAME}) + if (result.findTags == null) { + log.Warn("diff: No tags?") + return + } + if (result.findTags.tags.length === 0) { + log.Debug("diff: Tag not found, creating...") + return createTag() + } else { + return result.findTags.tags[0].id + } +} + +function createTag() { + var query = "mutation CreateTag($name: String!){tagCreate(input:{name:$name}){id}}" + var result = gql.Do(query, {name: TAG_NAME}) + log.Debug("diff: Tag created Id='" + result.tagCreate.id + "' name='" + TAG_NAME + "'") + return result.tagCreate.id +} + +function setTag(sceneIds, tagIds) { + var query = "mutation BulkSceneSetTag($scene_ids: [ID!], $tag_ids: [ID!]){\ + bulkSceneUpdate(input:{ids: $scene_ids, tag_ids:{ids: $tag_ids, mode:ADD}}){id}}" + + var result = gql.Do(query, {scene_ids: sceneIds, tag_ids: tagIds}) + log.Debug(result) + return result.bulkSceneUpdate.length +} + +main() \ No newline at end of file diff --git a/plugins/titleDiff/titleDiff.yml b/plugins/titleDiff/titleDiff.yml new file mode 100644 index 00000000..3a46c786 --- /dev/null +++ b/plugins/titleDiff/titleDiff.yml @@ -0,0 +1,12 @@ +name: titleDiff +description: Tag Scenes where scene title differs from filename +url: https://github.com/stashapp/CommunityScripts +version: 1.0 +exec: + - titleDiff.js +interface: js +tasks: + - name: Diff title <-> filename + description: 'Run' + defaultArgs: + mode: diff From 19b924172ee16c5f3c92a910cf62ff3339b1c303 Mon Sep 17 00:00:00 2001 From: o-fl0w Date: Mon, 26 Sep 2022 01:38:46 +0200 Subject: [PATCH 2/3] titleDiff: README.md --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 84d9ea41..256ad296 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,8 @@ StashDB |[StashDB Submission Helper](/userscripts/StashDB_Submission_Helper)|Ad ## Utility Scripts -Category|Plugin Name|Description|Minimum Stash version ---------|-----------|-----------|--------------------- -Kodi|[Kodi Helper](scripts/kodi-helper)|Generates `nfo` and `strm` for use with Kodi.|v0.7 -Maintenance|[Stash Sqlite Renamer](scripts/Sqlite_Renamer)|Renames your files using stash's metadata.|v0.7 +Category| Plugin Name | Description |Minimum Stash version +--------|------------------------------------------------|----------------------------------------------------------------------------------------|--------------------- +Kodi| [Kodi Helper](scripts/kodi-helper) | Generates `nfo` and `strm` for use with Kodi. |v0.7 +Maintenance| [Stash Sqlite Renamer](scripts/Sqlite_Renamer) | Renames your files using stash's metadata. |v0.7 +Maintenance| [Title Diff](plugins/titleDiff) | Tag scenes where title differs from filename|v0.7 From cbc1753c0cdb96b7f823b951335bd94ba2f08511 Mon Sep 17 00:00:00 2001 From: o-fl0w Date: Mon, 26 Sep 2022 01:47:18 +0200 Subject: [PATCH 3/3] fix name/descr. of task --- plugins/titleDiff/titleDiff.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/titleDiff/titleDiff.yml b/plugins/titleDiff/titleDiff.yml index 3a46c786..c1807ef2 100644 --- a/plugins/titleDiff/titleDiff.yml +++ b/plugins/titleDiff/titleDiff.yml @@ -6,7 +6,7 @@ exec: - titleDiff.js interface: js tasks: - - name: Diff title <-> filename - description: 'Run' + - name: Run diff + description: 'Tag scenes where title differs from filename' defaultArgs: mode: diff