Skip to content

Commit

Permalink
Refactor custdl.py to fix button indexing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xAmarnath committed May 4, 2024
1 parent a4a1392 commit d993bd1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions modules/custdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async def series_x(e):

buttons = []
for season in seasons:
buttons.append([Button.inline(season["title"], data=f"season_{series_id}_{season['season_id']}_{series['category']}_{len(buttons)}")])
buttons.append([Button.inline(season["title"], data=f"season_{series_id}_{season['season_id']}_{series['category']}_{len(buttons)+1}")])

buttons.append([Button.inline("Back", data="back")])

Expand All @@ -142,7 +142,7 @@ async def season_x(e):

buttons = []
for episode in episodes:
buttons.append([Button.inline(episode["title"], data=f"episode_{series_id}_{season_id}_{episode['episode_id']}_{category}_{season_index}_{len(buttons)}")])
buttons.append([Button.inline(episode["title"], data=f"episode_{series_id}_{season_id}_{episode['episode_id']}_{category}_{season_index}_{len(buttons)+1}")])

buttons.append([Button.inline("Download All", data=f"download_all")])
buttons.append([Button.inline("Back", data=f"series_{series_id}")])
Expand Down Expand Up @@ -207,7 +207,9 @@ async def download_x(e):
except KeyError:
return await e.edit("Series not found.")

out_folder = "downloads"
out_folder = "downloads_temp"
if not await exists(out_folder):
await mkdir(out_folder)
out_filename = f"{series['title']}_{category}_{season_index}_{episode_index}.mkv"
await e.edit(f"Downloading {out_filename}...", buttons=[Button.inline("Back", data=f"series_{series_id}")])
ms = await e.respond("Downloading...")
Expand All @@ -230,11 +232,15 @@ async def download_x(e):
(await create_subprocess_shell(" ".join(ffmpeg_command))).wait()

# os.remove(f"{out_folder}/{out_filename}")
await create_subprocess_shell(f"mv '{out_folder}/{out_filename.replace('.mkv', '_subs.mkv')}' downloads/").wait()

await ms.edit(f"Downloaded {out_filename} in {time.time() - t:.2f} seconds.", buttons=[[Button.inline("Back", data=f"episode_{series_id}_{season_index}_{episode_index}_{category}_{season_index}_{episode_index}")],
[Button.url("Index Link", f"{SERVIO_TEMP}")]])
await remove(f"{out_folder}/{out_filename}")

# move the file to downloads folder





Expand Down

0 comments on commit d993bd1

Please sign in to comment.