Reputation: 159
I need the default directory a torrent file will create when it is started using any torrent manager - as a string. I'm not a programmer, but with other help I was able to obtain the contents (files) of the torrent as strings:
info = libtorrent.torrent_info(torrent_file)
for f in info.files():
file_name = "%s" % (f.path)
# do something with file_name
Upvotes: 0
Views: 2302
Reputation: 11245
One thing to keep in mind is that there are two kinds of torrent files. Single-file torrents and multi-file torrents. The typical filename structure of the two kinds are:
single-file torrents: save-path/torrent-name
multi-file torrents: save-path/torrent-name/all-files-in-torrent
It sounds like you're looking for the name of the directory files of the torrent are stored in (by convention of most clients). i.e. the torrent name.
Example code to do this in python using libtorrent:
import libtorrent as lt
import sys
ti = lt.torrent_info(sys.argv[1])
if ti.num_files() > 1:
print(ti.name())
else:
# single-file torrent, name() may be a filename
# instead of directory name
Upvotes: 1