Skip to content

Commit 565cf03

Browse files
committed
letterboxd date fix
1 parent d89e0ce commit 565cf03

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

backend/src/fetching/letterboxd.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use cached::proc_macro::once;
2+
use regex::Regex;
23
use scraper::{Html, Selector};
34
use types::Movie;
45

@@ -16,15 +17,22 @@ fn parse_image(html: &Html) -> Result<String, Box<dyn std::error::Error>> {
1617
}
1718

1819
fn parse_release_year(html: &Html) -> Result<String, Box<dyn std::error::Error>> {
19-
let img_selector = Selector::parse("div.react-component.poster.film-poster").unwrap();
20+
let frame_selector = Selector::parse("span.frame[title]").unwrap();
2021

21-
Ok(html
22-
.select(&img_selector)
22+
let date_re = Regex::new(r"\((\d{4})\)").unwrap();
23+
24+
let title = html
25+
.select(&frame_selector)
2326
.next()
24-
.ok_or("Image source not found in HTML")?
25-
.attr("data-film-release-year")
26-
.ok_or("Image source attribute not found in HTML")?
27-
.to_string())
27+
.ok_or("Frame not found in HTML")?
28+
.attr("title")
29+
.ok_or("Title not found in frame HTML")?;
30+
31+
Ok(date_re
32+
.captures(title)
33+
.and_then(|caps| caps.get(1))
34+
.map(|year| year.as_str().to_owned())
35+
.ok_or("Couldn't parse date")?)
2836
}
2937

3038
// 1 day

0 commit comments

Comments
 (0)