From 0fc03e780c48642f2b253a1faf50cda1fed6f646 Mon Sep 17 00:00:00 2001 From: dylan Date: Thu, 25 Dec 2025 18:20:44 +0000 Subject: [PATCH] added functions to fetch trakt movie history and combine episode and movie titles --- utils.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/utils.js b/utils.js index be66013..7e4751f 100644 --- a/utils.js +++ b/utils.js @@ -119,6 +119,23 @@ export async function getTraktEpisode(username, id, showImage = true) { return `${cleanTitle} ![${cleanTitle}](https://widgets.trakt.tv/users/${id}/watched/thumb@2x.jpg?type=episode&image_only=1)` } +export async function getTraktMovie(username, showImage = true) { + const res = await fetch( + `https://trakt.tv/users/${username}/history/movies/added/asc.atom?slurm=${process.env.TRAKT_SLURM}`, + ) + const data = await res.text() + const dom = new JSDOM(data) + const entry = dom.window.document.querySelector('entry') + const title = entry.querySelector('title').textContent + return markdownCharEscape(title) +} + +export async function getTraktEpisodeAndMovie(username, id, showImage = true) { + const episode = await getTraktEpisode(username, id, showImage) + const movie = await getTraktMovie(username, showImage) + return `${episode} and ${movie}` +} + export async function getReadingBooklogr(booklogrUrl, booklogrUser) { const res = await fetch(`${booklogrUrl}/v1/profiles/${booklogrUser}`) const data = await res.json()