Skip to content

Commit

Permalink
Fix stop Duplicate check
Browse files Browse the repository at this point in the history
Signed-off-by: anasty17 <[email protected]>
  • Loading branch information
anasty17 committed Nov 6, 2023
1 parent 0b1179f commit 79a0b90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 41 deletions.
1 change: 1 addition & 0 deletions bot/helper/ext_utils/task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
52 changes: 11 additions & 41 deletions bot/helper/listeners/aria2_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
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,
deleteMessage,
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
Expand All @@ -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
Expand Down

0 comments on commit 79a0b90

Please sign in to comment.