2011-12-31 15 views
17

मैंने manual के माध्यम से पढ़ा है और मुझे जवाब नहीं मिल रहा है। एक चुंबक लिंक को देखते हुए मैं एक धार फ़ाइल उत्पन्न करना चाहता हूं ताकि मेटाडेटा को फिर से लोड करने से बचने के लिए इसे अगले स्टार्टअप पर लोड किया जा सके। मैंने तेजी से फिर से शुरू करने की सुविधा की कोशिश की है, लेकिन मुझे अभी भी मेटा डेटा प्राप्त करना है जब मैं इसे करता हूं और इसमें काफी समय लग सकता है। जिन उदाहरणों को मैंने देखा है वे एक नए धार के लिए धार फ़ाइलों को बनाने के लिए हैं, जहां मैं एक चुंबक यूरी से मेल खाता हूं।लिबोरोरेंट - एक चुंबक लिंक देखते हुए, आप एक धार फ़ाइल कैसे उत्पन्न करते हैं?

+0

दी, प्रलेखन खराब है (हालांकि अजीब प्रयोग करने योग्य)। लेकिन, मेटाडेटा एक्सटेंशन http://www.rasterbar.com/products/libtorrent/manual.html#add-extension के साथ क्या गलत है? –

उत्तर

11

समाधान यहाँ पाया जाता है:

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

बनाने देखें धार:

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

पहली पंक्तियों को संशोधित करें:

file_storage fs; 

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

create_torrent t(fs); 

इस के लिए:

torrent_info ti = handle.get_torrent_info() 

create_torrent t(ti) 

"संभाल" यहां से है:

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

इसके अलावा धार आप यह सुनिश्चित करें कि मेटाडाटा डाउनलोड किया गया है करना है बनाने से पहले, इस फोन करके करना handle.has_metadata()

अद्यतन

libtorrent अजगर एपीआई की तरह लगता है एपीआई महत्वपूर्ण ग की ++ और कुछ है कि मैग्नेट से धार बनाने के लिए आवश्यक है याद आ रही है, उदाहरण के ऊपर अजगर कारण में काम नहीं करेगा create_torrent अजगर वर्ग के रूप में torrent_info स्वीकार नहीं करता है पैरामीटर (सी ++ यह उपलब्ध है)।

तो मैं इसे दूसरे तरीके से करने की कोशिश की, लेकिन यह भी एक ईंट की दीवार है कि यह असंभव बना देता है का सामना करना पड़ा, यहाँ कोड है:

torfile.set_hash(i, hash) 

:

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() 

इस लाइन पर फेंक दिया कोई त्रुटि है यह हैश को const char* होने की उम्मीद है लेकिन torrent_info.hash_for_piece(int) कक्षा big_number देता है जिसमें इसे वापस कॉन्स्ट char * में परिवर्तित करने के लिए कोई एपीआई नहीं है।

जब मुझे कुछ समय लगता है तो मैं इस लापता एपीआई बग को libtorrent डेवलपर्स को रिपोर्ट करूंगा, क्योंकि वर्तमान में पाइथन बाइंडिंग का उपयोग करते समय चुंबक उरी से एक .torrent फ़ाइल बनाना असंभव है।

torrent_info.orig_files() पाइथन बाइंडिंग में भी गायब है, मुझे यकीन नहीं है कि torrent_info.files() पर्याप्त है।

अद्यतन 2

मैं इस पर एक मुद्दा बना लिया है, यह यहाँ देखें: http://code.google.com/p/libtorrent/issues/detail?id=294

स्टार यह तो वे जल्दी ठीक करें।

अद्यतन 3

अब यह तय हो गई है, वहाँ एक 0.16.0 रिलीज है। खिड़कियों के लिए द्विआधारी भी उपलब्ध हैं।

+1

सभी कड़ी मेहनत के लिए बहुत बहुत धन्यवाद! – ciferkey

0

यदि resume data को सहेजना आपके लिए काम नहीं करता है, तो आप मौजूदा कनेक्शन से जानकारी का उपयोग कर एक नई धार फ़ाइल उत्पन्न करने में सक्षम हैं।

fs = libtorrent.file_storage() 
libtorrent.add_files(fs, "somefiles") 
t = libtorrent.create_torrent(fs) 
t.add_tracker("http://10.0.0.1:312/announce") 
t.set_creator("My Torrent") 
t.set_comment("Some comments") 
t.set_priv(True) 
libtorrent.set_piece_hashes(t, "C:\\", lambda x: 0), libtorrent.bencode(t.generate()) 
f=open("mytorrent.torrent", "wb") 
f.write(libtorrent.bencode(t.generate())) 
f.close() 

मुझे शक है कि यह फिर से शुरू इस उद्देश्य के लिए विशेष रूप से बनाया समारोह की तुलना में तेजी कर देंगे।

3

बस आधुनिक libtorrent अजगर पैकेज का उपयोग त्वरित अपडेट देना चाहते थे: libtorrent अब parse_magnet_uri विधि है जो आप एक धार संभाल उत्पन्न करने के लिए उपयोग कर सकते हैं:

import libtorrent, os, time 

def magnet_to_torrent(magnet_uri, dst): 
    params = libtorrent.parse_magnet_uri(magnet_uri) 
    session = libtorrent.session() 
    handle = session.add_torrent(params) 
    print "Downloading metadata..." 
    while not handle.has_metadata(): 
     time.sleep(0.1) 
    torrent_info = handle.get_torrent_info() 
    torrent_file = libtorrent.create_torrent(torrent_info) 
    torrent_path = os.path.join(dst, torrent_info.name() + ".torrent") 
    with open(torrent_path, "wb") as f: 
     f.write(libtorrent.bencode(torrent_file.generate())) 
    print "Torrent saved to %s" % torrent_path 
संबंधित मुद्दे