Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7663693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:06:46+00:00 2026-05-31T14:06:46+00:00

I have read through the manual and I cannot find the answer. Given a

  • 0

I have read through the manual and I cannot find the answer. Given a magnet link I would like to generate a torrent file so that it can be loaded on the next startup to avoid redownloading the metadata. I have tried the fast resume feature, but I still have to fetch meta data when I do it and that can take quite a bit of time. Examples that I have seen are for creating torrent files for a new torrent, where as I would like to create one matching a magnet uri.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:06:47+00:00Added an answer on May 31, 2026 at 2:06 pm

    Solution found here:

    http://code.google.com/p/libtorrent/issues/detail?id=165#c5

    See creating torrent:

    http://www.rasterbar.com/products/libtorrent/make_torrent.html

    Modify first lines:

    file_storage fs;
    
    // recursively adds files in directories
    add_files(fs, "./my_torrent");
    
    create_torrent t(fs);
    

    To this:

    torrent_info ti = handle.get_torrent_info()
    
    create_torrent t(ti)
    

    “handle” is from here:

    torrent_handle add_magnet_uri(session& ses, std::string const& uri add_torrent_params p);
    

    Also before creating torrent you have to make sure that metadata has been downloaded, do this by calling handle.has_metadata().

    UPDATE

    Seems like libtorrent python api is missing some of important c++ api that is required to create torrent from magnets, the example above won’t work in python cause create_torrent python class does not accept torrent_info as parameter (c++ has it available).

    So I tried it another way, but also encountered a brick wall that makes it impossible, here is the code:

    if handle.has_metadata():
    
        torinfo = handle.get_torrent_info()
    
        fs = libtorrent.file_storage()
        for file in torinfo.files():
            fs.add_file(file)
    
        torfile = libtorrent.create_torrent(fs)
        torfile.set_comment(torinfo.comment())
        torfile.set_creator(torinfo.creator())
    
        for i in xrange(0, torinfo.num_pieces()):
            hash = torinfo.hash_for_piece(i)
            torfile.set_hash(i, hash)
    
        for url_seed in torinfo.url_seeds():
            torfile.add_url_seed(url_seed)
    
        for http_seed in torinfo.http_seeds():
            torfile.add_http_seed(http_seed)
    
        for node in torinfo.nodes():
            torfile.add_node(node)
    
        for tracker in torinfo.trackers():
            torfile.add_tracker(tracker)
    
        torfile.set_priv(torinfo.priv())
    
        f = open(magnet_torrent, "wb")
        f.write(libtorrent.bencode(torfile.generate()))
        f.close()
    

    There is an error thrown on this line:

    torfile.set_hash(i, hash)
    

    It expects hash to be const char* but torrent_info.hash_for_piece(int) returns class big_number which has no api to convert it back to const char*.

    When I find some time I will report this missing api bug to libtorrent developers, as currently it is impossible to create a .torrent file from a magnet uri when using python bindings.

    torrent_info.orig_files() is also missing in python bindings, I’m not sure whether torrent_info.files() is sufficient.

    UPDATE 2

    I’ve created an issue on this, see it here:
    http://code.google.com/p/libtorrent/issues/detail?id=294

    Star it so they fix it fast.

    UPDATE 3

    It is fixed now, there is a 0.16.0 release. Binaries for windows are also available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have read through the MSDN naming guidelines and could not find a clear answer,
I'm trying to have my application read through a text file and look for
I have read through other questions on this site - using the example answer
I have read through several reviews on Amazon and some books seem outdated. I
I have read through the solutions to similar problems, but they all seem to
I have read through the Rails docs for Routing , Restful Resources , and
I have read through some tutorials about javascript prototypal inheritance patterns but I am
Okay guys, I have read through all the other posts and question on jQuery
Ok, I'm programming in objective-C and using Xcode. I have read through the documentation
I've read through a number of topics now and have not found one quite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.