arvidn / libtorrent

an efficient feature complete C++ bittorrent implementation
http://libtorrent.org
Other
5.23k stars 992 forks source link

Download by parts #4631

Closed smirok closed 4 years ago

smirok commented 4 years ago

I tried to figure it out for a long time, but I couldn't.

Whether libtorrent has the ability to parse the .torrent and choose which files/directories I want to download (as in transmission or mediaget, for example). Or is it the only option to parse the torrent file yourself?

Thank you in advance

zbooa commented 4 years ago

I tried to figure it out for a long time, but I couldn't.

Whether libtorrent has the ability to parse the .torrent and choose which files/directories I want to download (as in transmission or mediaget, for example). Or is it the only option to parse the torrent file yourself?

Thank you in advance

This . Get it from handle.

lt::torrent_info ti = h.get_torrent_info();
lt::file_storage const& st = ti.files();

for (auto const i : st.file_range()) {
    st.file_path(i).c_str();//or something else....
}

Get it from file.

std::fstream in;
in.exceptions(std::ifstream::failbit);
in.open(filename.c_str(), std::ios_base::in | std::ios_base::binary);
in.seekg(0, std::ios_base::end);
size_t const size = size_t(in.tellg());
in.seekg(0, std::ios_base::beg);
std::vector<char> ret(size);
in.read(ret.data(), size);

std::vector<char> buf = ret;
int pos = -1;
lt::load_torrent_limits cfg;
lt::bdecode_node const e = lt::bdecode(buf, ec, &pos, cfg.max_decode_depth, cfg.max_decode_tokens);
lt::torrent_info const t(std::move(e), cfg);
buf.clear();
return t; //lt::torrent_info

choose which files. Set file_priority(nIndex , lt::xxxxxx); lt::xxxxxx = lt::dont_download || lt::default_priority || lt::top_priority || lt::low_priority

Hope it help you.

smirok commented 4 years ago

Thanks a lot.

arvidn commented 4 years ago

you can set file priorities as part of the add_torrent_params object directly, that way there won't be a race where some files may be downloaded a little bit before you set the priority to dont_download