refactor: downloader

This commit is contained in:
Benex254
2024-08-11 20:54:32 +03:00
parent c80a8235e1
commit 4102685cbc
3 changed files with 35 additions and 6 deletions

View File

@@ -27,9 +27,27 @@ class YtDLPDownloader:
# Function to download the file
# TODO: untpack the title to its actual values episode_title and anime_title
def _download_file(self, url: str, download_dir, title, silent, vid_format="best"):
anime_title = sanitize_filename(title[0])
episode_title = sanitize_filename(title[1])
def _download_file(
self,
url: str,
anime_title: str,
episode_title: str,
download_dir: str,
silent: bool,
vid_format: str = "best",
):
"""Helper function that downloads anime given url and path details
Args:
url: [TODO:description]
anime_title: [TODO:description]
episode_title: [TODO:description]
download_dir: [TODO:description]
silent: [TODO:description]
vid_format: [TODO:description]
"""
anime_title = sanitize_filename(anime_title)
episode_title = sanitize_filename(episode_title)
ydl_opts = {
# Specify the output path and template
"outtmpl": f"{download_dir}/{anime_title}/{episode_title}.%(ext)s",
@@ -41,7 +59,15 @@ class YtDLPDownloader:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
# WARN: May remove this legacy functionality
def download_file(self, url: str, title, silent=True):
"""A helper that just does things in the background
Args:
title ([TODO:parameter]): [TODO:description]
silent ([TODO:parameter]): [TODO:description]
url: [TODO:description]
"""
self.downloads_queue.put((self._download_file, (url, title, silent)))

View File

@@ -1,3 +1,4 @@
import time
from typing import TYPE_CHECKING
import click
@@ -145,14 +146,16 @@ def download(config: "Config", anime_title, episode_range, highest_priority):
downloader._download_file(
link,
anime["title"],
episode_title,
download_dir,
(anime["title"], episode_title),
True,
config.format,
)
except Exception as e:
print(e)
time.sleep(1)
print("Continuing")
clear()
print("Done")
print("Done Downloading")
exit_app()

View File

@@ -67,5 +67,5 @@ class EpisodeStream(TypedDict):
class Server(TypedDict):
server: str
episode_title: str | None
episode_title: str
links: list[EpisodeStream]