diff --git a/lib/v2/twitch/schedule.js b/lib/v2/twitch/schedule.js index 21345e196f5409..b393fc8fdeddc4 100644 --- a/lib/v2/twitch/schedule.js +++ b/lib/v2/twitch/schedule.js @@ -57,7 +57,8 @@ module.exports = async (ctx) => { const displayName = channelShellData.userOrError.displayName; - const out = streamScheduleData.user.channel.schedule.segments.map((item) => ({ + // schedule segments may be null + const out = streamScheduleData.user.channel.schedule.segments?.map((item) => ({ title: item.title, guid: item.id, link: `https://www.twitch.tv/${login}`, diff --git a/lib/v2/twitch/video.js b/lib/v2/twitch/video.js index d552077d98c815..a29c5443fefdc4 100644 --- a/lib/v2/twitch/video.js +++ b/lib/v2/twitch/video.js @@ -4,14 +4,18 @@ const { parseDate } = require('@/utils/parse-date'); // https://github.com/streamlink/streamlink/blob/master/src/streamlink/plugins/twitch.py#L286 const TWITCH_CLIENT_ID = 'kimne78kx3ncx6brgo4mv6wki5h1ko'; -const FILTER_CURSOR_MAP = { - archive: 0, - highlights: 1, - all: 2, +const FILTER_NODE_TYPE_MAP = { + archive: 'LATEST_BROADCASTS', + highlights: 'LATEST_NON_BROADCASTS', + all: 'ALL_VIDEOS', }; module.exports = async (ctx) => { - const { login, filter = 'all' } = ctx.params; + const login = ctx.params.login; + const filter = ctx.params.filter?.toLowerCase() || 'all'; + if (!FILTER_NODE_TYPE_MAP[filter]) { + throw Error(`Unsupported filter type "${filter}", please choose from { ${Object.keys(FILTER_NODE_TYPE_MAP).join(', ')} }`); + } const response = await got({ method: 'post', @@ -45,7 +49,10 @@ module.exports = async (ctx) => { const displayName = channelVideoShelvesQueryData.user.displayName; - const videoShelvesEdge = channelVideoShelvesQueryData.user.videoShelves.edges[FILTER_CURSOR_MAP[filter] || FILTER_CURSOR_MAP.all]; + const videoShelvesEdge = channelVideoShelvesQueryData.user.videoShelves.edges.find((edge) => edge.node.type === FILTER_NODE_TYPE_MAP[filter]); + if (!videoShelvesEdge) { + throw Error(`No video under filter type "${filter}"`); + } const out = videoShelvesEdge.node.items.map((item) => ({ title: item.title, @@ -53,7 +60,7 @@ module.exports = async (ctx) => { author: displayName, pubDate: parseDate(item.publishedAt), description: `
`, - category: [item.game.displayName], + category: item.game && [item.game.displayName], // item.game may be null })); ctx.state.data = { diff --git a/website/docs/routes/live.mdx b/website/docs/routes/live.mdx index 1e92b84d4f6ef7..7cf6de50cc588d 100644 --- a/website/docs/routes/live.mdx +++ b/website/docs/routes/live.mdx @@ -18,7 +18,7 @@ ### Channel Video {#twitch-channel-video} - + | archive | highlights | all | | ----------------- | ----------------------------- | ---------- |