Skip to content

Commit

Permalink
Temporary fix for subfolders in jdownloader
Browse files Browse the repository at this point in the history
Signed-off-by: anasty17 <[email protected]>
  • Loading branch information
anasty17 committed Dec 30, 2023
1 parent e33be66 commit b67db09
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
8 changes: 5 additions & 3 deletions bot/helper/ext_utils/jdownloader_booter.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,17 @@ def connectToDevice(self):
continue
break
self.device.enable_direct_connection()
LOGGER.info("JDownloader Device is Connected!")
LOGGER.info("JDownloader Device have been Connected!")

@new_task
async def keepJdAlive(self):
while True:
await aiosleep(180)
if self.device is None:
break
await sync_to_async(self.reconnect)

try:
await sync_to_async(self.reconnect)
except:
pass

jdownloader = JDownloader()
2 changes: 1 addition & 1 deletion bot/helper/listeners/jdownloader_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async def _onDownloadComplete(gid):
jdownloader.device.downloads.cleanup,
"DELETE_DISABLED",
"REMOVE_LINKS_AND_DELETE_FILES",
"ALL",
"SELECTED",
package_ids=[gid],
)
await task.listener.onDownloadComplete()
Expand Down
15 changes: 6 additions & 9 deletions bot/helper/mirror_utils/download_utils/jd_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,29 +125,26 @@ async def add_jd_download(listener, path):
],
)
packages = []
size = 0
exists = False
for pack in queued_downloads:
if pack["saveTo"] == path:
if len(packages) == 0:
name = pack["name"]
gid = pack["uuid"]
size = pack.get("bytesTotal", 0)
jd_downloads[gid] = "collect"
if pack["onlineCount"] == 0:
if pack.get("onlineCount", 1) == 0:
await listener.onDownloadError(name)
return
packages.append(pack["uuid"])
size += pack.get("bytesTotal", 0)
exists = True

if len(packages) > 1:
await retry_function(
jdownloader.device.action,
"/linkgrabberv2/movePackages",
[packages[1:], packages[0]],
"/linkgrabberv2/movetoNewPackage",
[[], packages, name, path],
)

if exists:
if len(packages) == 1:
break

listener.name = listener.name or name
Expand Down Expand Up @@ -188,7 +185,7 @@ async def add_jd_download(listener, path):
[gid],
)

await sleep(1)
await sleep(0.5)

download_packages = await retry_function(
jdownloader.device.downloads.query_packages,
Expand Down
4 changes: 2 additions & 2 deletions bot/helper/mirror_utils/status_utils/jdownloader_status.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from bot import LOGGER, jd_lock, jd_downloads
from bot.helper.ext_utils.jdownloader_booter import jdownloader
from bot.helper.ext_utils.bot_utils import sync_to_async
from bot.helper.ext_utils.bot_utils import retry_function
from bot.helper.ext_utils.status_utils import (
MirrorStatus,
get_readable_file_size,
Expand Down Expand Up @@ -78,7 +78,7 @@ def gid(self):

async def cancel_task(self):
LOGGER.info(f"Cancelling Download: {self.name()}")
await sync_to_async(
await retry_function(
jdownloader.device.downloads.remove_links, package_ids=[int(self._gid)]
)
async with jd_lock:
Expand Down

0 comments on commit b67db09

Please sign in to comment.