[Script] Relocate files in qBT

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
User avatar
rednoah
The Source
Posts: 23008
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

[Script] Relocate files in qBT

Post by rednoah »

(requires FileBot r10230 or higher) This post-processing script will relocate files in qBT after moving / renaming files with FileBot.


:!: This script currently only supports relocation for single-file torrents.
(NOTE: qBT fundamentally cannot relocate multi-file torrents where multiple files have have been moved into multiple different target directories)

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"

// find torrent for each processed file
args.eachWithIndex{ f, i ->
	def torrent = info.find{ it.content_path == f.path }
	if (torrent) {
		submit "$api/torrents/renameFile", [hash: torrent.hash, oldPath: f.name, newPath: model[i].f.name]
		submit "$api/torrents/setLocation", [hashes: torrent.hash, location: model[i].folder]
	} else {
		println "Torrent not found: $f"
	}		
}

// clear login cookie
submit "$api/auth/logout", [:]



Did you arrive here via a search?

:idea: You may prefer to use --action hardlink to simply have the same file twice at two or more file paths. No qBT relocation necessary.

:idea: You may prefer to use --action keeplink to replace the original file path with a symlink to the new file path. No qBT relocation necessary.
:idea: Please read the FAQ and How to Request Help.
Post Reply