Public
Script
Readme

Gets a list with all the films a user has added to their public diary in Letterboxd. The result is a JSON file with the following structure:

"updated_at": "2023-08-13", "count": 470, "films": [ { "watched_on": "2022-10-24", "title": "Aftersun (2022)", "rating": 4.5, "rewatched": false }, { "watched_on": "2021-03-20", "title": "Le Trou (1960)", "rating": 5, "rewatched": true }, ... { "watched_on": "2020-09-13", "title": "Tampopo (1985)", "rating": 5, "rewatched": false } ] }

If you want to use it in the browser, just visit this URL:

https://javier-letterboxdscrapper.web.val.run/?username={username}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=5";
export const letterboxd = async (username: string) => {
const { default: cheerio } = await import("npm:cheerio");
const URL = `https://letterboxd.com/${username}/films/diary/`;
const getTotalPages = async () => {
const html = await fetchText(URL);
const $ = cheerio.load(html);
return +$(".paginate-page a").last().text();
};
const getFilmsForPage = async (page) => {
const html = await fetchText(URL + "page/" + page);
const $ = cheerio.load(html);
return $(".diary-entry-edit a").map((i, metadata) => {
const filmTitle = $(metadata).data("film-name");
const watchedOn = $(metadata).data("viewing-date");
const rewatched = $(metadata).data("rewatch");
const year = $(metadata).data("film-year");
const title = `${filmTitle} (${year})`;
const rating = parseInt($(metadata).data("rating"), 10) / 2;
return { title, watched_on: watchedOn, rating, rewatched };
});
};
async function getFilms() {
const totalPages = await getTotalPages();
const films = [];
for (let i = 1; i <= totalPages; i++) {
const movies = await getFilmsForPage(i);
for (let j = 0; j < movies.length; j++) {
films.push(movies[j]);
}
}
return {
updated_at: new Date().toISOString().split("T")[0],
count: films.length,
films,
};
}
return getFilms();
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
April 30, 2024