important context: i have been developing a deluge plugin to integrate telegram (commands and notifications) with my deluge server. (https://github.com/BlazeMV/delugram if you wanna have a look) its heavily inspired from and similar to telegrammer plugin. my plugin supports adding magnets. i'm using add_torrent_magnet of deluge core for this task. my plugin uses python-telegram-bot (PTB) under the hood, which uses asyncio (as opposed to deluge using twisted), so you might see some cross-async-framework compatibility code here and there. I am also using another plugin called filebottool to rename and move downloaded torrents into my plex dir.
i have noticed that file_priorities option is not set on the torrent when we add torrent from a magnet. I have already spend hours adding up to days

- This is the case when adding magnets using core.add_torrent_magnet() OR when adding magnets from any ui if we (click) "Add" before files are loaded into ui.
- Adding torrents via .torrent files does not have this problem since .torrent files have metadata embedded in them including files list. But magnet links does not have metadata embedded in the link.
- This is (probably?) not a bug, but how its intended to work?
- i have looked into deluge gtk3ui code and looks like its loading metadata asynchronously, to display files list. Using the method code.prefetch_magnet_metadata()
- I understand that file_priorities is not set until files in torrent are listed which happens during prefetch_magnet_metadata(). Again expected behaviour.
- when torrents are added using core.add_torrent_magnet(uri) method file_priorities is set to [] by default. because deluge doesn't know how many files there are in the torrent? This still allows files in the torrent to be downloaded i'm assuming because deluge's default priority is 4 (Normal) and not 0 (Skip)
- But since torrent.options["file_priorities"] still return [] (empty list) even after torrent download is completed, this is causing issues with filebottool. filebottool expects file_priorities to be present and a non empty list. This is so that filebottool will now which files to skip when renaming / moving. (if file_priorities = [0,4], filebottool will skip first file and rename second). But since file_priorities = [] filebottool skips over all the files. See https://github.com/Laharah/deluge-FileB ... ol/core.py line 383 and 384 for reference.
- I'm am mentioning filebottool because thats what i have been working with, but i assume this could be true with any other plugins leveraging torrent.options["file_priorities"] expecting it to be a non empty list. Like if i wrote a custom script and used Execute plugin to run that script, it will still get an empty file_priorities list. Anyways i will also be submitting an issue to filebottool to see if they could address this issue.
- I guess this is not a bug report. Just confirming my finding, informing others of this behaviour, and getting advice on how i could tackle this issue from my plugin. Although i don't want to believe that that this is something my plugin should be addressing (fetching magnet metadata -> listing files, building default file_priorities and setting them on added magnet)
- Would it be possible for deluge to fetch metadata during core.add_torrent_magnet(uri) method? maybe an additional optional argument to fetch metadata asynchronously before downloading files and setting proper torrent options.
- Or, provide another single method which will fetch metadata, and build all proper torrent options including file_priorities. Here i'm assuming file_priorities isn't the only extra option fetch metadata will allow to set.
Code: Select all
info_hash, encoded_metadata = await self.core.prefetch_magnet_metadata(update.message.text).asFuture(
asyncio.get_event_loop())
metadata = bdecode(b64decode(encoded_metadata))
torrent_info = TorrentInfo.from_metadata(metadata)
file_priorities = [4] * len(torrent_info.files) # Set all files to normal priority
tid = self.core.add_torrent_magnet(uri=update.message.text, options={
'delugram_chat_id': update.effective_chat.id,
'file_priorities': file_priorities,
})
footnotes:
- Apologies for the long rant. As i said earlier, I have spend days on this pesky issue.

- I may be wrong on multiple of my findings, Please feel free to correct me.
- I am very new to python and deluge.
- My dev env is as follows: deluge 2.1.1, libtorrent: 2.0.10.0, Python: 3.12.8, OS: Darwin 15.3 arm64
- My Deluge server is as follows: deluge 2.1.2.dev0, libtorrent: 2.0.10.0, Python: 3.12.3, OS: Linux Ubuntu 24.04 noble