mirror of
https://github.com/NohamR/Ratio.py.git
synced 2025-05-24 00:38:57 +00:00
multi torrents
This commit is contained in:
parent
f7484f547b
commit
f6f0ace33c
@ -11,14 +11,15 @@ from tqdm import tqdm
|
|||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from struct import unpack
|
from struct import unpack
|
||||||
|
import os
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
class process_torrent():
|
class process_torrent():
|
||||||
|
|
||||||
def __init__(self, configuration):
|
def __init__(self, configuration):
|
||||||
self.configuration = configuration
|
self.configuration = configuration
|
||||||
self.open_torrent()
|
self.open_torrent()
|
||||||
|
self.timer = 0
|
||||||
self.torrentclient = Transmission406(self.tracker_info_hash())
|
self.torrentclient = Transmission406(self.tracker_info_hash())
|
||||||
|
|
||||||
def open_torrent(self):
|
def open_torrent(self):
|
||||||
@ -28,11 +29,14 @@ class process_torrent():
|
|||||||
self.b_enc = bencoding()
|
self.b_enc = bencoding()
|
||||||
self.metainfo = self.b_enc.bdecode(data)
|
self.metainfo = self.b_enc.bdecode(data)
|
||||||
self.info = self.metainfo['info']
|
self.info = self.metainfo['info']
|
||||||
|
self.files = []
|
||||||
if 'length' not in self.info:
|
if 'length' not in self.info:
|
||||||
self.info['length'] = 0
|
self.info['length'] = 0
|
||||||
for file in self.info['files']:
|
for file in self.info['files']:
|
||||||
self.info['length'] += file['length']
|
self.info['length'] += file['length']
|
||||||
print(pretty_data(self.info['files']))
|
self.files.append(file['path'])
|
||||||
|
# print(pretty_data(self.info['files']))
|
||||||
|
# print(self.files)
|
||||||
|
|
||||||
def tracker_info_hash(self):
|
def tracker_info_hash(self):
|
||||||
raw_info = self.b_enc.get_dict('info')
|
raw_info = self.b_enc.get_dict('info')
|
||||||
@ -60,16 +64,12 @@ class process_torrent():
|
|||||||
params = tc.get_query(uploaded=0,
|
params = tc.get_query(uploaded=0,
|
||||||
downloaded=0,
|
downloaded=0,
|
||||||
event='started')
|
event='started')
|
||||||
|
|
||||||
print('----------- First Command to Tracker --------')
|
|
||||||
content = self.send_request(params, headers)
|
content = self.send_request(params, headers)
|
||||||
self.tracker_response_parser(content)
|
self.tracker_response_parser(content)
|
||||||
|
|
||||||
def tracker_response_parser(self, tr_response):
|
def tracker_response_parser(self, tr_response):
|
||||||
b_enc = bencoding()
|
b_enc = bencoding()
|
||||||
response = b_enc.bdecode(tr_response)
|
response = b_enc.bdecode(tr_response)
|
||||||
print('----------- Received Tracker Response --------')
|
|
||||||
print(pretty_data(response))
|
|
||||||
raw_peers = b_enc.get_dict('peers')
|
raw_peers = b_enc.get_dict('peers')
|
||||||
i = 0
|
i = 0
|
||||||
peers = []
|
peers = []
|
||||||
@ -83,38 +83,33 @@ class process_torrent():
|
|||||||
peers.append((ip, port))
|
peers.append((ip, port))
|
||||||
self.interval = response['interval']
|
self.interval = response['interval']
|
||||||
|
|
||||||
def wait(self):
|
def seedqueue(queue):
|
||||||
random_badtime = random.randint(10,15)*60 # interval to send request betwen 10min and 15min
|
|
||||||
self.interval = random_badtime
|
|
||||||
pbar = tqdm(total=self.interval)
|
|
||||||
print('sleep: {}'.format(self.interval))
|
|
||||||
t = 0
|
|
||||||
while t < (self.interval):
|
|
||||||
t += 1
|
|
||||||
pbar.update(1)
|
|
||||||
sleep(1)
|
|
||||||
pbar.close()
|
|
||||||
|
|
||||||
def tracker_process(self):
|
|
||||||
while True:
|
while True:
|
||||||
self.tracker_start_request()
|
waitingqueue = ""
|
||||||
|
for torrent in queue:
|
||||||
|
if torrent.timer <= 0:
|
||||||
|
torrent.tracker_start_request()
|
||||||
|
|
||||||
print('----------- Sending Command to Tracker --------')
|
min_up = torrent.interval-(torrent.interval*0.1)
|
||||||
|
max_up = torrent.interval
|
||||||
# get upload
|
|
||||||
min_up = self.interval-(self.interval*0.1)
|
|
||||||
max_up = self.interval
|
|
||||||
randomize_upload = random.randint(min_up, max_up)
|
randomize_upload = random.randint(min_up, max_up)
|
||||||
uploaded = int(self.configuration['upload'])*1000*randomize_upload
|
uploaded = int(torrent.configuration['upload'])*1000*randomize_upload
|
||||||
|
|
||||||
# get download
|
|
||||||
downloaded = 0
|
downloaded = 0
|
||||||
|
|
||||||
tc = self.torrentclient
|
tc = torrent.torrentclient
|
||||||
headers = tc.get_headers()
|
headers = tc.get_headers()
|
||||||
params = tc.get_query(uploaded=uploaded,
|
params = tc.get_query(uploaded=uploaded,
|
||||||
downloaded=downloaded,
|
downloaded=downloaded,
|
||||||
event='stopped')
|
event='stopped')
|
||||||
content = self.send_request(params, headers)
|
content = torrent.send_request(params, headers)
|
||||||
self.tracker_response_parser(content)
|
torrent.tracker_response_parser(content)
|
||||||
self.wait()
|
|
||||||
|
torrent.timer = random.randint(10,15)*60 # interval to send request betwen 10min and 15min
|
||||||
|
torrent.interval = torrent.timer
|
||||||
|
else:
|
||||||
|
torrent.timer -= 1
|
||||||
|
waitingqueue += f"Waiting {torrent.timer} seconds for {torrent.configuration['torrent']}" + "\n"
|
||||||
|
os.system('cls' if os.name == 'nt' else 'clear')
|
||||||
|
print(waitingqueue)
|
||||||
|
sleep(1)
|
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"torrent": "./file.torrent",
|
"torrents": "torrentsfolder",
|
||||||
"upload": "350"
|
"upload": "350"
|
||||||
}
|
}
|
||||||
|
31
ratio.py
31
ratio.py
@ -1,34 +1,43 @@
|
|||||||
from code.process_torrent import process_torrent
|
from code.process_torrent import process_torrent, seedqueue
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
"""Create the arguments"""
|
"""Create the arguments"""
|
||||||
parser = argparse.ArgumentParser('\nratio.py -c <configuration-file.json>')
|
parser = argparse.ArgumentParser(description="Fake ratio")
|
||||||
parser.add_argument("-c", "--configuration", help="Configuration file")
|
parser.add_argument("-c", "--configuration", help="Configuration file")
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
def load_configuration(configuration_file):
|
def load_configuration(configuration_file):
|
||||||
with open(configuration_file) as f:
|
with open(configuration_file) as f:
|
||||||
configuration = json.load(f)
|
configuration = json.load(f)
|
||||||
|
if 'torrents' not in configuration:
|
||||||
if 'torrent' not in configuration:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return configuration
|
return configuration
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
queue = []
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
if args.configuration:
|
if args.configuration:
|
||||||
configuration = load_configuration(args.configuration)
|
configuration = load_configuration(args.configuration)
|
||||||
else:
|
else:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if not configuration:
|
if not configuration:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
folder_path = configuration['torrents']
|
||||||
to = process_torrent(configuration)
|
torrents_path = []
|
||||||
to.tracker_process()
|
for root, dirs, files in os.walk(folder_path):
|
||||||
|
for file in files:
|
||||||
|
if file.endswith(".torrent"):
|
||||||
|
torrents_path.append(os.path.join(root, file))
|
||||||
|
for torrent_file in torrents_path:
|
||||||
|
config = {
|
||||||
|
"torrent": torrent_file,
|
||||||
|
"upload": configuration['upload']
|
||||||
|
}
|
||||||
|
torrent = process_torrent(config)
|
||||||
|
queue.append(torrent)
|
||||||
|
print(f'Got {len(queue)} torrents')
|
||||||
|
seedqueue(queue)
|
Loading…
x
Reference in New Issue
Block a user