Skip to content

Commit 251f7a4

Browse files
committed
adds error message when no pages are downloaded
1 parent 0d3656f commit 251f7a4

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- uses: actions/checkout@v6
19+
- name: Build
20+
run: cargo build --verbose
1921
- name: Run tests
2022
run: cargo test --verbose

src/lib/scraper/scraper.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ pub fn download_issue_skip_downloaded(
8282
length_limit: max_length,
8383
..Default::default()
8484
};
85-
let issue_combined_id = std::format!("{0} [{1}]", sanitise_with_options(&meta.get_full_title(), &sanitize_options), meta.id);
85+
let issue_combined_id = std::format!(
86+
"{0} [{1}]",
87+
sanitise_with_options(&meta.get_full_title(), &sanitize_options),
88+
meta.id
89+
);
8690
let dest = match meta.book_type {
8791
ContentType::Magazine | ContentType::Newspaper => {
8892
std::format!("{dest}/{0}", sanitise(&meta.title))
@@ -142,7 +146,10 @@ pub fn download_issue_skip_downloaded(
142146
}
143147

144148
// Fetch JSON to get info about all pages.
145-
let mut res = try_download(&get_json_url(&id, "1", "1", Some(options)), options.download_attempts)?;
149+
let mut res = try_download(
150+
&get_json_url(&id, "1", "1", Some(options)),
151+
options.download_attempts,
152+
)?;
146153
let mut body = String::new();
147154
res.read_to_string(&mut body)?;
148155
let issue: IssueJson = serde_json::from_str(&body).to_result()?;
@@ -362,6 +369,15 @@ pub fn download_issue_skip_downloaded(
362369
}
363370
}
364371

372+
if pages_downloaded.is_empty() {
373+
return Err(std::io::Error::other(
374+
match options.tld.as_str() {
375+
".com" => "No downloadable pages found.",
376+
_ => "No downloadable pages found. Setting --tld-override to \".com\" may fix this issue.",
377+
}
378+
));
379+
}
380+
365381
// Download any formats not already downloaded.
366382
if formats.contains(FormatFlags::Pdf) {
367383
println!("Generating PDF...");
@@ -381,13 +397,6 @@ pub fn download_issue_skip_downloaded(
381397
if let Some(downloaded) = already_downloaded {
382398
downloaded.insert(id.to_string());
383399
}
384-
options.archive_file.as_ref().map(|archive| {
385-
if let Ok(mut file) = OpenOptions::new().append(true).create(true).open(archive) {
386-
if let Err(e) = file.write(std::format!("{id}\n").as_bytes()) {
387-
eprintln!("Couldn't write to file: {}", e);
388-
}
389-
}
390-
});
391400
if let Some(archive) = options.archive_file.as_ref() {
392401
if let Ok(mut file) = OpenOptions::new().append(true).create(true).open(archive) {
393402
if let Err(e) = file.write(std::format!("{id}\n").as_bytes()) {

0 commit comments

Comments
 (0)