Stop duplicate mirror for Telegram files
Co-authored-by: FA Tulloh <yourtulloh@users.noreply.github.com> Signed-off-by: breakdowns <hafitz666@outlook.co.id>
This commit is contained in:
parent
c0bfd3cfc0
commit
dedf1a330a
10
README.md
10
README.md
|
|
@ -142,7 +142,7 @@ Fill up rest of the fields. Meaning of each fields are discussed below:
|
|||
### Optional Field
|
||||
- **ACCOUNTS_ZIP_URL**: Only if you want to load your Service Account externally from an Index Link. Archive your Service Account json files to a zip file directly (don't archive the accounts folder. Select all the jsons inside and zip them only instead. Name the zip file with whatever you want, it doesn't matter). Fill this with the direct link of that file.
|
||||
- **TOKEN_PICKLE_URL**: Only if you want to load your **token.pickle** externally from an Index Link. Fill this with the direct link of that file.
|
||||
- **AUTHORIZED_CHATS**: Fill user_id and chat_id of you want to authorize, Seprate them with space, Examples: ```-0123456789 -1122334455 6915401739```.
|
||||
- **AUTHORIZED_CHATS**: Fill user_id and chat_id (not username) of you want to authorize, Seprate them with space, Examples: ```-0123456789 -1122334455 6915401739```.
|
||||
- **IS_TEAM_DRIVE**: Set to `True` if `GDRIVE_FOLDER_ID` is from a Team Drive else `False` or Leave it empty.
|
||||
- **USE_SERVICE_ACCOUNTS**: (Leave empty if unsure) Whether to use Service Accounts or not. For this to work see [Using Service Accounts](https://github.com/breakdowns/slam-mirrorbot#generate-service-accounts-what-is-service-account) section below.
|
||||
- **INDEX_URL**: Refer to https://gitlab.com/ParveenBhadooOfficial/Google-Drive-Index The URL should not have any trailing '/'
|
||||
|
|
@ -154,10 +154,10 @@ Fill up rest of the fields. Meaning of each fields are discussed below:
|
|||
- **STOP_DUPLICATE_MIRROR**: (Leave empty if unsure) if this field is set to `True`, bot will check file in Drive, if it is present in Drive, downloading will be stopped. (**Note**: File will be checked using filename, not using filehash, so this feature is not perfect yet)
|
||||
- **STOP_DUPLICATE_MEGA**: (Leave empty if unsure) if this field is set to `True`, bot will check file in Drive, if it is present in Drive, downloading Mega will be stopped. (**Note**: File will be checked using filename, not using filehash, so this feature is not perfect yet)
|
||||
- **STOP_DUPLICATE_CLONE**: (Leave empty if unsure) if this field is set to `True`, bot will check file in Drive, if it is present in Drive, cloning will be stopped. (**Note**: File will be checked using filename, not using filehash, so this feature is not perfect yet)
|
||||
- **CLONE_LIMIT**: To limit cloning Google Drive (leave space between number and unit, Available units is (gb or GB, tb or TB).
|
||||
- **MEGA_LIMIT**: To limit downloading Mega (leave space between number and unit, Available units is (gb or GB, tb or TB).
|
||||
- **TORRENT_DIRECT_LIMIT**: To limit the Torrent/Direct mirror size, Leave space between number and unit. Available units is (gb or GB, tb or TB).
|
||||
- **TAR_UNZIP_LIMIT**: To limit mirroring as Tar or unzipmirror. Available units is (gb or GB, tb or TB).
|
||||
- **CLONE_LIMIT**: To limit cloning Google Drive (leave space between number and unit, Available units is (gb or GB, tb or TB), Examples: ```100 gb, 100 GB, 10 tb, 10 TB```
|
||||
- **MEGA_LIMIT**: To limit downloading Mega (leave space between number and unit, Available units is (gb or GB, tb or TB), Examples: ```100 gb, 100 GB, 10 tb, 10 TB```
|
||||
- **TORRENT_DIRECT_LIMIT**: To limit the Torrent/Direct mirror size, Leave space between number and unit. Available units is (gb or GB, tb or TB), Examples: ```100 gb, 100 GB, 10 tb, 10 TB```
|
||||
- **TAR_UNZIP_LIMIT**: To limit mirroring as Tar or unzipmirror. Available units is (gb or GB, tb or TB), Examples: ```100 gb, 100 GB, 10 tb, 10 TB```
|
||||
- **IMAGE_URL**: Show Image/Logo in /start message. Fill value of image your link image, use telegra.ph or any direct link image.
|
||||
- **VIEW_LINK**: View Link button to open file Index Link in browser instead of direct download link, you can figure out if it's compatible with your Index code or not, open any video from you Index and check if the END of link from browser link bar is `?a=view`, if yes make it `True` it will work (Compatible with [Bhadoo Index](https://gitlab.com/ParveenBhadooOfficial/Google-Drive-Index) Code)
|
||||
- **UPTOBOX_TOKEN**: Uptobox token to mirror uptobox links. Get it from [Uptobox Premium Account](https://uptobox.com/my_account).
|
||||
|
|
|
|||
|
|
@ -1,25 +1,26 @@
|
|||
import logging
|
||||
import threading
|
||||
import time
|
||||
|
||||
from bot import LOGGER, download_dict, download_dict_lock, app
|
||||
from bot import LOGGER, download_dict, download_dict_lock, app, STOP_DUPLICATE_MIRROR
|
||||
from .download_helper import DownloadHelper
|
||||
from ..status_utils.telegram_download_status import TelegramDownloadStatus
|
||||
from bot.helper.telegram_helper.message_utils import *
|
||||
from bot.helper.mirror_utils.upload_utils.gdriveTools import GoogleDriveHelper
|
||||
from time import sleep
|
||||
from bot.helper.ext_utils.bot_utils import get_readable_file_size
|
||||
|
||||
global_lock = threading.Lock()
|
||||
GLOBAL_GID = set()
|
||||
|
||||
logging.getLogger("pyrogram").setLevel(logging.WARNING)
|
||||
|
||||
|
||||
class TelegramDownloadHelper(DownloadHelper):
|
||||
def __init__(self, listener):
|
||||
super().__init__()
|
||||
self.__listener = listener
|
||||
self.__resource_lock = threading.RLock()
|
||||
self.__name = ""
|
||||
self.__gid = ''
|
||||
self.__start_time = time.time()
|
||||
self.__gid = ""
|
||||
self._bot = app
|
||||
self.__is_cancelled = False
|
||||
|
||||
|
|
@ -70,8 +71,11 @@ class TelegramDownloadHelper(DownloadHelper):
|
|||
self.__listener.onDownloadComplete()
|
||||
|
||||
def __download(self, message, path):
|
||||
download = self._bot.download_media(message,
|
||||
progress=self.__onDownloadProgress, file_name=path)
|
||||
download = self._bot.download_media(
|
||||
message,
|
||||
progress = self.__onDownloadProgress,
|
||||
file_name = path
|
||||
)
|
||||
if download is not None:
|
||||
self.__onDownloadComplete()
|
||||
else:
|
||||
|
|
@ -95,9 +99,29 @@ class TelegramDownloadHelper(DownloadHelper):
|
|||
else:
|
||||
name = filename
|
||||
path = path + name
|
||||
if download:
|
||||
|
||||
if download or STOP_DUPLICATE_MIRROR:
|
||||
LOGGER.info(f"Checking File/Folder if already in Drive...")
|
||||
sleep(1)
|
||||
if self.__listener.isTar:
|
||||
name = name + ".tar"
|
||||
if self.__listener.extract:
|
||||
smsg = None
|
||||
else:
|
||||
gd = GoogleDriveHelper()
|
||||
smsg, button = gd.drive_list(name)
|
||||
if smsg:
|
||||
self.__onDownloadError('File/Folder is already available in Drive.\n\n')
|
||||
sendMarkup("Here are the search results:",
|
||||
self.__listener.bot,
|
||||
self.__listener.update,
|
||||
button
|
||||
)
|
||||
self.__is_cancelled = True
|
||||
return
|
||||
|
||||
self.__onDownloadStart(name, media.file_size, media.file_id)
|
||||
LOGGER.info(f'Downloading telegram file with id: {media.file_id}')
|
||||
LOGGER.info(f'Downloading Telegram file with id: {media.file_id}')
|
||||
threading.Thread(target=self.__download, args=(_message, path)).start()
|
||||
else:
|
||||
self.__onDownloadError('File already being downloaded!')
|
||||
|
|
|
|||
|
|
@ -280,7 +280,6 @@ def _mirror(bot, update, isTar=False, extract=False):
|
|||
listener = MirrorListener(bot, update, pswd, isTar, tag, extract)
|
||||
tg_downloader = TelegramDownloadHelper(listener)
|
||||
tg_downloader.add_download(reply_to, f'{DOWNLOAD_DIR}{listener.uid}/', name)
|
||||
sendStatusMessage(update, bot)
|
||||
if len(Interval) == 0:
|
||||
Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in New Issue