Groovy: Select all
def api = 'http://localhost:8080/api/v2'
def login = [username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD']
// post HTML login form and receive login cookie
submit "$api/auth/login", login
// retrieve qBT torrent index
def info = curl "$api/torrents/info"
def renameFile = [] as Set
def setLocation = [] as Set
// find torrent for each processed file
args.eachWithIndex{ target, i ->
def source = model[i].f
def torrent = info.find{ source.path.startsWith(it.content_path) }
if (torrent) {
def content = curl "$api/torrents/files?hash=$torrent.hash"
content.each{
if (source == torrent.save_path / it.name) {
renameFile += [hash: torrent.hash, oldPath: it.name, newPath: target.name]
setLocation += [hashes: torrent.hash, location: target.dir]
// handle companion files
content.each{
def oldPath = torrent.save_path / it.name
def newPath = target.dir / oldPath.name
if (oldPath !in model.f && oldPath.exists() && !newPath.exists()) {
action(oldPath, newPath)
renameFile += [hash: torrent.hash, oldPath: it.name, newPath: newPath.name]
}
}
}
}
} else {
println "Torrent not found: $source"
}
}
// send relocate requests
renameFile.each{ submit "$api/torrents/renameFile", it }
setLocation.each{ submit "$api/torrents/setLocation", it }
// clear login cookie
submit "$api/auth/logout", [:]
Did you arrive here via a search?

