parent
418e68aa57
commit
1a49f937d8
|
|
@ -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}`,
|
||||
|
|
|
|||
|
|
@ -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: `<img style="max-width: 100%;" src="${item.previewThumbnailURL}"><br/><img style="max-width: 100%;" src="${item.animatedPreviewURL}">`,
|
||||
category: [item.game.displayName],
|
||||
category: item.game && [item.game.displayName], // item.game may be null
|
||||
}));
|
||||
|
||||
ctx.state.data = {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
### Channel Video {#twitch-channel-video}
|
||||
|
||||
<Route author="hoilc" path="/video/:login/:filter?" example="/twitch/video/riotgames/highlights" paramsDesc={['Twitch username', 'Video type, Default to all']} radar="1" />
|
||||
<Route author="hoilc" path="/twitch/video/:login/:filter?" example="/twitch/video/riotgames/highlights" paramsDesc={['Twitch username', 'Video type, Default to all']} radar="1" />
|
||||
|
||||
| archive | highlights | all |
|
||||
| ----------------- | ----------------------------- | ---------- |
|
||||
|
|
|
|||
Loading…
Reference in New Issue