On the linux platform, you can use Python to create a BT seed and obtain the BT seed information.

Source: Internet
Author: User

On the linux platform, you can use Python to create a BT seed and obtain the BT seed information.

This article describes how to use Python to create a BT seed and obtain the BT seed information on the linux platform. We will share this with you for your reference. The details are as follows:

I recently studied how to set up the linux BT server environment. I need to prepare BT seeds in linux and obtain BT seed information. I sorted out this process:

Prepare BT seed SoftwareThis site.

Installation:

[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

The python bencode module is required to obtain the BT seed information: https://pypi.python.org/packages/source/ B /bencode/bencode-1.0.tar.gz.

Installation:

#tar -zxf bencode-1.0.tar.gz#cd bencode-1.0.tar.gz#python setup.py install

The python script for making and verifying is as follows:

#!/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 is the name of the file or directory.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.