snowyu / libtorrent

Automatically exported from code.google.com/p/libtorrent
Other
1 stars 0 forks source link

make_magnet_uri function misses webseeds #599

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello, I try to use libtorrent from python and getting the following:

fs = libtorrent.file_storage()
libtorrent.add_files(fs, 'file')
t = libtorrent.create_torrent(fs, 256*1024)
t.add_url_seed('http://10.10.10.10/file')
libtorrent.set_piece_hashes(t, os.path.dirname('file'))
metadata = t.generate()
info = libtorrent.torrent_info(metadata)
infohash = str(info.info_hash()).lower()
magnet = str(libtorrent.make_magnet_uri(info)).lower()

What is the expected output? What do you see instead?
Returned from make_magnet_uri link has no ws args included in spite of web seed 
exists in torrent file.
Desired behaviour is to include them.

What version of the product are you using? On what operating system?
Ubuntu 12.10 libtorrent-rasterbar6=0.16.3-0ubuntu1, 
python-libtorrent=0.16.3-0ubuntu1
Ubuntu 14.04 libtorrent-rasterbar7=0.16.13-1ubuntu2, 
python-libtorrent=0.16.13-1ubuntu2

Thanks in advance.

Original issue reported on code.google.com by me@teran.ru on 14 Apr 2014 at 2:04

GoogleCodeExporter commented 9 years ago
could you try this patch? It doesn't parse web seeds out of magnet links still 
though.

Index: src/magnet_uri.cpp
===================================================================
--- src/magnet_uri.cpp  (revision 9886)
+++ src/magnet_uri.cpp  (working copy)
@@ -50,7 +50,6 @@
        ret += to_hex(ih.to_string());

        torrent_status st = handle.status(torrent_handle::query_name);
-
        if (!st.name.empty())
        {
            ret += "&dn=";
@@ -58,7 +57,6 @@
        }

        std::vector<announce_entry> const& tr = handle.trackers();
-
        for (std::vector<announce_entry>::const_iterator i = tr.begin(), end(tr.end()); i != end; ++i)
        {
            ret += "&tr=";
@@ -65,6 +63,14 @@
            ret += escape_string(i->url.c_str(), i->url.length());
        }

+       std::set<std::string> seeds = handle.url_seeds();
+       for (std::set<std::string>::iterator i = seeds.begin()
+           , end(seeds.end()); i != end; ++i)
+       {
+           ret += "&ws=";
+           ret += escape_string(i->c_str(), i->length());
+       }
+
        return ret;
    }

@@ -91,6 +97,16 @@
            ret += escape_string(i->url.c_str(), i->url.length());
        }

+       std::vector<web_seed_entry> const& seeds = info.web_seeds();
+       for (std::vector<web_seed_entry>::const_iterator i = seeds.begin()
+           , end(seeds.end()); i != end; ++i)
+       {
+           if (i->type != web_seed_entry::url_seed) continue;
+
+           ret += "&ws=";
+           ret += escape_string(i->url.c_str(), i->url.length());
+       }
+
        return ret;
    }

Original comment by arvid.no...@gmail.com on 15 Apr 2014 at 7:13

GoogleCodeExporter commented 9 years ago

Original comment by arvid.no...@gmail.com on 24 Apr 2014 at 6:36