feat: tv posters

This commit is contained in:
Cory Dransfeldt 2023-05-26 20:25:18 -07:00
parent 71fd6da548
commit 06484abc42
No known key found for this signature in database
3 changed files with 38 additions and 27 deletions

View file

@ -1,23 +1,19 @@
const { extract } = require('@extractus/feed-extractor')
const { AssetCache } = require('@11ty/eleventy-fetch')
const EleventyFetch = require('@11ty/eleventy-fetch')
module.exports = async function () {
const TV_KEY = process.env.API_KEY_TRAKT
const url = `https://trakt.tv/users/cdransf/history.atom?slurm=${TV_KEY}`
// noinspection JSCheckFunctionSignatures
const asset = new AssetCache('tv_data')
if (asset.isCacheValid('1h')) return await asset.getCachedValue()
const res = await extract(url, {
getExtraEntryFields: (feedEntry) => {
const image = feedEntry['media:thumbnail']['@_url']
return {
image,
}
const url = 'https://api.trakt.tv/users/cdransf/history/shows'
const res = EleventyFetch(url, {
duration: '1h',
type: 'json',
fetchOptions: {
headers: {
'Content-Type': 'application/json',
'trakt-api-version': 2,
'trakt-api-key': TV_KEY,
},
},
}).catch((error) => {
console.log(error.message)
})
const data = res.entries.splice(0, 6)
await asset.save(data, 'json')
return data
}).catch()
const shows = await res
return shows.splice(0, 6)
}