Skip to content

Instantly share code, notes, and snippets.

@gileri
Created June 20, 2020 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gileri/91928df4444561e5f944da897d7ed173 to your computer and use it in GitHub Desktop.
Save gileri/91928df4444561e5f944da897d7ed173 to your computer and use it in GitHub Desktop.
Move rTorrent torrent download directories via XMLRPC
#!/bin/env python3
import logging
import sys
import xmlrpc.client
logging.basicConfig(level=logging.INFO)
def move_all_torrents(server: str, old_prefix: str, new_prefix: str):
with xmlrpc.client.ServerProxy(server) as proxy:
for torrent in proxy.download_list():
directory = proxy.d.directory(torrent)
if directory.find(old_prefix) != 0:
logging.warning("Prefix %s doesn't match %s", old_prefix, directory)
continue
new_directory = directory.replace(old_prefix, new_prefix)
logging.info("%s : Moving %s to %s", torrent, directory, new_directory)
proxy.d.directory_base.set(torrent, new_directory)
if __name__ == "__main__":
move_all_torrents(
server=sys.argv[1],
old_prefix=sys.argv[2],
new_prefix=sys.argv[3],
)
@gileri
Copy link
Author

gileri commented Jun 20, 2020

Move all torrents from a mount point to another (such as /mnt/source and /mnt/dest) :

python3 main.py http://localhost/RPC2 /mnt/source /mnt/dest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment