Last active
April 23, 2022 19:00
-
-
Save poontology/4f96cb291c6fb05907e10ac28bfab0d8 to your computer and use it in GitHub Desktop.
graphql script to add a specific tag to all scenes in stashapp, try it in chrome developer console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let graphqlUrl = "http://ip:9999/graphql" | |
async function updateSceneTags(input) { | |
return await fetch(graphqlUrl, { | |
"headers": { | |
"content-type": "application/json" | |
}, | |
"body": JSON.stringify({ | |
query: `mutation MyMutation($input: [SceneUpdateInput!]!) { | |
scenesUpdate(input: $input) { id } | |
}`, | |
variables: { input }, | |
operationName: "MyMutation" | |
}), | |
"method": "POST", | |
}); | |
} | |
async function getNontagged(tag_id) { | |
const res = await fetch(graphqlUrl, { | |
"headers": { | |
"content-type": "application/json" | |
}, | |
"body": JSON.stringify({ | |
query: `query MyQuery { | |
findScenes(scene_filter: { tags: {value: "${tag_id}", modifier: EXCLUDES}}) { | |
scenes { id } | |
} | |
}` | |
}), | |
"method": "POST", | |
}); | |
return (await res.json()).data.findScenes.scenes | |
} | |
// it's not supported to mass tag an id-range | |
// updateSceneTags([...Array(40).keys()].map(i => { return { id: i, tag_ids: [4] } })) | |
// because stash only takes 25 at a time, instead loop until no untagged videos left.. | |
let nt = [] | |
//const isOk = (l) => confirm((l.length ? l.length+" updated, continue?" : "update non-tagged videos?")) | |
const isOk = (l) => { console.log(l.length+" updated"); return (l.length > 0); } | |
const tag_id = 4 | |
while(isOk(nt)) { | |
nt = (await getNontagged(tag_id)).map(e => { e.tag_ids=[tag_id]; return e }) | |
await updateSceneTags(nt) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment