linux平臺使用Python制作BT種子并獲取BT種子信息的方法
本文實例講述了linux平臺使用Python制作BT種子并獲取BT種子信息的方法。分享給大家供大家參考,具體如下:
最近研究了一下linux BT服務(wù)器環(huán)境的搭建,需要在linux下制作BT種子并獲取BT種子信息,整理了一下這個過程:
制作BT種子軟件本站下載地址。
安裝:
[root@localhost src]# tar zxf mktorrent-1.0.tar.gz [root@localhost src]# cd mktorrent-1.0 [root@localhost mktorrent-1.0]# make [root@localhost mktorrent-1.0]# make install [root@localhost ~]# which mktorrent /usr/local/bin/mktorrent
需要python的bencode模塊來獲取BT種子信息,下載地址: https://pypi.python.org/packages/source/b/bencode/bencode-1.0.tar.gz。
安裝:
#tar -zxf bencode-1.0.tar.gz #cd bencode-1.0.tar.gz #python setup.py install
制作和驗證的python腳本如下:
#!/usr/bin/env python # -*- coding: utf-8 -*- import os, re, time, sys import hashlib, bencode file_name = 'bt_test.exe' bt_source = '/data/updir/%s' % file_name bt_name = '/data/source/%s.torrent' % file_name if os.path.exists(bt_name): os.remove(bt_name) if os.path.exists(bt_source): conm = "/usr/local/bin/mktorrent -v -p -l 18 -a http://bt1.text.cn/announce -a http://bt2.text.cn/announce -o %s %s" % (bt_name,bt_source) res = os.popen(conm).readlines()[-1].strip() if 'done' in res: bt_path = {} bt_file = open(bt_name, 'rb') bt_info = bencode.bdecode(bt_file.read()).get('info') bt_info_hash_hex = hashlib.sha1(bencode.bencode(bt_info)).hexdigest() if os.path.isdir(bt_source): bt_file_size = 0 for length in bt_info.get('files'): bt_file_size = bt_file_size + int(length['length']) bt_path['/'.join(length['path'])] = length['length'] else: bt_file_size = bt_info.get('length') bt_file_name = bt_info.get('name') bt_path[bt_file_name]=bt_file_size bt_file.close() print bt_path print "Create torrent success" else: print "Create torrent Error" sys.exit() else: print "This source not find" sys.exit()
file_name為做種的文件或目錄名字。
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python文件與目錄操作技巧匯總》、《Python文本文件操作技巧匯總》、《Python URL操作技巧總結(jié)》、《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進(jìn)階經(jīng)典教程》
希望本文所述對大家Python程序設(shè)計有所幫助。
相關(guān)文章
python實現(xiàn)圖片數(shù)據(jù)增強(qiáng)的示例詳解
這篇文章主要為大家詳細(xì)介紹了python實現(xiàn)圖片數(shù)據(jù)增強(qiáng)的相關(guān)知識,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價值,感興趣的小伙伴可以跟隨小編一起了解一下2023-10-10Python利用BeautifulSoup解析網(wǎng)頁內(nèi)容
當(dāng)今信息爆炸的時代,網(wǎng)絡(luò)上充斥著海量的數(shù)據(jù),而網(wǎng)絡(luò)爬蟲作為一種數(shù)據(jù)采集工具,扮演著至關(guān)重要的角色,BeautifulSoup 是一個Python庫,它可以從HTML或XML文件中提取數(shù)據(jù),本文介紹了Python如何利用BeautifulSoup解析網(wǎng)頁內(nèi)容,需要的朋友可以參考下2024-06-06matplotlib實現(xiàn)熱成像圖colorbar和極坐標(biāo)圖的方法
今天小編就為大家分享一篇matplotlib實現(xiàn)熱成像圖colorbar和極坐標(biāo)圖的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12Python爬蟲:將headers請求頭字符串轉(zhuǎn)為字典的方法
今天小編就為大家分享一篇Python爬蟲:將headers請求頭字符串轉(zhuǎn)為字典的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08Python微醫(yī)掛號網(wǎng)醫(yī)生數(shù)據(jù)抓取
今天小編就為大家分享一篇關(guān)于Python微醫(yī)掛號網(wǎng)醫(yī)生數(shù)據(jù)抓取,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-01-01python的三目運(yùn)算符和not in運(yùn)算符使用示例
這篇文章主要介紹了python的三目運(yùn)算符和not in運(yùn)算符使用示例,需要的朋友可以參考下2014-03-03