Fix stop Duplicate check

Signed-off-by: anasty17 <e.anastayyar@gmail.com>
This commit is contained in:
anasty17 2023-11-06 15:15:24 +02:00
parent 0b1179f7a2
commit 79a0b90313
2 changed files with 12 additions and 41 deletions

View File

@ -20,6 +20,7 @@ async def stop_duplicate_check(listener):
not is_gdrive_id(listener.upDest)
or listener.isLeech
or listener.select
or isinstance(listener.upDest, int)
or listener.upDest.startswith("mtp:")
and not listener.user_dict.get("stop_duplicate", False)
or config_dict["STOP_DUPLICATE"]

View File

@ -3,14 +3,12 @@ from time import time
from aiofiles.os import remove as aioremove, path as aiopath
from bot import aria2, task_dict_lock, task_dict, LOGGER, config_dict
from bot.helper.mirror_utils.gdrive_utils.search import gdSearch
from bot.helper.mirror_utils.status_utils.aria2_status import Aria2Status
from bot.helper.ext_utils.files_utils import get_base_name, clean_unwanted
from bot.helper.ext_utils.files_utils import clean_unwanted
from bot.helper.ext_utils.bot_utils import (
new_thread,
bt_selection_buttons,
sync_to_async,
get_telegraph_list,
)
from bot.helper.telegram_helper.message_utils import (
sendMessage,
@ -18,7 +16,7 @@ from bot.helper.telegram_helper.message_utils import (
update_status_message,
)
from bot.helper.ext_utils.status_utils import getTaskByGid
from bot.helper.ext_utils.links_utils import is_gdrive_id
from bot.helper.ext_utils.task_manager import stop_duplicate_check
@new_thread
@ -45,43 +43,15 @@ async def _onDownloadStarted(api, gid):
await sleep(1)
if task := await getTaskByGid(gid):
if (
task.listener.upDest.startswith("mtp:")
and task.listener.user_dict("stop_duplicate", False)
or not task.listener.upDest.startswith("mtp:")
and config_dict["STOP_DUPLICATE"]
):
if (
task.listener.isLeech
or task.listener.select
or not is_gdrive_id(task.listener.upDest)
):
return
download = await sync_to_async(api.get_download, gid)
if not download.is_torrent:
await sleep(2)
download = download.live
LOGGER.info("Checking File/Folder if already in Drive...")
name = download.name
if task.listener.compress:
name = f"{name}.zip"
elif task.listener.extract:
try:
name = get_base_name(name)
except:
name = None
if name is not None:
telegraph_content, contents_no = await sync_to_async(
gdSearch(stopDup=True).drive_list,
name,
task.listener.upDest,
task.listener.user_id,
)
if telegraph_content:
msg = f"File/Folder is already available in Drive.\nHere are {contents_no} list results:"
button = await get_telegraph_list(telegraph_content)
await task.listener.onDownloadError(msg, button)
await sync_to_async(api.remove, [download], force=True, files=True)
download = await sync_to_async(api.get_download, gid)
await sleep(2)
download = download.live
task.listener.name = download.name
msg, button = await stop_duplicate_check(task.listener)
if msg:
await sendMessage(task.listener.message, msg, button)
await sync_to_async(api.remove, [download], force=True, files=True)
return
@new_thread