Add gid method in Status class for download classes
Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
This commit is contained in:
parent
a44d0da9f6
commit
49fe46bad3
|
|
@ -1,9 +1,10 @@
|
||||||
from bot import download_dict, download_dict_lock
|
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from bot import download_dict, download_dict_lock
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
MAGNET_REGEX = r"magnet:\?xt=urn:btih:[a-zA-Z0-9]*"
|
MAGNET_REGEX = r"magnet:\?xt=urn:btih:[a-zA-Z0-9]*"
|
||||||
|
|
@ -54,11 +55,12 @@ def get_readable_file_size(size_in_bytes) -> str:
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return 'File too large'
|
return 'File too large'
|
||||||
|
|
||||||
|
|
||||||
def getDownloadByGid(gid):
|
def getDownloadByGid(gid):
|
||||||
with download_dict_lock:
|
with download_dict_lock:
|
||||||
for dl in download_dict.values():
|
for dl in download_dict.values():
|
||||||
if dl.status() == MirrorStatus.STATUS_DOWNLOADING:
|
if dl.status() == MirrorStatus.STATUS_DOWNLOADING:
|
||||||
if dl.download().gid == gid:
|
if dl.gid() == gid:
|
||||||
return dl
|
return dl
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
@ -97,13 +99,13 @@ def get_readable_message():
|
||||||
msg += download.status()
|
msg += download.status()
|
||||||
if download.status() != MirrorStatus.STATUS_ARCHIVING:
|
if download.status() != MirrorStatus.STATUS_ARCHIVING:
|
||||||
msg += f"\n<code>{get_progress_bar_string(download)} {download.progress()}</code> of " \
|
msg += f"\n<code>{get_progress_bar_string(download)} {download.progress()}</code> of " \
|
||||||
f"{download.size()}" \
|
f"{download.size()}" \
|
||||||
f" at {download.speed()}, ETA: {download.eta()} "
|
f" at {download.speed()}, ETA: {download.eta()} "
|
||||||
if download.status() == MirrorStatus.STATUS_DOWNLOADING:
|
if download.status() == MirrorStatus.STATUS_DOWNLOADING:
|
||||||
if hasattr(download, 'is_torrent'):
|
if hasattr(download, 'is_torrent'):
|
||||||
msg += f"| P: {download.download().connections} " \
|
msg += f"| P: {download.download().connections} " \
|
||||||
f"| S: {download.download().num_seeders}"
|
f"| S: {download.download().num_seeders}"
|
||||||
msg += f"\nGID: <code>{download.download().gid}</code>"
|
msg += f"\nGID: <code>{download.gid()}</code>"
|
||||||
msg += "\n\n"
|
msg += "\n\n"
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,17 @@
|
||||||
from .download_helper import DownloadHelper
|
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from ..status_utils.telegram_download_status import TelegramDownloadStatus
|
|
||||||
from bot.helper.ext_utils.bot_utils import get_readable_file_size
|
|
||||||
from bot import LOGGER, bot, download_dict, download_dict_lock, TELEGRAM_API,\
|
|
||||||
TELEGRAM_HASH, USER_SESSION_STRING
|
|
||||||
from pyrogram import Client
|
from pyrogram import Client
|
||||||
|
|
||||||
|
from bot import LOGGER, bot, download_dict, download_dict_lock, TELEGRAM_API, \
|
||||||
|
TELEGRAM_HASH, USER_SESSION_STRING
|
||||||
|
from .download_helper import DownloadHelper
|
||||||
|
from ..status_utils.telegram_download_status import TelegramDownloadStatus
|
||||||
|
|
||||||
global_lock = threading.Lock()
|
global_lock = threading.Lock()
|
||||||
GLOBAL_GID = set()
|
GLOBAL_GID = set()
|
||||||
|
|
||||||
|
|
||||||
class TelegramDownloadHelper(DownloadHelper):
|
class TelegramDownloadHelper(DownloadHelper):
|
||||||
def __init__(self, listener):
|
def __init__(self, listener):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
@ -19,8 +21,8 @@ class TelegramDownloadHelper(DownloadHelper):
|
||||||
self.__gid = ''
|
self.__gid = ''
|
||||||
self.__start_time = time.time()
|
self.__start_time = time.time()
|
||||||
self.__user_bot = Client(api_id=TELEGRAM_API,
|
self.__user_bot = Client(api_id=TELEGRAM_API,
|
||||||
api_hash=TELEGRAM_HASH,
|
api_hash=TELEGRAM_HASH,
|
||||||
session_name=USER_SESSION_STRING)
|
session_name=USER_SESSION_STRING)
|
||||||
self.__user_bot.start()
|
self.__user_bot.start()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
@ -51,15 +53,16 @@ class TelegramDownloadHelper(DownloadHelper):
|
||||||
self.progress = current / self.size * 100
|
self.progress = current / self.size * 100
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def __onDownloadComplete(self):
|
def __onDownloadComplete(self):
|
||||||
|
|
||||||
self.__listener.onDownloadComplete()
|
self.__listener.onDownloadComplete()
|
||||||
|
|
||||||
def __download(self, message, path):
|
def __download(self, message, path):
|
||||||
self.__user_bot.download_media(message,
|
self.__user_bot.download_media(message,
|
||||||
progress=self.__onDownloadProgress, file_name=path)
|
progress=self.__onDownloadProgress, file_name=path)
|
||||||
self.__onDownloadComplete()
|
self.__onDownloadComplete()
|
||||||
|
|
||||||
def add_download(self, message, path):
|
def add_download(self, message, path):
|
||||||
if message.chat.type == "private":
|
if message.chat.type == "private":
|
||||||
_message = self.__user_bot.get_messages(bot.get_me().id, message.message_id)
|
_message = self.__user_bot.get_messages(bot.get_me().id, message.message_id)
|
||||||
|
|
@ -70,7 +73,7 @@ class TelegramDownloadHelper(DownloadHelper):
|
||||||
with global_lock:
|
with global_lock:
|
||||||
# For avoiding locking the thread lock for long time unnecessarily
|
# For avoiding locking the thread lock for long time unnecessarily
|
||||||
download = media.file_id not in GLOBAL_GID
|
download = media.file_id not in GLOBAL_GID
|
||||||
|
|
||||||
if download:
|
if download:
|
||||||
self.__onDownloadStart(media.file_name, media.file_size, media.file_id)
|
self.__onDownloadStart(media.file_name, media.file_size, media.file_id)
|
||||||
LOGGER.info(media.file_id)
|
LOGGER.info(media.file_id)
|
||||||
|
|
|
||||||
|
|
@ -74,3 +74,7 @@ class AriaDownloadStatus(Status):
|
||||||
|
|
||||||
def uid(self):
|
def uid(self):
|
||||||
return self.__uid
|
return self.__uid
|
||||||
|
|
||||||
|
def gid(self):
|
||||||
|
self.__update()
|
||||||
|
return self.__gid
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
|
from bot import DOWNLOAD_DIR
|
||||||
from bot.helper.ext_utils.bot_utils import MirrorStatus, get_readable_file_size, get_readable_time
|
from bot.helper.ext_utils.bot_utils import MirrorStatus, get_readable_file_size, get_readable_time
|
||||||
from .status import Status
|
from .status import Status
|
||||||
from bot import DOWNLOAD_DIR
|
|
||||||
|
|
||||||
|
|
||||||
class TelegramDownloadStatus(Status):
|
class TelegramDownloadStatus(Status):
|
||||||
|
|
@ -8,6 +8,9 @@ class TelegramDownloadStatus(Status):
|
||||||
self.obj = obj
|
self.obj = obj
|
||||||
self.uid = uid
|
self.uid = uid
|
||||||
|
|
||||||
|
def gid(self):
|
||||||
|
return self.obj.gid
|
||||||
|
|
||||||
def path(self):
|
def path(self):
|
||||||
return f"{DOWNLOAD_DIR}{self.uid}"
|
return f"{DOWNLOAD_DIR}{self.uid}"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue