[console] Getting Torrent ID

General support for problems installing or using Deluge
Post Reply
btr74
Member
Member
Posts: 12
Joined: Tue Sep 29, 2015 10:34 pm

[console] Getting Torrent ID

Post by btr74 »

I want to create a script that will execute 'deluge-console move' which requires a torrent-id and a path.

How do I get the torrent ID of an arbitrary torrent? Do I need to do 'deluge-console info' and then parse the output for the torrent I'm looking for? Or is there an easier way to get the ID?

Thanks!
mhertz
Moderator
Moderator
Posts: 2195
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: [console] Getting Torrent ID

Post by mhertz »

It depends. Yes you could parse 'deluge-console info' and btw it supports adding chars with asterisk before or after, e.g. 'deb*' to find your debian iso, and likewise supports same from move command, despite not documented, so if knowing name then don't have to parse output at all. You could also instead of deluge-console use deluge API through a deluge client python script, so client.core.move_storage(), but there it's not supporting other than torrent-ids, well, unless using deluge-console API too, with it's match_torrent(), and otherwise would need extra code for parsing it. Note i'm not very good at this, just so not wanna give off wrong kinda vibe :)

Anyway, what I mean with "it depends" is that you could also if possible use just the execute plugin, which by itself serves you the torrent name and id on a platter, though if you only need specific torrents and not all, then i'd guess irrelevant. If using deluge client script, then could also hook on torrent_finished_even to archieve the same roughly.

Last, in deluge2 there's currently an error about when moving_storage, then it does work, and e.g. I just retested again with using asterisk etc, but it hangs afterwards and so have to be force-quit unfortunetly - it does work though, but just annoying that it doesn't exit itself gracefully afterwards - I cannot remember if submitted bug-report when this was reportet about a year or so ago, I vagualy seem to remember, and i'd suspect I did, but i'll check afterwards and if I didn't then, I'll make it now instead. I'm gonna look at it also myself, but highly guessing is way over my head so not think will lead to anything - I quickly see that it works as said, but stalls afterwards seemingly because of error: "_curses.error: must call initscr() first", line 77 of deluge/ui/console/modes/basemode.py on_terminal_size(). I'll look up the error now.

Anyway hope you find solution.
btr74
Member
Member
Posts: 12
Joined: Tue Sep 29, 2015 10:34 pm

Re: [console] Getting Torrent ID

Post by btr74 »

hey thanks for response. I didn't realize I needed * to make matching work (and that it worked on names as well as ids), that's quite helpful.

I can only seem to make matching work with single-word input. Is there a way to get it to work for phrases? eg: deluge-console info *deb* will work but deluge-console info *debian distro* (or any variation '*debian distro*', *debian\ distro*) all give deluge-console: error: argument Command: invalid choice.

Like you mentioned, the move command still hangs instead of exiting gracefully (I had forgotten that I encountered that bug when trying to do something similar almost two years ago), so this is all kind of a moot point until that bug is fixed.

Maybe I'll look into python libs and see about writing this in python instead of bash.

Thanks again.
mhertz
Moderator
Moderator
Posts: 2195
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: [console] Getting Torrent ID

Post by mhertz »

You're very welcome and lol it was you which originally reportet it here, long ago, thanks for that btw, else wouldn't be aware :) I just checked and I never reported it strangely, must've forgot, so i'll do it today or tomorrow.

About your issue, then I just tested that it works if you quote the deluge-console command args given, plus additionally the glob-string searched for, e.g. I tested with the ipmagnet test torrent, which is listed as having name of "IP Magnet Tracking Link", and deleted it with:

Code: Select all

deluge-console "rm --confirm --remove_data '*net Track*'"
I forgot test btw if case-sensitive in globbing or not, but I seem to remember that it was when tested it some years ago, yeah pretty sure about it was actually. Anyway, Maybe there's other ways too, e.g. escape char etc, but this works atleast - little more dificult maybe from scripting then presumably. Btw, I used the long-format option '--confirm' instead of '-c' as quick workaround for current bug where else collides with '-c' already assigned for '--config', and else would need additional prepended "connect localhost ;" or "-c ~/.config/deluge" to make work as cannot find your auth file otherwise and complaints(since mistakenly directed to use nonexisting new config-dir with the -c).

Edit: Seems the move command dosen't work anyway, sorry, I don't know why looked like it did previously, but now I cannot make it work currently - besides hanging, then reports the new place correct, but no moved storage there. I'll investigate some more tomorrow before reporting bug. When in python manually importing curses module and runing e.g. curses.resizeterm(40,40), then also reports error need initscr() first, which worked when doing that, but though when adding it to deluge code then just stated other error next - also I don't get why even need mess with curses when running non-interactively i.e. cli not curses mode, that seems little buggy to me, and nop'ing out the function and the call to it from other file also, with 'pass' doesn't work either as hangs regardless, just without any curses error posted anymore when force-quiting out of the stall.

Edit2: Sorry, it does work currently as originally said, and just hangs afterwards, and md5sum check confirms moved correctly etc - I later on stupidly forgot use complete path and instead just gave relative one, and this isn't supported(but no error posted about that) and hence I thought didn't work, doh, sorry. Still no solution for the hanging either sadly, but will look more later again.
Last edited by mhertz on Fri Jun 04, 2021 7:20 pm, edited 2 times in total.
mhertz
Moderator
Moderator
Posts: 2195
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: [console] Getting Torrent ID

Post by mhertz »

Sorry, too many edits in previous post, so took liberty to make new one, hope okay. Anyway I finally fixed the stalling of deluge-console's 'move' command when run from cli mode(non-interactive/curses mode), so if wanna apply fix yourself, then simply comment out line 61 of '/usr/lib/python3.9/site-packages/deluge/ui/console/cmdline/commands/move.py'(or wherever you have that file i.e. which python version used etc), so becomes '#return d'.

I made bug-ticket reporting bug(and fix) here: https://dev.deluge-torrent.org/ticket/3473

Edit: Following command-line can be copy/pasted into a terminal to quickly apply fix irregardless of deluge install location:

Code: Select all

sudo find / -type f -path "*deluge/*/commands/move.py" -exec sed -i 's/return d/#return d/' {} \;
btr74
Member
Member
Posts: 12
Joined: Tue Sep 29, 2015 10:34 pm

Re: [console] Getting Torrent ID

Post by btr74 »

Sorry to necrobump, just wanted to say thanks for your response and help.
your edit of move.py solves the problem (more gracefully than my previous workaround of running the command inside of a bash timeout command)
And for filing an official bug report (as this appears to still be a bug as of 2.1.1)
mhertz
Moderator
Moderator
Posts: 2195
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: [console] Getting Torrent ID

Post by mhertz »

Appreciate your post buddy :) I made another ticket a year after, as had forgot to check if already had stupidly, and that is closed now in develop branch with gracefully help from DjLegolas and Cas. Will be fixed in next release, thanks for reporting, and kind post.
Post Reply