Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manpage #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ foo@bar:~/ratio.py$ python ratio.py -c configuration.json
```js
{
"torrent": "<Torrent file path>",
"upload": "<Upload speed (kB/s)>"
"upload": "<Upload speed (kB/s)>",
"client: "<transmission/qbittorrent>""
}
```
8 changes: 6 additions & 2 deletions code/process_torrent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from code.decoding_bencoded import bencoding
from code.torrentclientfactory import Transmission292
from code.torrentclientfactory import Transmission292, Qbittorrent425
from code.pretty import pretty_data, pretty_GET

from hashlib import sha1
Expand All @@ -19,7 +19,11 @@ class process_torrent():
def __init__(self, configuration):
self.configuration = configuration
self.open_torrent()
self.torrentclient = Transmission292(self.tracker_info_hash())

if configuration['client'] == 'transmission':
self.torrentclient = Transmission292(self.tracker_info_hash())
elif configuration['client'] == 'qbittorrent':
self.torrentclient = Qbittorrent425(self.tracker_info_hash())

def open_torrent(self):
torrent_file = self.configuration['torrent']
Expand Down
58 changes: 58 additions & 0 deletions code/torrentclientfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,61 @@ def generate_key(self):
chars = 'ABCDEF' + string.digits
key = self.id_generator(chars, 8)
return key

class Qbittorrent425():
def __init__(self, info_hash):
self.name = "qBittorrent"
parameters = {}
# urlencoded 20-byte SHA1 hash of the value of the info key from the Metainfo file
parameters['info_hash'] = info_hash
# urlencoded 20-byte string used as a unique ID for the client
parameters["peer_id"] = self.generate_peer_id()
# The port number that the client is listening on
parameters["port"] = random.randint(1025, 65535)
# Number of peers that the client would like to receive from the tracker
parameters["numwant"] = 80
# An additional identification that is not shared with any other peers
parameters["key"] = self.generate_key()
# Setting this to 1 indicates that the client accepts a compact response
parameters["compact"] = 0
# Setting this to 1 indicates that the client accepts crypto
parameters["supportcrypto"] = 1
self.parameters = parameters

def get_headers(self):
headers = {}
headers['User-Agent'] = 'qBittorrent/4.25'
headers['Accept'] = '*/*'
headers['Accept-Encoding'] = 'Accept-Encoding: gzip;q=1.0, deflate, identity'
return headers

def get_query(self, uploaded, downloaded, left=0, event=None):
# The total amount uploaded (since the client sent the 'started' event)
self.parameters["uploaded"] = uploaded
# The total amount downloaded (since the client sent the 'started' event)
self.parameters["downloaded"] = downloaded
# The number of bytes this client still has to download
self.parameters["left"] = left
# If specified, must be one of started, completed, stopped
if event:
self.parameters["event"] = event
params = '&'.join('{}={}'.format(k, v)
for k, v in self.parameters.items())
return params

def id_generator(self, chars, size):
id = ''
for _ in range(size):
id += random.choice(chars)
return id

def generate_peer_id(self):
chars = string.ascii_lowercase + string.digits
rand_id = self.id_generator(chars, 12)
peer_id = "-qB425-" + rand_id
return peer_id

def generate_key(self):
chars = 'ABCDEF' + string.digits
key = self.id_generator(chars, 8)
return key
21 changes: 21 additions & 0 deletions ratio.py.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.\" Process this file with
.\" groff -man -Tascii ratio.py.1
.\"
.TH Ratio.py 1 "AUGUST 2020" Linux "General Commands Manual"
.SH NAME
raio.py - Send fake infos to the torrent trackers
.SH SYNOPSIS
ratio.py -c [CONFIG_FILE]
.SH DESCRIPTION
Ratio.py is a small command line program in Python3. It fakes upload stats of a torrent. Currently the supported emulators are : Transmission and qBittorent
.IP "-h, --help"
show this help message and exit
.IP "-c --config"
path to the configuration file
.IP "-t, --torrent"
path to the torrent file
.IP "-u, --upload"
upload rate in kb/s
.IP "-C, --client"
client (transmission/qbittorrent)
.I