導航:首頁 > 編程語言 > 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磁鏈接下載種子文件相關的資料

熱點內容
為什麼代理伺服器沒響應 瀏覽:562
小程序編譯提示 瀏覽:823
nameerrorpython 瀏覽:294
辭典pdf下載 瀏覽:801
遺傳演算法違反約束路徑數目 瀏覽:177
少年班中的古人演算法 瀏覽:931
什麼app一鍵p圖好看 瀏覽:573
查詢手機連上電腦的命令 瀏覽:850
javasftp實現 瀏覽:369
源碼升級的意思 瀏覽:399
緩解壓力手勢圖片下載 瀏覽:96
程序員抽煙找靈感 瀏覽:767
老火湯pdf 瀏覽:224
少有人走的路與心靈對話pdf 瀏覽:205
兩單片機串口通信 瀏覽:801
程序員過試用期 瀏覽:108
演算法信息量不可計算 瀏覽:954
android淘寶防止反編譯 瀏覽:788
PIC單片機的內核寄存器 瀏覽:725
擠黑頭解壓視頻耳朵 瀏覽:771