mirror of
https://github.com/house-of-vanity/gaspar.git
synced 2025-08-21 15:37:16 +00:00
Add transmision client support.
This commit is contained in:
@@ -105,6 +105,15 @@ class DataBase:
|
|||||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"""
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ? )"""
|
||||||
self.execute(sql, attrs)
|
self.execute(sql, attrs)
|
||||||
|
|
||||||
|
def add_client(self, user_id, host, port):
|
||||||
|
sql = """INSERT OR REPLACE INTO tr_clients(user_id, host, port)
|
||||||
|
VALUES(?, ?, ?);"""
|
||||||
|
self.execute(sql, (user_id, host, port))
|
||||||
|
|
||||||
|
def get_client(self, user_id):
|
||||||
|
sql = "SELECT host, port FROM tr_clients WHERE user_id = ?"
|
||||||
|
return self.execute(sql, (user_id,))[0]
|
||||||
|
|
||||||
def get_attr(self, tor_id, attr):
|
def get_attr(self, tor_id, attr):
|
||||||
sql = """SELECT %s FROM torrents WHERE id = ? ORDER BY reg_time DESC LIMIT 1""" % attr
|
sql = """SELECT %s FROM torrents WHERE id = ? ORDER BY reg_time DESC LIMIT 1""" % attr
|
||||||
return self.execute(sql, (tor_id,))[0][0]
|
return self.execute(sql, (tor_id,))[0][0]
|
||||||
|
@@ -10,7 +10,7 @@ from .database import DataBase
|
|||||||
from .tools import format_topic
|
from .tools import format_topic
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.DEBUG,
|
level=logging.INFO,
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -73,17 +73,22 @@ def main():
|
|||||||
update.message.reply_text(msg, parse_mode='HTML', disable_web_page_preview=True)
|
update.message.reply_text(msg, parse_mode='HTML', disable_web_page_preview=True)
|
||||||
|
|
||||||
def handle_client(update, context):
|
def handle_client(update, context):
|
||||||
|
u_id = update.message.chat['id']
|
||||||
log.info(
|
log.info(
|
||||||
"Got /client request from user [%s] %s",
|
"Got /client request from user [%s] %s",
|
||||||
update.message.chat['id'],
|
u_id,
|
||||||
update.message.from_user.username)
|
update.message.from_user.username)
|
||||||
try:
|
try:
|
||||||
host, port = update.message.text.split(':')
|
host, port = update.message.text.split(':')
|
||||||
|
host = host.split(' ')[1]
|
||||||
except:
|
except:
|
||||||
update.message.reply_text(
|
update.message.reply_text(
|
||||||
'Send transmission RPC address like <b>host:port</b>',
|
'Send transmission RPC address like <b>host:port</b>',
|
||||||
parse_mode='HTML',
|
parse_mode='HTML',
|
||||||
disable_web_page_preview=True)
|
disable_web_page_preview=True)
|
||||||
|
return
|
||||||
|
torrent.db.add_client(u_id, host, port)
|
||||||
|
log.info(torrent.db.get_client(u_id))
|
||||||
|
|
||||||
|
|
||||||
updater = Updater(token, use_context=True)
|
updater = Updater(token, use_context=True)
|
||||||
|
@@ -52,6 +52,9 @@ def update_watcher(bot):
|
|||||||
subs = torrent.db.get_subscribers(alert['id'])
|
subs = torrent.db.get_subscribers(alert['id'])
|
||||||
for sub in subs:
|
for sub in subs:
|
||||||
bot.sendMessage(sub, msg, parse_mode='HTML', disable_web_page_preview=True)
|
bot.sendMessage(sub, msg, parse_mode='HTML', disable_web_page_preview=True)
|
||||||
|
host, port = torrent.db.get_client(sub)
|
||||||
|
if host and port:
|
||||||
|
add_tor(host, port, torrent.meta['info_hash'])
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
time.sleep(UPDATE_INTERVAL)
|
time.sleep(UPDATE_INTERVAL)
|
||||||
update_thread = threading.Thread(target=__thread)
|
update_thread = threading.Thread(target=__thread)
|
||||||
|
@@ -36,5 +36,11 @@ CREATE TABLE IF NOT EXISTS "alerts" (
|
|||||||
tor_id TEXT,
|
tor_id TEXT,
|
||||||
UNIQUE(user_id, tor_id)
|
UNIQUE(user_id, tor_id)
|
||||||
);
|
);
|
||||||
|
CREATE TABLE IF NOT EXISTS "tr_clients" (
|
||||||
|
user_id TEXT,
|
||||||
|
host TEXT,
|
||||||
|
port TEXT,
|
||||||
|
UNIQUE(user_id)
|
||||||
|
);
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
from transmission_rpc import Client
|
from transmission_rpc import Client
|
||||||
|
|
||||||
def add_tor(tor_hash):
|
def add_tor(host, port, tor_hash):
|
||||||
c = Client(host='msk.hexor.ru', port=80)
|
c = Client(host=host, port=port)
|
||||||
m = f'magnet:?xt=urn:btih:{tor_hash}'
|
m = f'magnet:?xt=urn:btih:{tor_hash}'
|
||||||
c.add_torrent(m)
|
c.add_torrent(m)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user