mirror of
https://github.com/stashapp/CommunityScripts.git
synced 2026-04-20 22:12:32 -05:00
Add dupeMarker
This commit is contained in:
8
plugins/dupeMarker/README.md
Normal file
8
plugins/dupeMarker/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
Marks duplicate markers with a tag: `[Marker: Duplicate]`
|
||||
|
||||
Tasks -> Search for duplicate markers
|
||||
|
||||
It will add the tag to any markers that have an **exact** match for title, time **and** primary tag.
|
||||
It will only add to existing markers, it is up to the user to go to the tag and navigate to the scene where the duplicates will be highlighted with the tag.
|
||||
|
||||
(it's technically a Dupe Marker Marker)
|
||||
69
plugins/dupeMarker/dupeMarker.py
Normal file
69
plugins/dupeMarker/dupeMarker.py
Normal file
@@ -0,0 +1,69 @@
|
||||
import json
|
||||
import sys
|
||||
import re
|
||||
import datetime as dt
|
||||
import stashapi.log as log
|
||||
from stashapi.tools import human_bytes
|
||||
from stashapi.stash_types import PhashDistance
|
||||
from stashapi.stashapp import StashInterface
|
||||
|
||||
FRAGMENT = json.loads(sys.stdin.read())
|
||||
MODE = FRAGMENT['args']['mode']
|
||||
stash = StashInterface(FRAGMENT["server_connection"])
|
||||
dupe_marker_tag = stash.find_tag('[Marker: Duplicate]', create=True).get("id")
|
||||
|
||||
def findScenesWithMarkers():
|
||||
totalDupes = 0
|
||||
scenes = stash.find_scenes(f={"has_markers": "true"},fragment="id")
|
||||
for scene in scenes:
|
||||
totalDupes += checkScene(scene)
|
||||
log.info("Found %d duplicate markers across %d scenes" % (totalDupes, len(scenes)))
|
||||
|
||||
def addMarkerTag(marker):
|
||||
query = """
|
||||
mutation SceneMarkerUpdate($input:SceneMarkerUpdateInput!) {
|
||||
sceneMarkerUpdate(input: $input) {
|
||||
id
|
||||
}
|
||||
}
|
||||
"""
|
||||
oldTags = [tag["id"] for tag in marker["tags"]]
|
||||
if dupe_marker_tag in oldTags:
|
||||
return
|
||||
oldTags.append(dupe_marker_tag)
|
||||
newMarker = {
|
||||
"id": marker["id"],
|
||||
"tag_ids": oldTags
|
||||
}
|
||||
stash._callGraphQL(query, {"input": newMarker })
|
||||
#stash.update_scene_marker(newMarker, "id")
|
||||
|
||||
def checkScene(scene):
|
||||
seen = set()
|
||||
dupes = []
|
||||
markers = stash.find_scene_markers(scene['id'])
|
||||
# find duplicate pairs
|
||||
for marker in markers:
|
||||
sortidx = ";".join([
|
||||
str(marker["title"]),
|
||||
str(marker["seconds"]),
|
||||
str(marker["primary_tag"]["id"])
|
||||
])
|
||||
if sortidx not in seen:
|
||||
seen.add(sortidx)
|
||||
else:
|
||||
dupes.append(marker)
|
||||
# add tag
|
||||
if dupes:
|
||||
log.debug("Found %d duplicate markers in scene %s" % (len(dupes), scene['id']))
|
||||
for dupe in dupes:
|
||||
addMarkerTag(dupe)
|
||||
return len(dupes)
|
||||
|
||||
def main():
|
||||
if MODE == "search":
|
||||
findScenesWithMarkers()
|
||||
log.exit("Plugin exited normally.")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
13
plugins/dupeMarker/dupeMarker.yml
Normal file
13
plugins/dupeMarker/dupeMarker.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
name: Dupe Marker Detector
|
||||
description: Finds and marks duplicate markers
|
||||
version: 0.1
|
||||
url: https://github.com/stashapp/CommunityScripts/
|
||||
exec:
|
||||
- python
|
||||
- "{pluginDir}/dupeMarker.py"
|
||||
interface: raw
|
||||
tasks:
|
||||
- name: 'Search'
|
||||
description: Search for duplicate markers
|
||||
defaultArgs:
|
||||
mode: search
|
||||
1
plugins/dupeMarker/requirements.txt
Normal file
1
plugins/dupeMarker/requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
stashapp-tools
|
||||
Reference in New Issue
Block a user