国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

linux平臺使用Python制作BT種子并獲取BT種子信息的方法

2019-11-25 16:23:33
字體:
來源:轉載
供稿:網友

本文實例講述了linux平臺使用Python制作BT種子并獲取BT種子信息的方法。分享給大家供大家參考,具體如下:

最近研究了一下linux BT服務器環境的搭建,需要在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, sysimport hashlib, bencodefile_name = 'bt_test.exe'bt_source = '/data/updir/%s' % file_namebt_name = '/data/source/%s.torrent' % file_nameif 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為做種的文件或目錄名字。

更多關于Python相關內容感興趣的讀者可查看本站專題:《Python文件與目錄操作技巧匯總》、《Python文本文件操作技巧匯總》、《Python URL操作技巧總結》、《Python圖片操作技巧總結》、《Python數據結構與算法教程》、《Python Socket編程技巧總結》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》及《Python入門與進階經典教程

希望本文所述對大家Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 拜泉县| 西藏| 滨州市| 九寨沟县| 镇康县| 滦南县| 工布江达县| 淮阳县| 无为县| 河西区| 自治县| 平谷区| 顺平县| 瑞金市| 阳朔县| 凉山| 宜章县| 乐清市| 广州市| 招远市| 浦县| 静安区| 大城县| 道真| 东乡族自治县| 基隆市| 石狮市| 嘉禾县| 天长市| 石楼县| 蓝山县| 若羌县| 西华县| 铜鼓县| 时尚| 江都市| 金寨县| 边坝县| 嘉定区| 休宁县| 开封县|