2014-11-23 38 views
2
 
def magnet2torrent(id, info_hash): 

    info_hash_id=id 

    magnet="magnet:?xt=urn:btih:"+info_hash 

    ses = lt.session() 
    params = { 
     'save_path': './', 
     'duplicate_is_error': True, 
     'storage_mode': lt.storage_mode_t(2), 
     'paused': False, 
     'auto_managed': True, 
     'duplicate_is_error': True 
    } 
    handle = lt.add_magnet_uri(ses, magnet, params) 

    print("Downloading Metadata (this may take a while)") 
    i = 0; 
    while (not handle.has_metadata()): 
#  i = i+1 
     if i > 300 : 
      return 
     sleep(1) 
    ses.pause() 
    print("Done") 

    torinfo = handle.get_torrent_info() 
    con = db.get_conncetion() 
    cur = con.cursor() 
    for f in torinfo: 
     cur.execute("INSERT INTO file_list (info_hash_id, name, size) VALUES (\""+str(info_hash_id)+"\", \""+str(f.path)+"\", "+str(f.size)+");") 
     print("INSERT INTO file_list (info_hash_id, name, size) VALUES (\""+str(info_hash_id)+"\", \""+str(f.path)+"\", "+str(f.size)+");") 
     con.commit() 
     cur.close() 
     con.close() 

我想如果我可以從info_hash獲取torrent文件,那麼我可以從torrent文件獲取文件列表。python libtorrent如何從info_hash獲取torrent文件列表?

但是當我運行我的代碼

while (not handle.has_metadata()):
沒有結束。 但像 http://magnet2torrent.com這樣的網頁給我磁力馬上

如何從info_hash獲取文件列表?

回答

2

如果您的磁鐵鏈接中沒有任何跟蹤器,則需要啓動DHT。您可以通過撥打電話:

ses.add_dht_router("router.utorrent.com", 6881) 
ses.start_dht() 

構建會話對象後。

+0

我添加了代碼,如

 magnet="magnet:?xt=urn:btih:"+info_hash ses = lt.session() ses.add_dht_router("router.utorrent.com", 6881) ses.start_dht() params = { 'save_path': './', 'duplicate_is_error': True, 'storage_mode': lt.storage_mode_t(2), 'paused': False, 'auto_managed': True, 'duplicate_is_error': True } handle = lt.add_magnet_uri(ses, magnet, params)
但循環未結束 – user2648192 2014-11-23 08:46:44

+0

您是否找到任何同行?你最終有DHT路由表中的任何節點? – Arvid 2014-11-24 07:53:44

相關問題