Skip to content

Commit

Permalink
fix a qbit error and status
Browse files Browse the repository at this point in the history
  • Loading branch information
5hojib committed Dec 9, 2024
1 parent 38d55bf commit 369c59e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
53 changes: 30 additions & 23 deletions bot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import subprocess
from asyncio import Lock, new_event_loop, set_event_loop
from datetime import datetime
from logging import (
Expand All @@ -13,11 +14,10 @@
info,
warning,
)
from os import environ, remove
from os import environ, remove, getcwd
from os import path as ospath
from shutil import rmtree
from socket import setdefaulttimeout
from subprocess import Popen, check_output, run
from sys import exit
from time import time

Expand Down Expand Up @@ -445,20 +445,21 @@ def format(self, record: LogRecord) -> str:
index_urls.append("")

PORT = environ.get("BASE_URL_PORT") or environ.get("PORT")
Popen(
subprocess.Popen(
f"gunicorn web.wserver:app --bind 0.0.0.0:{PORT} --worker-class gevent",
shell=True,
)

run(["xnox", "-d", "--profile=."], check=False)
subprocess.run(["xnox", "-d", f"--profile={getcwd()}"], check=False)

if not ospath.exists(".netrc"):
with open(".netrc", "w"):
pass
run(["chmod", "600", ".netrc"], check=False)
run(["cp", ".netrc", "/root/.netrc"], check=False)
subprocess.run(["chmod", "600", ".netrc"], check=False)
subprocess.run(["cp", ".netrc", "/root/.netrc"], check=False)

trackers = (
check_output(
subprocess.check_output(
"curl -Ns https://raw.githubusercontent.com/XIU2/TrackersListCollection/master/all.txt https://ngosang.github.io/trackerslist/trackers_all_http.txt https://newtrackon.com/api/all https://raw.githubusercontent.com/hezhijie0327/Trackerslist/main/trackerslist_tracker.txt | awk '$0' | tr '\n\n' ','",
shell=True,
)
Expand All @@ -470,7 +471,7 @@ def format(self, record: LogRecord) -> str:
if TORRENT_TIMEOUT is not None:
a.write(f"bt-stop-timeout={TORRENT_TIMEOUT}\n")
a.write(f"bt-tracker=[{trackers}]")
run(["xria", "--conf-path=/usr/src/app/a2c.conf"], check=False)
subprocess.run(["xria", "--conf-path=/usr/src/app/a2c.conf"], check=False)


if ospath.exists("shorteners.txt"):
Expand All @@ -485,16 +486,14 @@ def format(self, record: LogRecord) -> str:
if ospath.exists("accounts.zip"):
if ospath.exists("accounts"):
rmtree("accounts")
run(["7z", "x", "-o.", "-aoa", "accounts.zip", "accounts/*.json"], check=False)
run(["chmod", "-R", "777", "accounts"], check=False)
subprocess.run(["7z", "x", "-o.", "-aoa", "accounts.zip", "accounts/*.json"], check=False)
subprocess.run(["chmod", "-R", "777", "accounts"], check=False)
remove("accounts.zip")
if not ospath.exists("accounts"):
config_dict["USE_SERVICE_ACCOUNTS"] = False


alive = Popen(["python3", "alive.py"])

aria2 = API(ariaClient(host="http://localhost", port=6800, secret=""))
alive = subprocess.Popen(["python3", "alive.py"])


xnox_client = QbClient(
Expand Down Expand Up @@ -526,22 +525,30 @@ def format(self, record: LogRecord) -> str:
"server-stat-of",
]

aria2 = API(ariaClient(host="http://localhost", port=6800, secret=""))

if not aria2_options:
aria2_options = aria2.client.get_global_option()
else:
a2c_glo = {op: aria2_options[op] for op in aria2c_global if op in aria2_options}
aria2.set_global_options(a2c_glo)

if not qbit_options:
qbit_options = dict(xnox_client.app_preferences())
del qbit_options["listen_port"]
for k in list(qbit_options.keys()):
if k.startswith("rss"):
del qbit_options[k]
else:
qb_opt = {**qbit_options}
xnox_client.app_set_preferences(qb_opt)

def get_qb_options():
global qbit_options
if not qbit_options:
qbit_options = dict(xnox_client.app_preferences())
del qbit_options["listen_port"]
for k in list(qbit_options.keys()):
if k.startswith("rss"):
del qbit_options[k]
xnox_client.app_set_preferences({"web_ui_password": "mltbmltb"})
else:
qbit_options["web_ui_password"] = "mltbmltb"
qb_opt = {**qbit_options}
xnox_client.app_set_preferences(qb_opt)


get_qb_options()

info("Creating client from BOT_TOKEN")
bot = TgClient(
Expand Down
4 changes: 2 additions & 2 deletions bot/helper/ext_utils/status_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ async def get_readable_message(sid, is_user, page_no=1, status="All"):
msg += f"\n<b>Ratio: </b>{task.ratio()}"
else:
msg += f"\n<b>Size: </b>{task.size()}"
msg += f"\n<b>Elapsed: </b>{get_readable_time(time() - task.message.date.timestamp())}"
msg += f"\n<b>By: {source (task.listener)}</b>"
msg += f"\n<b>Elapsed: </b>{get_readable_time(time() - task.listener.message.date.timestamp())}"
msg += f"\n<b>By: {source(task.listener)}</b>"
msg += f"\n/stop_{task.gid()[:7]}\n\n"

if len(msg) == 0:
Expand Down

0 comments on commit 369c59e

Please sign in to comment.