From 2ee701030d8b6daec200b3831eac7230fc921e37 Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Fri, 22 Mar 2019 09:12:30 +0000 Subject: [PATCH] fix: handle YouTube deleted video (#1804) --- lib/routes/youtube/channel.js | 28 +++++++++++++++------------- lib/routes/youtube/playlist.js | 2 +- lib/routes/youtube/user.js | 28 +++++++++++++++------------- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/lib/routes/youtube/channel.js b/lib/routes/youtube/channel.js index 08a777096..8aa29586d 100644 --- a/lib/routes/youtube/channel.js +++ b/lib/routes/youtube/channel.js @@ -12,18 +12,20 @@ module.exports = async (ctx) => { title: `${data[0].snippet.channelTitle} 的 Youtube 视频`, link: `https://www.youtube.com/channel/${id}`, description: `${data[0].snippet.channelTitle} 的 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 ? '' : ''}${utils.formatDescription( - snippet.description - )}`, - pubDate: new Date(snippet.publishedAt).toUTCString(), - link: `https://www.youtube.com/watch?v=${videoId}`, - }; - }), + item: data + .filter((d) => d.snippet.title !== 'Private video' && d.snippet.title !== 'Deleted video') + .map((item) => { + const snippet = item.snippet; + const videoId = snippet.resourceId.videoId; + const img = utils.getThumbnail(snippet.thumbnails); + return { + title: snippet.title, + description: `${ + embed ? '' : '' + }${utils.formatDescription(snippet.description)}`, + pubDate: new Date(snippet.publishedAt).toUTCString(), + link: `https://www.youtube.com/watch?v=${videoId}`, + }; + }), }; }; diff --git a/lib/routes/youtube/playlist.js b/lib/routes/youtube/playlist.js index 20a536e8a..66a3dd019 100644 --- a/lib/routes/youtube/playlist.js +++ b/lib/routes/youtube/playlist.js @@ -13,7 +13,7 @@ module.exports = async (ctx) => { link: `https://www.youtube.com/playlist?list=${id}`, description: `Playlist: ${playlistTitle} by ${data[0].snippet.channelTitle}`, item: data - .filter((d) => d.snippet.title !== 'Private video') + .filter((d) => d.snippet.title !== 'Private video' && d.snippet.title !== 'Deleted video') .map((item) => { const snippet = item.snippet; const videoId = snippet.resourceId.videoId; diff --git a/lib/routes/youtube/user.js b/lib/routes/youtube/user.js index 7a0df544f..6130d205f 100644 --- a/lib/routes/youtube/user.js +++ b/lib/routes/youtube/user.js @@ -12,18 +12,20 @@ module.exports = async (ctx) => { 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 ? '' : ''}${utils.formatDescription( - snippet.description - )}`, - pubDate: new Date(snippet.publishedAt).toUTCString(), - link: `https://www.youtube.com/watch?v=${videoId}`, - }; - }), + item: data + .filter((d) => d.snippet.title !== 'Private video' && d.snippet.title !== 'Deleted video') + .map((item) => { + const snippet = item.snippet; + const videoId = snippet.resourceId.videoId; + const img = utils.getThumbnail(snippet.thumbnails); + return { + title: snippet.title, + description: `${ + embed ? '' : '' + }${utils.formatDescription(snippet.description)}`, + pubDate: new Date(snippet.publishedAt).toUTCString(), + link: `https://www.youtube.com/watch?v=${videoId}`, + }; + }), }; };