change label from cli

General support for problems installing or using Deluge
Post Reply
dededinuo
New User
New User
Posts: 2
Joined: Wed Apr 09, 2025 4:34 am

change label from cli

Post by dededinuo »

hi,
Im trying to change the label of torrent from the cli.
I don't mind using api of deluge-console.
I can't find any option to do it in any docs.
anyone know how to do it ?
dededinuo
New User
New User
Posts: 2
Joined: Wed Apr 09, 2025 4:34 am

Re: change label from cli

Post by dededinuo »

I have figuerd it out.
posting the python script here if someone else needs it.
I use it to change the label of files that are cross-seed and has 'cross_seed-link' in thier path.

Code: Select all

#!/usr/bin/python3
import requests
import sys
import logging

# CONFIGURATION
BASE_URL = "URL"
PASSWORD = "PASS"
LOG_FILE = "logfile"

# Command-line arguments
if len(sys.argv) != 4:
    print("Usage: python script.py <torrent_hash> <torrent_name> <torrent_path>")
    sys.exit(1)

TORRENT_ID = sys.argv[1]
TORRENT_NAME = sys.argv[2]
SAVE_PATH = sys.argv[3]
NEW_LABEL = "cross-seed"
MATCH_SUBSTRING = "cross-seed_links"  # Checking for this part of the path

# Set up logging
logging.basicConfig(filename=LOG_FILE, level=logging.INFO, format='%(asctime)s - %(message)s')

s = requests.Session()
login_url = BASE_URL + "json"

# Step 1: Login
resp = s.post(login_url, json={
    "method": "auth.login",
    "params": [PASSWORD],
    "id": 1
})
logging.info("Login response: %s", resp.json())
assert resp.json()["result"], "Login failed"

if MATCH_SUBSTRING in SAVE_PATH:
    logging.info("Path includes %s setting label...", MATCH_SUBSTRING)

    # Set label
    resp = s.post(login_url, json={
        "method": "label.set_torrent",
        "params": [TORRENT_ID, NEW_LABEL],
        "id": 4
    })
    logging.info("Changed label for torrent %s (%s) to %s", TORRENT_NAME, TORRENT_ID, NEW_LABEL)

    # Verify
    resp = s.post(login_url, json={
        "method": "core.get_torrent_status",
        "params": [TORRENT_ID, ["label"]],
        "id": 5
    })
    logging.info("Label for torrent %s (%s) is now: %s", TORRENT_NAME, TORRENT_ID, resp.json()["result"]["label"])
else:
    logging.info("Torrent : %s path %s does not include %s, skipping label change.", TORRENT_NAME, SAVE_PATH, MATCH_SUBSTRING)
mhertz
Moderator
Moderator
Posts: 2326
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: change label from cli

Post by mhertz »

Good job, thanks for posting! :)

Btw, just a heads-up, when using python already, then these methods available also directly in main python api, instead of going through the abstracted web-api methods to control said python api. Not wrong though, just if didn't knew, and as on linux(where on windows api isn't available built-in).
Post Reply