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 re
|
||||
import threading
|
||||
import time
|
||||
|
||||
from bot import download_dict, download_dict_lock
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
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:
|
||||
return 'File too large'
|
||||
|
||||
|
||||
def getDownloadByGid(gid):
|
||||
with download_dict_lock:
|
||||
for dl in download_dict.values():
|
||||
if dl.status() == MirrorStatus.STATUS_DOWNLOADING:
|
||||
if dl.download().gid == gid:
|
||||
if dl.gid() == gid:
|
||||
return dl
|
||||
return None
|
||||
|
||||
|
|
@ -97,13 +99,13 @@ def get_readable_message():
|
|||
msg += download.status()
|
||||
if download.status() != MirrorStatus.STATUS_ARCHIVING:
|
||||
msg += f"\n<code>{get_progress_bar_string(download)} {download.progress()}</code> of " \
|
||||
f"{download.size()}" \
|
||||
f" at {download.speed()}, ETA: {download.eta()} "
|
||||
f"{download.size()}" \
|
||||
f" at {download.speed()}, ETA: {download.eta()} "
|
||||
if download.status() == MirrorStatus.STATUS_DOWNLOADING:
|
||||
if hasattr(download, 'is_torrent'):
|
||||
msg += f"| P: {download.download().connections} " \
|
||||
f"| S: {download.download().num_seeders}"
|
||||
msg += f"\nGID: <code>{download.download().gid}</code>"
|
||||
msg += f"\nGID: <code>{download.gid()}</code>"
|
||||
msg += "\n\n"
|
||||
return msg
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
from .download_helper import DownloadHelper
|
||||
import threading
|
||||
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 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_GID = set()
|
||||
|
||||
|
||||
class TelegramDownloadHelper(DownloadHelper):
|
||||
def __init__(self, listener):
|
||||
super().__init__()
|
||||
|
|
@ -19,8 +21,8 @@ class TelegramDownloadHelper(DownloadHelper):
|
|||
self.__gid = ''
|
||||
self.__start_time = time.time()
|
||||
self.__user_bot = Client(api_id=TELEGRAM_API,
|
||||
api_hash=TELEGRAM_HASH,
|
||||
session_name=USER_SESSION_STRING)
|
||||
api_hash=TELEGRAM_HASH,
|
||||
session_name=USER_SESSION_STRING)
|
||||
self.__user_bot.start()
|
||||
|
||||
@property
|
||||
|
|
@ -51,15 +53,16 @@ class TelegramDownloadHelper(DownloadHelper):
|
|||
self.progress = current / self.size * 100
|
||||
except ZeroDivisionError:
|
||||
return 0
|
||||
|
||||
def __onDownloadComplete(self):
|
||||
|
||||
|
||||
self.__listener.onDownloadComplete()
|
||||
|
||||
def __download(self, message, path):
|
||||
self.__user_bot.download_media(message,
|
||||
progress=self.__onDownloadProgress, file_name=path)
|
||||
progress=self.__onDownloadProgress, file_name=path)
|
||||
self.__onDownloadComplete()
|
||||
|
||||
|
||||
def add_download(self, message, path):
|
||||
if message.chat.type == "private":
|
||||
_message = self.__user_bot.get_messages(bot.get_me().id, message.message_id)
|
||||
|
|
@ -70,7 +73,7 @@ class TelegramDownloadHelper(DownloadHelper):
|
|||
with global_lock:
|
||||
# For avoiding locking the thread lock for long time unnecessarily
|
||||
download = media.file_id not in GLOBAL_GID
|
||||
|
||||
|
||||
if download:
|
||||
self.__onDownloadStart(media.file_name, media.file_size, media.file_id)
|
||||
LOGGER.info(media.file_id)
|
||||
|
|
|
|||
|
|
@ -74,3 +74,7 @@ class AriaDownloadStatus(Status):
|
|||
|
||||
def uid(self):
|
||||
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 .status import Status
|
||||
from bot import DOWNLOAD_DIR
|
||||
|
||||
|
||||
class TelegramDownloadStatus(Status):
|
||||
|
|
@ -8,6 +8,9 @@ class TelegramDownloadStatus(Status):
|
|||
self.obj = obj
|
||||
self.uid = uid
|
||||
|
||||
def gid(self):
|
||||
return self.obj.gid
|
||||
|
||||
def path(self):
|
||||
return f"{DOWNLOAD_DIR}{self.uid}"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue