bt种子自动发布 linux,Linux制作BT种子并获取BT种子信息

引用:

#!/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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值