Skip to content

Commit

Permalink
Use more bitmap mime types
Browse files Browse the repository at this point in the history
  • Loading branch information
connorslade committed Oct 21, 2023
1 parent 4b298c1 commit ac88e7d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

A collection of all the [off images](https://technical.swissmicros.com/dm42/doc/dm42_user_manual.html#off_images) from the [Swissmicros Fourm](https://forum.swissmicros.com), generated automatically.

![Screenshot](https://github.com/Basicprogrammer10/offimg_gallery/assets/50306817/61305c2f-2d57-477d-a9a0-8b1496b48333)
![Screenshot](https://github.com/Basicprogrammer10/offimg_gallery/assets/50306817/f142a2fc-b9bb-4674-ab89-b9ace91b2812)
24 changes: 14 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use uuid::Uuid;
const BASE_URL: &str = "https://forum.swissmicros.com";
const OUT_DIR: &str = "out";

const BMP_TYPES: &[&str] = &["image/bmp", "image/x-ms-bmp"];

macro_rules! selector {
($raw:expr) => {{
static SELECTOR: once_cell::sync::OnceCell<scraper::Selector> =
Expand All @@ -35,7 +37,7 @@ fn main() -> Result<()> {
fs::create_dir(OUT_DIR)?;
}

let mut links = HashSet::new();
let mut topics = HashSet::new();
for page in 0.. {
let url = format!("{BASE_URL}/viewforum.php?f=14&start={}", 25 * page);
let res = ureq::get(&url).call()?;
Expand All @@ -49,17 +51,17 @@ fn main() -> Result<()> {
.map(|x| x.value().attr("href").unwrap()[2..].to_owned())
.collect::<Vec<_>>();
let count = posts.len();
links.extend(posts);
topics.extend(posts);

if count != 25 {
break;
}
}

println!("[*] Found {} posts", links.len());
let images = links
println!("[*] Found {} posts", topics.len());
let images = topics
.par_iter()
.progress_count(links.len() as u64)
.progress_count(topics.len() as u64)
.flat_map(|post| {
let mut images = Vec::new();
let mut seen = HashSet::new();
Expand All @@ -86,10 +88,8 @@ fn main() -> Result<()> {

for post in posts {
let id = post.value().attr("id").unwrap();
if seen.contains(id) {
if !seen.insert(id.to_owned()) {
break 'outer;
} else {
seen.insert(id.to_owned());
}

let date = post.select(selector!("time")).next().unwrap();
Expand Down Expand Up @@ -127,14 +127,18 @@ fn main() -> Result<()> {
Err(..) => return None,
};

if raw.status() != 200 || raw.header("Content-Type").unwrap() != "image/bmp" {
let content = raw.header("Content-Type").unwrap();
if raw.status() != 200 || !BMP_TYPES.contains(&content) {
return None;
}

let mut slice = Vec::new();
raw.into_reader().read_to_end(&mut slice).unwrap();

let bmp = RawBmp::from_slice(&slice).unwrap();
let Ok(bmp) = RawBmp::from_slice(&slice) else {
return None;
};

if bmp.header().bpp != Bpp::Bits1 || bmp.header().image_size != Size::new(400, 240) {
return None;
}
Expand Down
2 changes: 1 addition & 1 deletion web/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ hr {
margin-right: 1em;
margin-bottom: 1em;
padding: 0.5em;
width: 418px;
width: 400px;

& [foot] {
max-width: 400px;
Expand Down

0 comments on commit ac88e7d

Please sign in to comment.