I wanted to write a simple Python script that renames files/folders matching a certain criteria. I have exhausted all documentation and the StackOverflow but I am unable to find how the rename file/folder functionality works with Deluge v2.x. ChatGPT couldn't offer a working code either.
Since we know deluge-gtk v2 is capable of renaming files and folders, this should be possible. I guess the saddest part is, I could not find the deluge-gtk code that leverages the "rename api(?)" and learn from that implementation.
I am able to list torrents using deluge-console and DelugeRPCClient. I am able to list files in an torrent using DelugeRPCClient. I couldn't figure out renaming them though. Could someone give me a hint or show me an implementation?
RPC call to rename files and folders
Re: RPC call to rename files and folders
There's two deluge RPC API calls for this i.e. 'deluge.core.rename_{files,folder}'. The latter takes (torrent_id, "old-dir", "newdir") as string/var args, whereas former needs (torrent_id, [(idx, "new-path")]), where 'idx' is file-index of file wanting renamed, which can e..g be gotten from deluge.core.get_torrent_status(torrent-id, ['files'], which is a deferred so needs twisted callback appended).
Here's very quick messy deluge client script example for this, just as proof of concept with hardcoded torrent-id and localhost daemon login etc:
It renames a file here in torrent, and i've added some commented lines for showing the same for dir-renaming, getting torrent-indexes/paths and getting all loaded torrent-ids, to traverse/filter through yourself as per needed, plus registering hooks for file/folder rename events, to setup if needed, as is done async, so you don't know when finished otherwise, if relevant here.
Note some stuff needs '(*args, **kwargs)' defined for function despite not used by you, but is apparently on the backend, something about callbacks happening cleanly or whatnot, but anyway, not a mistake used here in the commented part I just mean.
I don't know much about this mind you, but just a few pointers at-least, hope helps little bit
Here's very quick messy deluge client script example for this, just as proof of concept with hardcoded torrent-id and localhost daemon login etc:
Code: Select all
from deluge.ui.client import client
from twisted.internet import reactor
def a(*args, **kwargs):
#def b(c):
# print(c)
# client.disconnect
# reactor.stop()
#client.core.get_torrent_status('6d4795dee70aeb88e03e5336ca7c9fcf0a1e206d',['files']).addCallback(b)
#client.core.rename_folder('6d4795dee70aeb88e03e5336ca7c9fcf0a1e206d',"foo","bar")
#client.core.get_session_state().addCallback(b)
#client.register_event_handler(TorrentFileRenamedEvent', x)
#client.register_event_handler('TorrentFolderRenamedEvent', y)
client.core.rename_files('6d4795dee70aeb88e03e5336ca7c9fcf0a1e206d',[(0,"foo/bar.iso")])
client.connect().addCallback(a)
reactor.run()
Note some stuff needs '(*args, **kwargs)' defined for function despite not used by you, but is apparently on the backend, something about callbacks happening cleanly or whatnot, but anyway, not a mistake used here in the commented part I just mean.
I don't know much about this mind you, but just a few pointers at-least, hope helps little bit
Re: RPC call to rename files and folders
lol....mhertz wrote: ↑Sun Jul 09, 2023 12:34 pm Here's very quick messy deluge client script example for this, just as proof of concept with hardcoded torrent-id and localhost daemon login etc:I don't know much about this mind you, but just a few pointers at-least, hope helps little bit :)Code: Select all
from deluge.ui.client import client from twisted.internet import reactor def a(*args, **kwargs): #def b(c): # print(c) # client.disconnect # reactor.stop() #client.core.get_torrent_status('6d4795dee70aeb88e03e5336ca7c9fcf0a1e206d',['files']).addCallback(b) #client.core.rename_folder('6d4795dee70aeb88e03e5336ca7c9fcf0a1e206d',"foo","bar") #client.core.get_session_state().addCallback(b) #client.register_event_handler(TorrentFileRenamedEvent', x) #client.register_event_handler('TorrentFolderRenamedEvent', y) client.core.rename_files('6d4795dee70aeb88e03e5336ca7c9fcf0a1e206d',[(0,"foo/bar.iso")]) client.connect().addCallback(a) reactor.run()
Never ceases to amaze me how humble and capable you are my friend.
Yea bro...who are you kidding :Pmhertz wrote: I don't know much about this but here is exactly what you asked for, example script to do exactly what you need more or less, with extra stuff you didn't even know you'd want, and comments on top of it all. Oh but sorry I don't know much about this....
Re: RPC call to rename files and folders
I'm smiling big from ear to ear, grinning hard, from reading that crazy kind and touchingly hilarious post bro, and despite way to much credit, then it really got to me, thank you so much brother, much love my friend
Re: RPC call to rename files and folders
This forced me to have a crash course on reactor, which I had been avoiding since I first come across it. I guess I was on the wrong side of the fence.
Thanks heaps mhertz! This gets me going.
Thanks heaps mhertz! This gets me going.
Re: RPC call to rename files and folders
Much welcome buddy, glad to hear