feat: nhl.com site

I was having trouble with the extant sites for this channel so I decided to add a source for the league's own guide. Unfortunately it's missing images since I don't know where they need to be hosted :(
This commit is contained in:
shay
2024-11-21 18:30:57 -06:00
parent 7610f7b9f5
commit 5d33db08b8
6 changed files with 116 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
const dayjs = require('dayjs')
module.exports = {
site: 'nhl.com',
// I'm not sure what `endDate` represents but they only return 1 day of
// results, with `endTime`s ocassionally in the following day.
days: 1,
url: ({ date }) => `https://api-web.nhle.com/v1/network/tv-schedule/${date.toJSON().split("T")[0]}`,
parser({ content }) {
const programs = []
const items = parseItems(content)
for (const item of items) {
programs.push({
title: item.title,
description: item.description === item.title ? undefined : item.description,
category: item.title === "NHL Game" ? "Sports event" : "Sports non-event",
// image: parseImage(item),
start: parseStart(item),
stop: parseStop(item)
})
}
return programs
}
}
// Unfortunately I couldn't determine how these are
// supposed to be formatted. Pointers appreciated!
// function parseImage(item) {
// const uri = item.broadcastImageUrl
// return uri ? `https://???/${uri}` : null
// }
function parseStart(item) {
return dayjs(item.startTime)
}
function parseStop(item) {
return dayjs(item.endTime)
}
function parseItems(content) {
return JSON.parse(content).broadcasts
}