download_helper: Avoid instantiating Aria APIs on each new mirror request
Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
This commit is contained in:
parent
d403c95c5a
commit
76c6d68d85
|
|
@ -1,6 +1,9 @@
|
|||
import logging
|
||||
import configparser
|
||||
import aria2p
|
||||
from telegram.ext import Updater
|
||||
|
||||
|
||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
level=logging.INFO)
|
||||
|
||||
|
|
@ -21,6 +24,13 @@ try:
|
|||
except KeyError:
|
||||
pass
|
||||
|
||||
aria2 = aria2p.API(
|
||||
aria2p.Client(
|
||||
host="http://localhost",
|
||||
port=6800,
|
||||
secret="",
|
||||
)
|
||||
)
|
||||
DOWNLOAD_DIR = None
|
||||
BOT_TOKEN = None
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
import aria2p
|
||||
from time import sleep
|
||||
from bot import LOGGER, DOWNLOAD_DIR, DOWNLOAD_STATUS_UPDATE_INTERVAL, download_list
|
||||
from bot import LOGGER, DOWNLOAD_DIR, DOWNLOAD_STATUS_UPDATE_INTERVAL, download_list, aria2
|
||||
from bot.helper.listeners import *
|
||||
from urllib.parse import urlparse
|
||||
from aria2p import Options
|
||||
|
||||
|
||||
def is_url(url: str):
|
||||
|
|
@ -24,22 +22,15 @@ def is_magnet(url: str):
|
|||
class DownloadHelper:
|
||||
|
||||
def __init__(self, listener: MirrorListeners):
|
||||
self.__aria2 = aria2p.API(
|
||||
aria2p.Client(
|
||||
host="http://localhost",
|
||||
port=6800,
|
||||
secret="",
|
||||
)
|
||||
)
|
||||
self.__listener = listener
|
||||
|
||||
def add_download(self, link: str):
|
||||
download = None
|
||||
if is_url(link):
|
||||
download = self.__aria2.add_uris([link], {'dir': DOWNLOAD_DIR + str(self.__listener.update.update_id),
|
||||
download = aria2.add_uris([link], {'dir': DOWNLOAD_DIR + str(self.__listener.update.update_id),
|
||||
'max_download_limit': 1})
|
||||
elif is_magnet(link):
|
||||
download = self.__aria2.add_magnet(link, {'dir': DOWNLOAD_DIR})
|
||||
download = aria2.add_magnet(link, {'dir': DOWNLOAD_DIR})
|
||||
else:
|
||||
self.__listener.onDownloadError("No download URL or URL malformed")
|
||||
return
|
||||
|
|
@ -55,7 +46,7 @@ class DownloadHelper:
|
|||
str_list = []
|
||||
LOGGER.info(download_list)
|
||||
for gid in list(download_list.values()):
|
||||
download = self.__aria2.get_download(gid)
|
||||
download = aria2.get_download(gid)
|
||||
str_list.append("<b>" + download.name + "</b>:- "
|
||||
+ download.progress_string() + " of "
|
||||
+ download.total_length_string()
|
||||
|
|
@ -65,7 +56,7 @@ class DownloadHelper:
|
|||
return str_list
|
||||
|
||||
def __get_download(self):
|
||||
return self.__aria2.get_download(download_list[self.__listener.update.update_id])
|
||||
return aria2.get_download(download_list[self.__listener.update.update_id])
|
||||
|
||||
def __update_download_status(self):
|
||||
# TODO: Try to find a way to move this code to mirror.py and send only a
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
python-telegram-bot
|
||||
google-api-python-client>=1.7.3
|
||||
google-auth-httplib2<=0.0.3
|
||||
google-api-python-client
|
||||
google-auth-httplib2
|
||||
google-auth-oauthlib
|
||||
httplib2>=0.11.3
|
||||
more-itertools>=4.2.0
|
||||
ndg-httpsclient>=0.4.0
|
||||
oauth>=1.0.1
|
||||
pyasn1>=0.4.3
|
||||
pyasn1-modules>=0.2.1
|
||||
uritemplate>=3.0.0
|
||||
|
|
|
|||
Loading…
Reference in New Issue