Skip to content

Commit

Permalink
Fix samedir stuck waiting the already faild download to finish
Browse files Browse the repository at this point in the history
Signed-off-by: anasty17 <[email protected]>
  • Loading branch information
anasty17 committed Nov 8, 2023
1 parent 350e0bf commit 168b695
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
6 changes: 3 additions & 3 deletions bot/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
GLOBAL_EXTENSION_FILTER,
cpu_eater_lock,
)
from bot.helper.telegram_helper.bot_commands import BotCommands
from bot.helper.ext_utils.bot_utils import new_task, sync_to_async
from bot.helper.ext_utils.links_utils import (
is_gdrive_id,
Expand All @@ -38,15 +39,14 @@
clean_target,
)
from bot.helper.ext_utils.bulk_links import extractBulkLinks
from bot.helper.mirror_utils.rclone_utils.list import RcloneList
from bot.helper.mirror_utils.gdrive_utils.list import gdriveList
from bot.helper.ext_utils.media_utils import split_file, get_document_type
from bot.helper.telegram_helper.bot_commands import BotCommands
from bot.helper.ext_utils.media_utils import (
createThumb,
getSplitSizeBytes,
createSampleVideo,
)
from bot.helper.mirror_utils.rclone_utils.list import RcloneList
from bot.helper.mirror_utils.gdrive_utils.list import gdriveList
from bot.helper.mirror_utils.status_utils.extract_status import ExtractStatus
from bot.helper.mirror_utils.status_utils.zip_status import ZipStatus
from bot.helper.mirror_utils.status_utils.split_status import SplitStatus
Expand Down
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 @@ -24,6 +24,7 @@ async def stop_duplicate_check(listener):
or listener.upDest.startswith("mtp:")
and listener.stopDuplicate
or not listener.stopDuplicate
or listener.sameDir
):
return False, None
name = listener.name
Expand Down
19 changes: 11 additions & 8 deletions bot/helper/listeners/task_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
clean_target,
join_files,
)
from bot.helper.telegram_helper.message_utils import (
sendMessage,
delete_status,
update_status_message,
)
from bot.helper.ext_utils.status_utils import get_readable_file_size
from bot.helper.ext_utils.bot_utils import sync_to_async
from bot.helper.ext_utils.links_utils import is_gdrive_id
Expand All @@ -36,11 +41,6 @@
from bot.helper.mirror_utils.gdrive_utils.upload import gdUpload
from bot.helper.mirror_utils.telegram_uploader import TgUploader
from bot.helper.mirror_utils.rclone_utils.transfer import RcloneTransferHelper
from bot.helper.telegram_helper.message_utils import (
sendMessage,
delete_status,
update_status_message,
)
from bot.helper.telegram_helper.button_build import ButtonMaker
from bot.helper.ext_utils.db_handler import DbManger
from bot.helper.common import TaskConfig
Expand All @@ -61,6 +61,11 @@ async def clean(self):
except:
pass

def removeFromSameDir(self):
if self.sameDir and self.mid in self.sameDir["tasks"]:
self.sameDir["tasks"].remove(self.mid)
self.sameDir["total"] -= 1

async def onDownloadStart(self):
if (
self.isSuperChat
Expand Down Expand Up @@ -331,9 +336,7 @@ async def onDownloadError(self, error, button=None):
if self.mid in task_dict:
del task_dict[self.mid]
count = len(task_dict)
if self.sameDir and self.mid in self.sameDir["tasks"]:
self.sameDir["tasks"].remove(self.mid)
self.sameDir["total"] -= 1
self.removeFromSameDir()
msg = f"{self.tag} Download: {escape(error)}"
await sendMessage(self.message, msg, button)
if count == 0:
Expand Down
6 changes: 6 additions & 0 deletions bot/modules/mirror_leech.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ async def newEvent(self):
reply_to, self.session = await get_tg_link_message(self.link)
except Exception as e:
await sendMessage(self.message, f"ERROR: {e}")
self.removeFromSameDir()
return

if isinstance(reply_to, list):
Expand Down Expand Up @@ -237,6 +238,7 @@ async def newEvent(self):
await sendMessage(
self.message, "Open this link for usage help!", COMMAND_USAGE["main"]
)
self.removeFromSameDir()
return

if self.link:
Expand All @@ -246,6 +248,7 @@ async def newEvent(self):
await self.beforeStart()
except Exception as e:
await sendMessage(self.message, e)
self.removeFromSameDir()
return

if (
Expand All @@ -272,6 +275,7 @@ async def newEvent(self):
LOGGER.info(e)
if e.startswith("ERROR:"):
await sendMessage(self.message, e)
self.removeFromSameDir()
return

if file_ is not None:
Expand All @@ -296,6 +300,8 @@ async def newEvent(self):
)
await add_aria2c_download(self, path, headers, ratio, seed_time)

self.removeFromSameDir()


async def mirror(client, message):
Mirror(client, message).newEvent()
Expand Down
5 changes: 5 additions & 0 deletions bot/modules/ytdlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ async def newEvent(self):
await sendMessage(
self.message, "Open this link for usage help!", COMMAND_USAGE["yt"]
)
self.removeFromSameDir()
return

if "mdisk.me" in self.link:
Expand Down Expand Up @@ -406,6 +407,7 @@ async def newEvent(self):
except Exception as e:
msg = str(e).replace("<", " ").replace(">", " ")
await sendMessage(self.message, f"{self.tag} {msg}")
self.removeFromSameDir()
return
finally:
self.run_multi(input_list, folder_name, YtDlp)
Expand All @@ -416,18 +418,21 @@ async def newEvent(self):
if not qual:
qual = await YtSelection(self).get_quality(result)
if qual is None:
self.removeFromSameDir()
return

try:
await self.beforeStart()
except Exception as e:
await sendMessage(self.message, e)
self.removeFromSameDir()
return

LOGGER.info(f"Downloading with YT-DLP: {self.link}")
playlist = "entries" in result
ydl = YoutubeDLHelper(self)
await ydl.add_download(path, qual, playlist, opt)
self.removeFromSameDir()


async def ytdl(client, message):
Expand Down

0 comments on commit 168b695

Please sign in to comment.