Files
RSSHub/routes/youtube/user.js
T
Henry Wang 72bf98117a Added playlist support. Refactored code (#795)
Close #728 

1. 重复代码精简
1. 可选内嵌视频,测试 Reeder iOS/mac 以及 TTRSS Chrome 完美播放。
1. Description 换行处理
2018-09-26 17:20:22 +08:00

30 lines
1.3 KiB
JavaScript

const utils = require('./utils');
module.exports = async (ctx) => {
const username = ctx.params.username;
const embed = !ctx.params.embed;
const playlistId = (await utils.getChannelWithUsername(username, 'contentDetails')).data.items[0].contentDetails.relatedPlaylists.uploads;
const data = (await utils.getPlaylistItems(playlistId, 'snippet,contentDetails')).data.items;
ctx.state.data = {
title: `${username} 的 Youtube 视频`,
link: `https://www.youtube.com/user/${username}`,
description: `${username} 的 Youtube 视频`,
item: data.map((item) => {
const snippet = item.snippet;
const videoId = snippet.resourceId.videoId;
const img = utils.getThumbnail(snippet.thumbnails);
return {
title: snippet.title,
description: `${embed ? '<iframe id="ytplayer" type="text/html" width="640" height="360" src="https://www.youtube.com/embed/' + videoId + '" frameborder="0" allowfullscreen></iframe>' : ''}${utils.formatDescription(
snippet.description
)}<img referrerpolicy="no-referrer" src="${img.url}">`,
pubDate: new Date(snippet.publishedAt).toUTCString(),
link: `https://www.youtube.com/watch?v=${videoId}`,
};
}),
};
};