Skip to content

Instantly share code, notes, and snippets.

@poontology
Last active April 23, 2022 19:00
Show Gist options
  • Save poontology/4f96cb291c6fb05907e10ac28bfab0d8 to your computer and use it in GitHub Desktop.
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
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