Modify Added (or other) attributes of a torrent?

General support for problems installing or using Deluge
Post Reply
cross
Member
Member
Posts: 22
Joined: Fri May 08, 2015 3:15 am

Modify Added (or other) attributes of a torrent?

Post by cross »

This may be more of a development question, but. I have recently lost all of the state on my deluge server (stupid human error). So, I have all/most of the torrent files, and am just re-adding them. however, this means the "Added" value for each of them is now.

I have the modification times of the received files, so a good source of data. Is it possible to change that value? Is that data for a torrent stored somewhere I can change? (I hav programming experience, so pointers to where/how it's stored and I can write a tool)
User avatar
ambipro
Moderator
Moderator
Posts: 445
Joined: Thu May 19, 2022 3:33 am
Contact:

Re: Modify Added (or other) attributes of a torrent?

Post by ambipro »

I believe it's all stored in the torrents.state file. You can see the structure of the states for torrents and their values @ https://git.deluge-torrent.org/deluge/t ... manager.py

However, editing it in a text editor is not going to work, as IIRC it's encoded. I don't have time (or remember) the encoding, but you can probably find it in the torrentmanager.py or follow a thread from there.
cross
Member
Member
Posts: 22
Joined: Fri May 08, 2015 3:15 am

Re: Modify Added (or other) attributes of a torrent?

Post by cross »

Hmm. Okay, getting back to this I'm able to read the state file using the above, and then dig into the files received for times. But, looking at the TorrentState loaded, there isn't an "added" time. Looking around torrentmanager.py it looks like it's not in there. :-(. I'll have to dig around the code to see if the AddedEvent is caught and used elsewhere for this, but if you have a pointer that would be appreciated.
User avatar
ambipro
Moderator
Moderator
Posts: 445
Joined: Thu May 19, 2022 3:33 am
Contact:

Re: Modify Added (or other) attributes of a torrent?

Post by ambipro »

Honestly I don't really have any insight I can give you on modifying this...sorry :(
mhertz
Moderator
Moderator
Posts: 2216
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: Modify Added (or other) attributes of a torrent?

Post by mhertz »

Libtorrent has an added_time status object(posix time, so date+time), deluge refers to it internally as time_added though, e.g. as seen in torrent.py where defined for usage initially. It's stored as far I know only in the fastresume file, and if deleting or loosing it, then deluge will just use current time of initial load and regenerating fastresume, as none else place stored, or so I believe atleast. I thought I would post you a little deluge client script example to go from, updating each torrents time_added, though unfortunetly I cannot post it, because failed working in my testing of it, and when I rechecked source I found only select set of options actually available for changing, which the API docs also state, and as added_time isn't editable in UIs, or probably neither deemed very useful a property to modify, then they didn't bother support it, unless i'm wrong, but think not. Then possibly an option using libtorrent directly, from python or C bindings, though I have no example from top of head there, though would guess not that difficult, atleast the likes of loading a torrent etc, wasen't, last I tried. Sorry no help :(
cross
Member
Member
Posts: 22
Joined: Fri May 08, 2015 3:15 am

Re: Modify Added (or other) attributes of a torrent?

Post by cross »

Alright. As long as it's stored somewhere, I can modify it. I'm not sure what is in the fastresume file. The state file, I think, is the state of all of the known torrents. I certainly would have expected all fields of that would be there. Is there a libtorrent object that the state entry references?
I'm happy to use libtorrent to change things, I'm starting this in python. I can get what I need so far, _except_ for the added time to compare the file ctimes to. ;-)
mhertz
Moderator
Moderator
Posts: 2216
Joined: Wed Jan 22, 2014 5:05 am
Location: Denmark

Re: Modify Added (or other) attributes of a torrent?

Post by mhertz »

I'm no expert as said, but believe the torrents.state is a deluge own concoction, with various stuff compiled in from libtorrent and deluge itself - you can check what exactly in the link also kindly provided by ambipro, in torrentmanager.py. Then the fastresume file is also partially a deluge concoction, meaning normally resume files are generated and saved for each torrent, but deluge compiles them for all torrents and appends in one big bencoded dict and unpacks and feeds libtorrent upon startup, both for piece info and status info like added_time. The session state is completely from libtorrent, but of-topic here of-course. Anyway, I thought why not just edit the fastresume file itself instead of starting new manual libtorrent session and update added_time and save resume again, and as said you need assemble a dict with all resumes for each torrent handle and bencode and save. Btw, torrents.state are pickled and you can unpickle and look inside(if wanna verify added_time missing), e.g. I previously posted in off-topic section a python script to do that, for changing save_path in that file, if interested(deluge_path_change in thread title), but for the resume, then if was for single torrents, then much easier to change, like for qbittorrent etc, but here not as easy, well unless just me, and honestly was much harder than my previous fooling around just adding a torrent and whatnot lol - I had lots annoying issues, and mind you, you can do much better yourself i'm sure, and just a quick example to go by if needed - very dumb example just changing to hardcoded single value, but just for proof of concept I mean, and I tested it works with a few torrents and sets the added_time to 2014 and doesn't recheck files upon startup - I didn't bother clean it up or use propper paths and names and whatnot, as not about that:

Code: Select all

#!/usr/bin/python

import os
import libtorrent as lt

f = open('torrents.fastresume', 'rb')
r = lt.bdecode(f.read())
r = {k.decode(): v for k, v in r.items()}
y = {}
for x in r:
    i = lt.read_resume_data(r[x])
    i.added_time = 1404567636
    y[x] = lt.bencode(lt.write_resume_data(i))
f = open('torrents.fastresume-new', 'wb', 0)
f.write(lt.bencode(y))
f.flush()
os.fsync(f.fileno())
(Can filter/match through torrent-ID which here 'x' and/or e.g 'i.name' etc)
Post Reply