導航:首頁 > 編程語言 > python磁鏈接下載種子文件

python磁鏈接下載種子文件

發布時間:2023-01-21 18:41:22

python 如何把磁力轉成torrent

磁鏈中包含torrent文件的hash和名稱、以及一個或多個tracker的地址。
以bittorrent協議向tracker發送下載torrent文件的請求,。tracker會返回torrent文件。

❷ 求《Python網路編程基礎》全文免費下載百度網盤資源,謝謝~

《python網路編程基礎》網路網盤pdf最新全集下載:
鏈接:https://pan..com/s/1tqW7XQTUmPWVGIU1y0tLkA

?pwd=c8d1 提取碼:c8d1
簡介:25年前,世界和現在是完全不同的。很少人能有機會和大洋彼岸的人談話。寄一封信需要好幾周的時間。收聽外國的短波新聞廣播除了需要專門的技術和耐心外,還要非常好的氣候條件。而今天,收到來自韓國的E-mail、查看加利福尼亞的天氣,以及閱讀德國當天的頭條新聞對我們來說都是很平常的事情,而且都可以在五分鍾之內完成。壓縮文件在互聯網上的傳輸使得我們可以做很多事情,從管理投資賬戶到觀看遠房親戚的照片。

❸ 求《Python編程金典》全文免費下載百度網盤資源,謝謝~

《Python編程金典》網路網盤pdf最新全集下載:
鏈接:https://pan..com/s/1eRMjMR1Ujg5b00SXqlTy0w

?pwd=ovx9 提取碼:ovx9
簡介:Python編程金典採用作者獨創的「活代碼」教學方式.層層揭示7Python這一程序設計語言的強大功能,並通過穿插在全書各處的屏幕輸出和編程技巧與提示,幫助讀者搭建良好的知識結構,養成良好的編程習慣、避免常見的縮程錯誤以及寫出高效、可靠的應用程序。

❹ 如何使用python實現bt種子和磁力鏈接的相互轉換

相應的將BT種子轉換為磁力鏈代碼為:

import bencode, hashlib, base64, urllib
torrent = open('ubuntu-12.04.2-server-amd64.iso.torrent', 'rb').read()
metadata = bencode.bdecode(torrent)
hashcontents = bencode.bencode(metadata['info'])
digest = hashlib.sha1(hashcontents).digest()
b32hash = base64.b32encode(digest)
params = {'xt': 'urn:btih:%s' % b32hash,
'dn': metadata['info']['name'],
'tr': metadata['announce'],
'xl': metadata['info']['length']}
paramstr = urllib.urlencode(params)
magneturi = 'magnet:?%s' % paramstr
print magneturi

還有另外一個效率相對較高,而且更方便的方案是安裝libtorrent,在ubuntu只需要apt-get install python-libtorrent即可對應轉換磁力鏈的代碼為:
import libtorrent as bt
info = bt.torrent_info('test.torrent')
print "magnet:?xt=urn:btih:%s&dn=%s" % (info.info_hash(), info.name())

轉換磁力鏈接為bt種子文件
下面來看一個反過程,將磁力鏈轉化為種子文件。
1、需要先安裝python-libtorrent包 ,在ubuntu環境下,可以通過以下指令完成安裝:
# sudo apt-get install python-libtorrent

