mirror of
https://github.com/ap-pauloafonso/ratio-spoof.git
synced 2026-05-18 07:41:46 +00:00
argsparse and and logic args
This commit is contained in:
parent
5e45eec05f
commit
506b0ced5f
1 changed files with 30 additions and 22 deletions
52
ratio-spoof.py
Normal file → Executable file
52
ratio-spoof.py
Normal file → Executable file
|
|
@ -7,12 +7,15 @@ import random
|
||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
|
import argparse
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
def t_total_size(data):
|
def t_total_size(data):
|
||||||
return sum(map(lambda x : x['length'] , data['info']['files']))
|
return sum(map(lambda x : x['length'] , data['info']['files']))
|
||||||
|
|
||||||
def t_infohash_urlencoded(data):
|
def t_infohash_urlencoded(data, raw_data):
|
||||||
info_offsets= result['info']['byte_offsets']
|
info_offsets= data['info']['byte_offsets']
|
||||||
info_bytes = hashlib.sha1(raw_data[info_offsets[0]:info_offsets[1]]).digest()
|
info_bytes = hashlib.sha1(raw_data[info_offsets[0]:info_offsets[1]]).digest()
|
||||||
return urllib.parse.quote(info_bytes).lower()
|
return urllib.parse.quote(info_bytes).lower()
|
||||||
|
|
||||||
|
|
@ -28,35 +31,40 @@ def next_announce_total_b(kb_speed, b_current, b_piece_size,s_time, b_total_limi
|
||||||
return b_total_limit
|
return b_total_limit
|
||||||
return next_announce
|
return next_announce
|
||||||
|
|
||||||
def next_announce_left_b(b_next_total, b_total_size):
|
def next_announce_left_b(b_current, b_total_size):
|
||||||
return b_total_size - b_next_total
|
return b_total_size - b_current
|
||||||
|
|
||||||
|
|
||||||
def peer_id():
|
def peer_id():
|
||||||
peer_id = f'-qB4030-{base64.urlsafe_b64encode(uuid.uuid4().bytes)[:12].decode()}'
|
peer_id = f'-qB4030-{base64.urlsafe_b64encode(uuid.uuid4().bytes)[:12].decode()}'
|
||||||
return peer_id
|
return peer_id
|
||||||
|
|
||||||
|
def find_approx_current(b_total_size, piece_size, percent):
|
||||||
|
if( percent <= 0): return 0
|
||||||
|
total = (percent/100) * b_total_size
|
||||||
|
current_approx = int(total / piece_size) * piece_size
|
||||||
|
return current_approx
|
||||||
|
|
||||||
|
|
||||||
|
def read_file(f, args_downalod, args_upload):
|
||||||
with open(sys.argv[1], 'rb') as f:
|
|
||||||
raw_data = f.read()
|
raw_data = f.read()
|
||||||
result = bencode_parser.decode(raw_data)
|
result = bencode_parser.decode(raw_data)
|
||||||
piece_size = t_piecesize_b(result)
|
piece_size = t_piecesize_b(result)
|
||||||
total_size = t_total_size(result)
|
total_size = t_total_size(result)
|
||||||
current = piece_size
|
current_downloaded = find_approx_current(total_size,piece_size,args_downalod[0])
|
||||||
while current < total_size:
|
current_uploaded = find_approx_current(total_size,piece_size,args_upload[0])
|
||||||
current = next_announce_total_b(50, current, piece_size, 1800, total_size)
|
delay_announce =1800
|
||||||
print(f'current: {current}, {int(current/piece_size)}/{int(total_size/piece_size)}')
|
print(total_size)
|
||||||
print(len(peer_id()))
|
while True:
|
||||||
# print(t_infohash_urlencoded(result))
|
if(current_downloaded < total_size):
|
||||||
|
current_downloaded = next_announce_total_b(args_downalod[1],current_downloaded, piece_size, delay_announce, total_size)
|
||||||
# offsets =data['info']['byte_offsets']
|
current_uploaded = next_announce_total_b(args_upload[1],current_uploaded, piece_size, delay_announce)
|
||||||
#info_hash = hashlib.sha1(raw_data[offsets[0]: offsets[1]]).hexdigest()
|
print(f'currentDownload: {current_downloaded} | left: {next_announce_left_b(current_downloaded, total_size)}| currentUpload: {current_uploaded}')
|
||||||
# sha1_hash =hashlib.sha1(raw_data[offsets[0]: offsets[1]])
|
time.sleep(1)
|
||||||
#test = hashlib.sha1(raw_data[offsets[0]: offsets[1]]).digest()
|
|
||||||
#print(data['announce'])
|
|
||||||
#print(urllib.parse.quote(test).lower())
|
|
||||||
|
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('-t', required=True,help='path .torrent file' , type=argparse.FileType('rb'))
|
||||||
|
parser.add_argument('-d', required=True,type=int,help='parms for download', nargs=2 ,metavar=('%_COMPLETE', 'KBS_SPEED'))
|
||||||
|
parser.add_argument('-u',required=True,type=int,help='parms for upload', nargs=2 ,metavar=('%_COMPLETE', 'KBS_SPEED'))
|
||||||
|
args = parser.parse_args()
|
||||||
|
read_file(args.t, args.d, args.u)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue