Skip to content

Commit 41bac13

Browse files
committed
Minor changes
Signed-off-by: anasty17 <[email protected]>
1 parent 74fe820 commit 41bac13

File tree

8 files changed

+43
-44
lines changed

8 files changed

+43
-44
lines changed

aria.sh aria-nox.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ aria2c --allow-overwrite=true --auto-file-renaming=true --bt-enable-lpd=true --b
66
--min-split-size=10M --follow-torrent=mem --check-certificate=false --optimize-concurrent-downloads=true \
77
--http-accept-gzip=true --max-file-not-found=0 --max-tries=20 --peer-id-prefix=-qB4520- --reuse-uri=true \
88
--content-disposition-default-utf8=true --user-agent=Wget/1.12 --peer-agent=qBittorrent/4.5.2 --quiet=true \
9-
--summary-interval=0 --max-upload-limit=1K
9+
--summary-interval=0 --max-upload-limit=1K
10+
qbittorrent-nox -d --profile="$(pwd)"

bot/__init__.py

+23-25
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545

4646
LOGGER = getLogger(__name__)
4747

48-
aria2 = ariaAPI(ariaClient(host="http://localhost", port=6800, secret=""))
49-
5048
load_dotenv("config.env", override=True)
5149

5250
Intervals = {"status": {}, "qb": "", "jd": ""}
@@ -139,6 +137,14 @@
139137
else:
140138
config_dict = {}
141139

140+
if not ospath.exists(".netrc"):
141+
with open(".netrc", "w"):
142+
pass
143+
run(
144+
"chmod 600 .netrc && cp .netrc /root/.netrc && chmod +x aria-nox.sh && ./aria-nox.sh",
145+
shell=True,
146+
)
147+
142148
OWNER_ID = environ.get("OWNER_ID", "")
143149
if len(OWNER_ID) == 0:
144150
log_error("OWNER_ID variable is missing! Exiting now")
@@ -436,14 +442,6 @@
436442
shell=True,
437443
)
438444

439-
run(["qbittorrent-nox", "-d", f"--profile={getcwd()}"])
440-
if not ospath.exists(".netrc"):
441-
with open(".netrc", "w"):
442-
pass
443-
run(
444-
"chmod 600 .netrc && cp .netrc /root/.netrc && chmod +x aria.sh && ./aria.sh",
445-
shell=True,
446-
)
447445
if ospath.exists("accounts.zip"):
448446
if ospath.exists("accounts"):
449447
run(["rm", "-rf", "accounts"])
@@ -454,7 +452,7 @@
454452
config_dict["USE_SERVICE_ACCOUNTS"] = False
455453

456454

457-
def get_client():
455+
def get_qb_client():
458456
return qbClient(
459457
host="localhost",
460458
port=8090,
@@ -479,20 +477,6 @@ def get_client():
479477
"server-stat-of",
480478
]
481479

482-
qb_client = get_client()
483-
if not qbit_options:
484-
qbit_options = dict(qb_client.app_preferences())
485-
del qbit_options["listen_port"]
486-
for k in list(qbit_options.keys()):
487-
if k.startswith("rss"):
488-
del qbit_options[k]
489-
else:
490-
qb_opt = {**qbit_options}
491-
for k, v in list(qb_opt.items()):
492-
if v in ["", "*"]:
493-
del qb_opt[k]
494-
qb_client.app_set_preferences(qb_opt)
495-
496480
log_info("Creating client from BOT_TOKEN")
497481
bot = tgClient(
498482
"bot",
@@ -507,6 +491,20 @@ def get_client():
507491

508492
scheduler = AsyncIOScheduler(timezone=str(get_localzone()), event_loop=bot_loop)
509493

494+
if not qbit_options:
495+
qbit_options = dict(get_qb_client().app_preferences())
496+
del qbit_options["listen_port"]
497+
for k in list(qbit_options.keys()):
498+
if k.startswith("rss"):
499+
del qbit_options[k]
500+
else:
501+
qb_opt = {**qbit_options}
502+
for k, v in list(qb_opt.items()):
503+
if v in ["", "*"]:
504+
del qb_opt[k]
505+
get_qb_client().app_set_preferences(qb_opt)
506+
507+
aria2 = ariaAPI(ariaClient(host="http://localhost", port=6800, secret=""))
510508
if not aria2_options:
511509
aria2_options = aria2.client.get_global_option()
512510
else:

bot/helper/ext_utils/files_utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from subprocess import run as srun
88
from sys import exit as sexit
99

10-
from bot import aria2, LOGGER, DOWNLOAD_DIR, get_client
10+
from bot import aria2, LOGGER, DOWNLOAD_DIR, get_qb_client
1111
from bot.helper.ext_utils.bot_utils import sync_to_async, cmd_exec
1212
from .exceptions import NotSupportedExtractionArchive
1313

@@ -91,7 +91,7 @@ async def clean_download(path):
9191

9292
def clean_all():
9393
aria2.remove_all(True)
94-
get_client().torrents_delete(torrent_hashes="all")
94+
get_qb_client().torrents_delete(torrent_hashes="all")
9595
try:
9696
rmtree(DOWNLOAD_DIR)
9797
except:
@@ -103,7 +103,7 @@ def exit_clean_up(signal, frame):
103103
try:
104104
LOGGER.info("Please wait, while we clean up and stop the running downloads")
105105
clean_all()
106-
srun(["pkill", "-9", "-f", "gunicorn|aria2c|qbittorrent-nox|ffmpeg"])
106+
srun(["pkill", "-9", "-f", "gunicorn|aria2c|qbittorrent-nox|ffmpeg|java"])
107107
sexit(0)
108108
except KeyboardInterrupt:
109109
LOGGER.warning("Force Exiting before the cleanup finishes!")

bot/helper/listeners/qbit_listener.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
task_dict,
77
task_dict_lock,
88
Intervals,
9-
get_client,
9+
get_qb_client,
1010
config_dict,
1111
QbTorrents,
1212
qb_listener_lock,
@@ -88,7 +88,7 @@ async def _onDownloadComplete(tor):
8888
except:
8989
pass
9090
await task.listener.onDownloadComplete()
91-
client = await sync_to_async(get_client)
91+
client = await sync_to_async(get_qb_client)
9292
if task.listener.seed:
9393
async with task_dict_lock:
9494
if task.listener.mid in task_dict:
@@ -112,7 +112,7 @@ async def _onDownloadComplete(tor):
112112

113113

114114
async def _qb_listener():
115-
client = await sync_to_async(get_client)
115+
client = await sync_to_async(get_qb_client)
116116
while True:
117117
async with qb_listener_lock:
118118
try:
@@ -193,7 +193,7 @@ async def _qb_listener():
193193
await sleep(0.5)
194194
except Exception as e:
195195
LOGGER.error(str(e))
196-
client = await sync_to_async(get_client)
196+
client = await sync_to_async(get_qb_client)
197197
await sleep(3)
198198

199199

bot/helper/mirror_utils/download_utils/qbit_download.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from bot import (
55
task_dict,
66
task_dict_lock,
7-
get_client,
7+
get_qb_client,
88
LOGGER,
99
config_dict,
1010
non_queued_dl,
@@ -40,7 +40,7 @@ def _get_hash_file(fpath):
4040

4141

4242
async def add_qb_torrent(listener, path, ratio, seed_time):
43-
client = await sync_to_async(get_client)
43+
client = await sync_to_async(get_qb_client)
4444
ADD_TIME = time()
4545
try:
4646
url = listener.link

bot/helper/mirror_utils/status_utils/qbit_status.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from asyncio import sleep
22

3-
from bot import LOGGER, get_client, QbTorrents, qb_listener_lock
3+
from bot import LOGGER, get_qb_client, QbTorrents, qb_listener_lock
44
from bot.helper.ext_utils.bot_utils import sync_to_async
55
from bot.helper.ext_utils.status_utils import (
66
MirrorStatus,
@@ -19,7 +19,7 @@ def get_download(client, tag, old_info=None):
1919

2020
class QbittorrentStatus:
2121
def __init__(self, listener, seeding=False, queued=False):
22-
self.client = get_client()
22+
self.client = get_qb_client()
2323
self.queued = queued
2424
self.seeding = seeding
2525
self.listener = listener

bot/modules/bot_settings.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
IS_PREMIUM_USER,
2727
task_dict,
2828
qbit_options,
29-
get_client,
29+
get_qb_client,
3030
LOGGER,
3131
bot,
3232
)
@@ -298,7 +298,7 @@ async def edit_qbit(_, message, pre_message, key):
298298
value = float(value)
299299
elif value.isdigit():
300300
value = int(value)
301-
await sync_to_async(get_client().app_set_preferences, {key: value})
301+
await sync_to_async(get_qb_client().app_set_preferences, {key: value})
302302
qbit_options[key] = value
303303
await update_buttons(pre_message, "qbit")
304304
await deleteMessage(message)
@@ -558,7 +558,7 @@ async def edit_bot_settings(client, query):
558558
await DbManager().update_aria2(data[2], "")
559559
elif data[1] == "emptyqbit":
560560
await query.answer()
561-
await sync_to_async(get_client().app_set_preferences, {data[2]: value})
561+
await sync_to_async(get_qb_client().app_set_preferences, {data[2]: value})
562562
qbit_options[data[2]] = ""
563563
await update_buttons(message, "qbit")
564564
if DATABASE_URL:

bot/modules/torrent_search.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pyrogram.handlers import MessageHandler, CallbackQueryHandler
55
from urllib.parse import quote
66

7-
from bot import bot, LOGGER, config_dict, get_client
7+
from bot import bot, LOGGER, config_dict, get_qb_client
88
from bot.helper.ext_utils.bot_utils import sync_to_async, new_task
99
from bot.helper.ext_utils.status_utils import get_readable_file_size
1010
from bot.helper.ext_utils.telegraph_helper import telegraph
@@ -19,7 +19,7 @@
1919

2020

2121
async def initiate_search_tools():
22-
qbclient = await sync_to_async(get_client)
22+
qbclient = await sync_to_async(get_qb_client)
2323
qb_plugins = await sync_to_async(qbclient.search_plugins)
2424
if SEARCH_PLUGINS := config_dict["SEARCH_PLUGINS"]:
2525
globals()["PLUGINS"] = []
@@ -100,7 +100,7 @@ async def _search(key, site, message, method):
100100
return
101101
else:
102102
LOGGER.info(f"PLUGINS Searching: {key} from {site}")
103-
client = await sync_to_async(get_client)
103+
client = await sync_to_async(get_qb_client)
104104
search = await sync_to_async(
105105
client.search_start, pattern=key, plugins=site, category="all"
106106
)
@@ -224,7 +224,7 @@ def _api_buttons(user_id, method):
224224
async def _plugin_buttons(user_id):
225225
buttons = ButtonMaker()
226226
if not PLUGINS:
227-
qbclient = await sync_to_async(get_client)
227+
qbclient = await sync_to_async(get_qb_client)
228228
pl = await sync_to_async(qbclient.search_plugins)
229229
for name in pl:
230230
PLUGINS.append(name["name"])

0 commit comments

Comments
 (0)