2、代碼如下:
#!/usr/bin/env python
import shutil
import tempfile
import os.path as pt
import sys
import libtorrent as lt
from time import sleep
def magnet2torrent(magnet, output_name=None):
if output_name and \
not pt.isdir(output_name) and \
not pt.isdir(pt.dirname(pt.abspath(output_name))):
print("Invalid output folder: " + pt.dirname(pt.abspath(output_name)))
print("")
sys.exit(0)
tempdir = tempfile.mkdtemp()
ses = lt.session()
params = {
'save_path': tempdir,
'plicate_is_error': True,
'storage_mode': lt.storage_mode_t(2),
'paused': False,
'auto_managed': True,
'plicate_is_error': True
}
handle = lt.add_magnet_uri(ses, magnet, params)
print("Downloading Metadata (this may take a while)")
while (not handle.has_metadata()):
try:
sleep(1)
except KeyboardInterrupt:
print("Aborting...")
ses.pause()
print("Cleanup dir " + tempdir)
shutil.rmtree(tempdir)
sys.exit(0)
ses.pause()
print("Done")
torinfo = handle.get_torrent_info()
torfile = lt.create_torrent(torinfo)
output = pt.abspath(torinfo.name() + ".torrent")
if output_name:
if pt.isdir(output_name):
output = pt.abspath(pt.join(
output_name, torinfo.name() + ".torrent"))
elif pt.isdir(pt.dirname(pt.abspath(output_name))):
output = pt.abspath(output_name)
print("Saving torrent file here : " + output + " ...")
torcontent = lt.bencode(torfile.generate())
f = open(output, "wb")
f.write(lt.bencode(torfile.generate()))
f.close()
print("Saved! Cleaning up dir: " + tempdir)
ses.remove_torrent(handle)
shutil.rmtree(tempdir)
return output
def showHelp():
print("")
print("USAGE: " + pt.basename(sys.argv[0]) + " MAGNET [OUTPUT]")
print(" MAGNET\t- the magnet url")
print(" OUTPUT\t- the output torrent file name")
print("")
def main():
if len(sys.argv) < 2:
showHelp()
sys.exit(0)
magnet = sys.argv[1]
output_name = None
if len(sys.argv) >= 3:
output_name = sys.argv[2]
magnet2torrent(magnet, output_name)
if __name__ == "__main__":
main()

3、用法如下
# python Magnet_To_Torrent2.py <magnet link> [torrent file]

❺ 求《python簡明教程中文》全文免費下載百度網盤資源,謝謝~

《python簡明教程中文》網路網盤pdf最新全集下載:
鏈接: https://pan..com/s/1XFNlyTxkH8wW404BJoJCwg

?pwd=97h3 提取碼: 97h3
簡介:Python語言可能是第一種即簡單又功能強大的編程語言。它不僅適合於初學者,也適合於專業人員使用,更加重要的是,用Python編程是一種愉快的事。本身將幫助你學習這個奇妙的語言,並且向你展示如何即快捷又方便地完成任務一一真正意義上「為編程問題提供的完美解決方案!」

❻ 求《python語言入門》全文免費下載百度網盤資源,謝謝~

《python語言入門》網路網盤pdf最新全集下載:
鏈接:https://pan..com/s/1sUwZer9FylBQ9RVqsQRUdA

?pwd=nd76 提取碼:nd76
簡介:Python語言入門將對Python編程語言做全面而精煉的介紹。Python是一種流行的面向對象語言,既可用於獨立的程序,也可用於腳本程序,適用於各種領域。它是自由的、可移植的、強大的,而且非常易於使用。

閱讀全文

與python磁鏈接下載種子文件相關的資料

熱點內容
我的世界如何查看伺服器種子pc 瀏覽:282
linuxlamp編譯安裝 瀏覽:609
枚舉演算法ppt 瀏覽:184
cmd查看進程命令 瀏覽:956
手機內怎麼刪除APP 瀏覽:834
魚群和鳥群演算法區別 瀏覽:93
pdf尺寸設置 瀏覽:211
android訪問本地伺服器 瀏覽:512
程序員相親被刪除微信 瀏覽:790
centos命令窗口 瀏覽:596
編譯器有幾個好用的 瀏覽:500
資料庫和網站如何搭載伺服器 瀏覽:154
網路流理論演算法與應用 瀏覽:795
java和matlab 瀏覽:388
釘釘蘋果怎麼下app軟體 瀏覽:832
php網站驗證碼不顯示 瀏覽:859
鋁膜構造柱要設置加密區嗎 瀏覽:344
考駕照怎麼找伺服器 瀏覽:885
阿里雲伺服器如何更換地區 瀏覽:972
手機app調音器怎麼調古箏 瀏覽:503