Skip to content

Commit

Permalink
feat: add list-ids flag (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
baduker authored Jan 16, 2025
1 parent 5768cc8 commit 5e46a5e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ Cargo.lock
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.

.idea/
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "untitled"
version = "0.4.4"
version = "0.4.5"
edition = "2021"

[dependencies]
Expand Down
6 changes: 5 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ pub enum Commands {
#[arg(short, long, value_name = "ID", conflicts_with = "url")]
id: Option<String>,

/// Download multiple galleries by providing their ids by separating them with commas
#[arg(short, long, num_args = 1.., value_name = "LIST-IDS", conflicts_with = "url")]
list_ids: Option<Vec<String>>,

/// Download full-size images
#[arg(long, default_value = "false")]
full_size_image: bool,
},
#[command(about = "Updates girl's galleries")]
Update {
/// auto approve the update (don't ask for confirmation)
/// Auto approve the update (don't ask for confirmation)
#[arg(short, long, value_name = "AUTO_APPROVE", default_value = "false")]
auto_approve: bool,

Expand Down
82 changes: 49 additions & 33 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,65 @@ use clap::Parser;
use cli::{Cli, Commands};
use config::{print_config, read_or_create_config, MyConfig};

const BASE_URL: &str = "https://kindgirls.com/old/girls.php?id=";
fn main() {
let start_timer = std::time::Instant::now();
let cli = Cli::parse();
match read_or_create_config::<MyConfig>() {
Ok(config) => match cli.command {
Some(Commands::Config { print }) => {
if print {
print_config(&config);
Ok(config) => {
match cli.command {
Some(Commands::Config { print }) => {
if print {
print_config(&config);
}
}
}
Some(Commands::Scrape {
url,
id,
full_size_image,
}) => match (url, id) {
(Some(url), None) => scrape(&config, Some(&url), full_size_image),
(None, Some(id)) => {
if !validate_id(&id) {
eprintln!(
Some(Commands::Scrape {
url,
id,
list_ids,
full_size_image,
}) => match (url, id, list_ids) {
(Some(url), None, None) => scrape(&config, Some(&url), full_size_image),
(None, Some(id), None) => {
if !validate_id(&id) {
eprintln!(
"Girl's page ID's are only numbers! Double check the id and try again."
);
return;
return;
}
let gallery_url = format!("{}{}", BASE_URL, id);
scrape(&config, Some(&gallery_url), full_size_image)
}
let constructed_url =
format!("https://www.kindgirls.com/old/girls.php?id={}", id);
scrape(&config, Some(&constructed_url), full_size_image)
}
(None, None) => eprintln!("You need to specify either a girl's page URL or ID!"),
(Some(_), Some(_)) => eprintln!("You can't use both URL and ID at the same time!"),
},
Some(Commands::Update {
auto_approve,
parallel,
workers,
}) => {
if auto_approve {
println!("Running the update in the AUTO-APPROVE mode.");
(None, None, Some(list_ids)) => {
for id in list_ids {
if !validate_id(&id) {
eprintln!("Error: ID's are only numbers! Double check the id and try again.");
return;
}
let gallery_url = format!("{}{}", BASE_URL, id);
// TODO: It'd be nice to implement multi-threading here
scrape(&config, Some(&gallery_url), full_size_image)
}
}
(None, None, None) => {
eprintln!("You need to specify either a girl's page URL or ID!")
}
_ => eprintln!("You can't use both an URL and IDs at the same time!"),
},
Some(Commands::Update {
auto_approve,
parallel,
workers,
}) => {
if auto_approve {
println!("Running the update in the AUTO-APPROVE mode.");
}
scraper::updater::Updater::update(&config, auto_approve, parallel, workers)
.unwrap();
}
scraper::updater::Updater::update(&config, auto_approve, parallel, workers)
.unwrap();
None => eprintln!("No command specified! Use --help to see available commands."),
}
None => eprintln!("No command specified! Use --help to see available commands."),
},
}
Err(e) => {
eprintln!("Error: {}", e);
}
Expand Down
4 changes: 4 additions & 0 deletions src/scraper/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const DEFAULT_USER_AGENT: &str = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7
const DEFAULT_BASE_URL: &str = "https://kindgirls.com";

pub fn scrape<T: Config>(config: &T, url: Option<&str>, full_size_image: bool) {
// Add a validation check based on id that can be read from the url
// All collections have a JSON file that holds the id field
// If the id from the url matches the id in the file, we already have all the data
// We can prompt the user to update the data if it's outdated
match url {
Some(url) => {
println!("Collecting data from {}", url);
Expand Down

0 comments on commit 5e46a5e

Please sign in to comment.