-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtorrent.py
More file actions
executable file
·63 lines (56 loc) · 2.73 KB
/
Copy pathtorrent.py
File metadata and controls
executable file
·63 lines (56 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import humanize
import qbittorrentapi
from telegram import Update
from telegram.ext import ContextTypes
from hurry.filesize import size
import config
from utils import no_can_do, print_progressbar, printlog
_localize = humanize.i18n.activate("it_IT")
type(_localize)
async def lista_torrent(update: Update, context: ContextTypes.DEFAULT_TYPE):
if await no_can_do(update, context):
return
if update.effective_user.id not in config.ADMINS:
return
# print(f'{get_now()} {await get_display_name(update.effective_user)} in {await get_chat_name(update.message.chat.id)} chiede la lista torrent')
await printlog(update, "chiede la lista torrent")
# instantiate a Client using the appropriate WebUI configuration
# TORRENT
qbt_client = qbittorrentapi.Client(
host=f"{config.TORRENT_IP}:{config.TORRENT_PORT}",
username=config.TORRENT_USER,
password=config.TORRENT_PASSWORD,
REQUESTS_ARGS={"timeout": 2.1},
)
# the Client will automatically acquire/maintain a logged in state in line with any request.
# therefore, this is not necessary; however, you many want to test the provided login credentials.
# try:
# qbt_client.auth_log_in()
# except Exception as e:
# print(e)
# display qBittorrent info
# print(f'qBittorrent: {qbt_client.app.version}')
# print(f'qBittorrent Web API: {qbt_client.app.web_api_version}')
# for k,v in qbt_client.app.build_info.items(): print(f'{k}: {v}')
# retrieve and show all torrents
message = ""
try:
torrents_info = qbt_client.torrents_info(sort="progress")
if not torrents_info:
await update.message.reply_text("Nessun torrent in download")
return
else:
for torrent in torrents_info:
if torrent.progress == 1:
message += f"[100%] <b>{torrent.name}</b> (<i>{torrent.state}</i>)\n\n"
else:
progress_perc = round(torrent.progress * 100, 2)
message += f'<b>{torrent.name}</b> (<i>{torrent.state}</i>) {size(torrent.total_size)}\n↓ {str(round(torrent.dlspeed/1024/1024, 2))} MB/s · ↑ {str(round(torrent.upspeed/1024/1024, 2))} MB/s\nETA: {"∞" if torrent.eta == 8640000 else (str(humanize.precisedelta(torrent.eta, suppress=["days"], minimum_unit="seconds")))}\n{str(progress_perc)}% {print_progressbar(progress_perc, suffix="", prefix="")}\n\n'
if not message:
await update.message.reply_text("Nessun torrent in download")
else:
await update.message.reply_html(message)
except Exception as e:
await update.message.reply_text(f"Errore!\n{e}")
# # pause all torrents
# qbt_client.torrents.pause.all()