aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--crates/yt/src/commands/download/implm/download/mod.rs13
-rw-r--r--crates/yt/src/commands/download/implm/mod.rs2
-rw-r--r--crates/yt/src/commands/download/mod.rs5
3 files changed, 17 insertions, 3 deletions
diff --git a/crates/yt/src/commands/download/implm/download/mod.rs b/crates/yt/src/commands/download/implm/download/mod.rs
index fd28a63..763e9f8 100644
--- a/crates/yt/src/commands/download/implm/download/mod.rs
+++ b/crates/yt/src/commands/download/implm/download/mod.rs
@@ -217,8 +217,16 @@ impl Downloader {
/// This Downloader will periodically check if the database has changed, and then also
/// change which videos it downloads.
/// This will run, until the database doesn't contain any watchable videos
- pub(crate) async fn consume(&mut self, app: Arc<App>, max_cache_size: u64) -> Result<()> {
- while let Some(next_video) = Video::next_to_download(&app).await? {
+ pub(crate) async fn consume(
+ &mut self,
+ app: Arc<App>,
+ max_cache_size: u64,
+ max_to_download: usize,
+ ) -> Result<()> {
+ let mut current_count = 0;
+ while let Some(next_video) = Video::next_to_download(&app).await?
+ && current_count < max_to_download
+ {
match self
.is_enough_cache_available(&app, max_cache_size, &next_video)
.await?
@@ -234,6 +242,7 @@ impl Downloader {
if current_download.is_finished() {
// The download is done, finalize it and leave it removed.
self.yt_dlp = Some(current_download.finalize(&app).await?);
+ current_count += 1;
continue;
}
diff --git a/crates/yt/src/commands/download/implm/mod.rs b/crates/yt/src/commands/download/implm/mod.rs
index 8647a54..99b82fd 100644
--- a/crates/yt/src/commands/download/implm/mod.rs
+++ b/crates/yt/src/commands/download/implm/mod.rs
@@ -29,7 +29,7 @@ impl DownloadCommand {
pub(in crate::commands) async fn implm(self, app: Arc<App>) -> Result<()> {
let DownloadCommand {
force,
- max_cache_size,
+ count
} = self;
let max_cache_size = app.config.download.max_cache_size.as_u64();
diff --git a/crates/yt/src/commands/download/mod.rs b/crates/yt/src/commands/download/mod.rs
index f765803..148aebb 100644
--- a/crates/yt/src/commands/download/mod.rs
+++ b/crates/yt/src/commands/download/mod.rs
@@ -21,6 +21,11 @@ pub(super) struct DownloadCommand {
#[arg(short, long)]
force: bool,
+ /// The maximum amount of videos to download, before stopping.
+ ///
+ /// If not given, will download until nothing uncached is selected as `watch`
+ #[arg(short, long, default_value_t = usize::MAX)]
+ count: usize,
}
fn byte_parser(input: &str) -> Result<u64, anyhow::Error> {