Tôi đã đọc qua số manual và tôi không thể tìm thấy câu trả lời. Với một liên kết nam châm, tôi muốn tạo một tệp torrent để nó có thể được tải vào lần khởi động tiếp theo để tránh tải xuống lại siêu dữ liệu. Tôi đã thử tính năng tiếp tục nhanh, nhưng tôi vẫn phải tìm nạp dữ liệu meta khi tôi thực hiện và có thể mất khá nhiều thời gian. Ví dụ mà tôi đã thấy là để tạo ra các tập tin torrent cho một torrent mới, nơi mà tôi muốn tạo ra một phù hợp với một uri nam châm.Libtorrent - Với một liên kết nam châm, làm thế nào để bạn tạo ra một tập tin torrent?
Trả lời
Giải pháp tìm thấy ở đây:
http://code.google.com/p/libtorrent/issues/detail?id=165#c5
Xem tạo torrent:
http://www.rasterbar.com/products/libtorrent/make_torrent.html
Sửa đổi dòng đầu tiên:
file_storage fs;
// recursively adds files in directories
add_files(fs, "./my_torrent");
create_torrent t(fs);
Để này:
torrent_info ti = handle.get_torrent_info()
create_torrent t(ti)
"xử lý" là từ đây:
torrent_handle add_magnet_uri(session& ses, std::string const& uri add_torrent_params p);
Ngoài ra trước khi tạo torrent bạn phải chắc chắn rằng siêu dữ liệu đã được tải, thực hiện điều này bằng cách gọi handle.has_metadata()
.
CẬP NHẬT
Có vẻ như libtorrent python api đang thiếu một số c quan trọng ++ api đó là cần thiết để tạo torrent từ nam châm, ví dụ trên sẽ không làm việc trong python nguyên nhân lớp create_torrent
python không chấp nhận torrent_info như tham số (C++ có sẵn).
Vì vậy, tôi đã cố gắng nói cách khác, nhưng cũng gặp phải một bức tường gạch mà làm cho nó không thể, đây là mã:
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()
Có một lỗi ném vào dòng này:
torfile.set_hash(i, hash)
Nó hy vọng băm là const char*
nhưng torrent_info.hash_for_piece(int)
trả về lớp big_number
mà không có api để chuyển đổi nó trở lại const char *.
Khi tôi tìm thấy một số thời gian, tôi sẽ báo cáo lỗi api bị thiếu này cho các nhà phát triển libtorrent, vì hiện tại không thể tạo tệp .torrent từ một uri nam châm khi sử dụng các ràng buộc python.
torrent_info.orig_files()
cũng bị thiếu trong các ràng buộc python, tôi không chắc liệu torrent_info.files()
có đủ hay không.
UPDATE 2
tôi đã tạo ra một vấn đề về vấn đề này, nhìn thấy nó ở đây: http://code.google.com/p/libtorrent/issues/detail?id=294
sao nó để họ sửa chữa nó nhanh.
CẬP NHẬT 3
Nó được cố định bây giờ, có một phiên bản 0.16.0. Binaries cho các cửa sổ cũng có sẵn.
Cảm ơn bạn rất nhiều vì tất cả công việc khó khăn! – ciferkey
Nếu lưu resume data không hoạt động cho bạn, bạn có thể tạo tệp torrent mới bằng thông tin từ kết nối hiện có.
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()
Tôi nghi ngờ rằng nó sẽ làm cho bản lý lịch nhanh hơn chức năng được tạo riêng cho mục đích này.
Hãy thử để xem mã này http://code.google.com/p/libtorrent/issues/attachmentText?id=165&aid=-5595452662388837431&name=java_client.cpp&token=km_XkD5NBdXitTaBwtCir8bN-1U%3A1327784186190 nó sử dụng add_magnet_uri mà tôi nghĩ là những gì bạn cần
Chỉ muốn cung cấp một bản cập nhật nhanh chóng bằng cách sử dụng gói libtorrent Python hiện đại: libtorrent bây giờ có parse_magnet_uri
phương pháp mà bạn có thể sử dụng để tạo ra một tay cầm torrent:
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
- 1. Làm thế nào để có được đồng đẳng đầu tiên từ một liên kết nam châm torrent?
- 2. tải một Torrent với libtorrent-python
- 3. Làm thế nào để bạn xây dựng một bộ chỉ mục tập tin torrent?
- 4. Làm thế nào để tìm ra nếu một tập tin là một liên kết?
- 5. Làm thế nào để tạo một liên kết đến một tập tin trong rst với nhân sư?
- 6. Làm thế nào để tạo ra một liên kết tượng trưng với SCons?
- 7. Làm thế nào để bạn liên kết một cột GridView với một giá trị lớp con?
- 8. Đọc tập tin từ torrent
- 9. Làm thế nào để bạn liên kết một CollectionContainer với một bộ sưu tập trong một mô hình khung nhìn?
- 10. MySQL làm thế nào để bạn thêm vào một tập tin với INTO OUTFILE?
- 11. Làm thế nào thường python tuôn ra một tập tin?
- 12. Làm thế nào để tạo ra tập tin chơi heroku?
- 13. Làm thế nào để trích xuất tên tập tin từ một tập tin URI và tạo một liên kết cho cùng?
- 14. Làm thế nào để bạn liên kết XML với XSD?
- 15. Làm thế nào để bạn chọn tên tập tin của một maven jar-với-phụ thuộc?
- 16. Làm thế nào để lập trình tạo ra một tập tin "true" Excel
- 17. Làm thế nào để sử dụng DownloadLink của Wicket với một tập tin được tạo ra khi đang bay?
- 18. Làm thế nào để thêm một cột từ một tập tin vào một tập tin
- 19. So sánh 2 tập tin Unix và kết nối đầu ra với một tập tin mới?
- 20. Làm thế nào để bạn xác định bằng cách sử dụng stat() cho dù một tập tin là một liên kết tượng trưng?
- 21. mã Java để tạo ra một tập tin JAR
- 22. Làm thế nào để liên kết một .DLL tĩnh?
- 23. Làm thế nào để thực hiện một hành động liên kết như một đầu vào tập tin
- 24. Làm thế nào để nhúng một tập tin vào một tập tin HTML?
- 25. Làm thế nào để bạn liên kết một DropDownList trong một GridView trong trường EditItemTemplate?
- 26. Tạo một liên kết cứng từ một tập tin xử lý trên Unix?
- 27. Trong Python nhân sư, làm thế nào để liên kết đến một tập tin trong thư mục _static
- 28. Làm thế nào để viết trong một tập tin với nhiều chủ đề?
- 29. liên kết một tập tin .proto sử dụng qmake
- 30. Python & GTK3: Làm thế nào để tạo ra một Liststore
Cấp, tài liệu là khủng khiếp (mặc dù kỳ lạ có thể sử dụng). Tuy nhiên, có gì sai với phần mở rộng siêu dữ liệu http://www.rasterbar.com/products/libtorrent/manual.html#add-extension? –