Add cli option to select subscriptions file
This commit is contained in:
parent
407fb26e50
commit
b4b30d1fc0
6 changed files with 20 additions and 9 deletions
|
@ -33,6 +33,7 @@ mod tests {
|
||||||
let file_env = FileEnv::create(&Args {
|
let file_env = FileEnv::create(&Args {
|
||||||
downloads: dir.path().to_string_lossy().to_string(),
|
downloads: dir.path().to_string_lossy().to_string(),
|
||||||
history: "downloaded.txt".to_string(),
|
history: "downloaded.txt".to_string(),
|
||||||
|
subscriptions: file_name.to_string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
//when
|
//when
|
||||||
|
@ -55,6 +56,7 @@ mod tests {
|
||||||
let file_env = FileEnv::create(&Args {
|
let file_env = FileEnv::create(&Args {
|
||||||
downloads: dir.path().to_string_lossy().to_string(),
|
downloads: dir.path().to_string_lossy().to_string(),
|
||||||
history: "downloaded.txt".to_string(),
|
history: "downloaded.txt".to_string(),
|
||||||
|
subscriptions: file_name.to_string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
//when
|
//when
|
||||||
|
@ -77,6 +79,7 @@ mod tests {
|
||||||
let file_env = FileEnv::create(&Args {
|
let file_env = FileEnv::create(&Args {
|
||||||
downloads: dir.path().to_string_lossy().to_string(),
|
downloads: dir.path().to_string_lossy().to_string(),
|
||||||
history: "downloaded.txt".to_string(),
|
history: "downloaded.txt".to_string(),
|
||||||
|
subscriptions: file_name.to_string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
//when
|
//when
|
||||||
|
|
|
@ -42,6 +42,7 @@ mod tests {
|
||||||
&FileEnv::create(&Args {
|
&FileEnv::create(&Args {
|
||||||
downloads: dir.path().to_string_lossy().to_string(),
|
downloads: dir.path().to_string_lossy().to_string(),
|
||||||
history: "downloaded.txt".to_string(),
|
history: "downloaded.txt".to_string(),
|
||||||
|
subscriptions: "subscriptions.txt".to_string(),
|
||||||
}),
|
}),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -76,6 +77,7 @@ mod tests {
|
||||||
&FileEnv::create(&Args {
|
&FileEnv::create(&Args {
|
||||||
downloads: dir.path().to_string_lossy().to_string(),
|
downloads: dir.path().to_string_lossy().to_string(),
|
||||||
history: "downloaded.txt".to_string(),
|
history: "downloaded.txt".to_string(),
|
||||||
|
subscriptions: "subscriptions.txt".to_string(),
|
||||||
}),
|
}),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ mod test {
|
||||||
&FileEnv::create(&Args {
|
&FileEnv::create(&Args {
|
||||||
downloads: dir.path().to_string_lossy().to_string(),
|
downloads: dir.path().to_string_lossy().to_string(),
|
||||||
history: "downloaded.txt".to_string(),
|
history: "downloaded.txt".to_string(),
|
||||||
|
subscriptions: "subscriptions.txt".to_string(),
|
||||||
}),
|
}),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -76,6 +77,7 @@ mod test {
|
||||||
&FileEnv::create(&Args {
|
&FileEnv::create(&Args {
|
||||||
downloads: dir.path().to_string_lossy().to_string(),
|
downloads: dir.path().to_string_lossy().to_string(),
|
||||||
history: "downloaded.txt".to_string(),
|
history: "downloaded.txt".to_string(),
|
||||||
|
subscriptions: "subscriptions.txt".to_string(),
|
||||||
}),
|
}),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -111,6 +113,7 @@ mod test {
|
||||||
&FileEnv::create(&Args {
|
&FileEnv::create(&Args {
|
||||||
downloads: dir.path().to_string_lossy().to_string(),
|
downloads: dir.path().to_string_lossy().to_string(),
|
||||||
history: "downloaded.txt".to_string(),
|
history: "downloaded.txt".to_string(),
|
||||||
|
subscriptions: "subscriptions.txt".to_string(),
|
||||||
}),
|
}),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -20,8 +20,8 @@ pub struct Env {
|
||||||
pub file: FileEnv,
|
pub file: FileEnv,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(subscriptions: &str, site: &str, a: &Args, e: Env) -> Result<()> {
|
pub fn run(site: &str, a: &Args, e: Env) -> Result<()> {
|
||||||
for channel_name in file::read::lines_from(subscriptions, &e.file)? {
|
for channel_name in file::read::lines_from(&a.subscriptions, &e.file)? {
|
||||||
println!("Channel: {}", channel_name);
|
println!("Channel: {}", channel_name);
|
||||||
let feed_url = feed::find(site, &channel_name, &e.network)?;
|
let feed_url = feed::find(site, &channel_name, &e.network)?;
|
||||||
for entry in feed::get(&feed_url, &e.network)?.entries() {
|
for entry in feed::get(&feed_url, &e.network)?.entries() {
|
||||||
|
@ -62,6 +62,8 @@ mod tests {
|
||||||
let subs_file_name = "subs";
|
let subs_file_name = "subs";
|
||||||
let subs_dir =
|
let subs_dir =
|
||||||
create_text_file(subs_file_name, "@channel1\nignore me\n@channel2".as_bytes())?;
|
create_text_file(subs_file_name, "@channel1\nignore me\n@channel2".as_bytes())?;
|
||||||
|
let subs_file_name = format!("{}/{}", subs_dir.path().to_string_lossy(), subs_file_name);
|
||||||
|
|
||||||
// one item from each channel is already listed in the downloads.txt file
|
// one item from each channel is already listed in the downloads.txt file
|
||||||
let history_file_name = "history";
|
let history_file_name = "history";
|
||||||
let history_dir = create_text_file(history_file_name, "c1-f2\nc2-f3".as_bytes())?;
|
let history_dir = create_text_file(history_file_name, "c1-f2\nc2-f3".as_bytes())?;
|
||||||
|
@ -74,6 +76,7 @@ mod tests {
|
||||||
let args = Args {
|
let args = Args {
|
||||||
downloads: subs_dir.path().to_string_lossy().to_string(),
|
downloads: subs_dir.path().to_string_lossy().to_string(),
|
||||||
history: history_file_name.clone(),
|
history: history_file_name.clone(),
|
||||||
|
subscriptions: subs_file_name.clone(),
|
||||||
};
|
};
|
||||||
let env = Env {
|
let env = Env {
|
||||||
network: NetworkEnv {
|
network: NetworkEnv {
|
||||||
|
@ -95,10 +98,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
file: FileEnv {
|
file: FileEnv {
|
||||||
open: mock_file_open(HashMap::from([
|
open: mock_file_open(HashMap::from([
|
||||||
(
|
(subs_file_name.to_string(), subs_file_name),
|
||||||
subs_file_name.to_string(),
|
|
||||||
format!("{}/{}", subs_dir.path().to_string_lossy(), subs_file_name),
|
|
||||||
),
|
|
||||||
(history_file_name.to_string(), history_file_name),
|
(history_file_name.to_string(), history_file_name),
|
||||||
])),
|
])),
|
||||||
append_line: mock_file_append_line(),
|
append_line: mock_file_append_line(),
|
||||||
|
@ -106,7 +106,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
//when
|
//when
|
||||||
run(subs_file_name, site, &args, env)?;
|
run(site, &args, env)?;
|
||||||
//then
|
//then
|
||||||
drop(subs_dir);
|
drop(subs_dir);
|
||||||
drop(history_dir);
|
drop(history_dir);
|
||||||
|
|
|
@ -6,13 +6,11 @@ use podal::prelude::*;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
println!("Podal");
|
println!("Podal");
|
||||||
let subscriptions = "subscriptions.txt";
|
|
||||||
let site = "https://www.youtube.com/";
|
let site = "https://www.youtube.com/";
|
||||||
|
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
podal::run(
|
podal::run(
|
||||||
subscriptions,
|
|
||||||
site,
|
site,
|
||||||
&args,
|
&args,
|
||||||
podal::Env {
|
podal::Env {
|
||||||
|
|
|
@ -12,4 +12,9 @@ pub struct Args {
|
||||||
/// Defaults to "downloaded.txt" located in the downloads directory.
|
/// Defaults to "downloaded.txt" located in the downloads directory.
|
||||||
#[arg(long, default_value = "downloaded.txt")]
|
#[arg(long, default_value = "downloaded.txt")]
|
||||||
pub history: String,
|
pub history: String,
|
||||||
|
|
||||||
|
/// The name of the subscriptions file.
|
||||||
|
/// Defaults to "subscriptions.txt" located in the downloads directory.
|
||||||
|
#[arg(long, default_value = "subscriptions.txt")]
|
||||||
|
pub subscriptions: String,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue