2014-11-23 3 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에서 토런트 파일을 가져올 수 있다면 토런트 파일에서 파일 목록을 가져올 수 있다고 생각합니다.python libtorrent info_hash에서 토런트 파일 목록을 얻는 방법은 무엇입니까?

그러나 내 코드를 실행할 때

while (not handle.has_metadata()):
끝나지 않았습니다. 하지만 웹 페이지는 http://magnet2torrent.com입니다. 즉시 급류를 내게됩니다.

info_hash에서 파일 목록을 가져 오는 방법은 무엇입니까?

답변

2

자석 링크에 추적기가없는 경우 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

+0

다른 피어를 전혀 찾으십니까? 결국 DHT 라우팅 테이블에 노드가 생기게됩니까? – Arvid