600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > bt种子自动发布 linux Linux制作BT种子并获取BT种子信息

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

时间:2023-04-14 16:12:40

相关推荐

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 /announce -a /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()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。