From bf2730f991dd8a56d0d4416a48fcb18c498efc50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Sun, 29 Nov 2020 21:54:35 +0100 Subject: [PATCH] Fix exploration for multiple videos --- lib/explore.mjs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/explore.mjs b/lib/explore.mjs index 62bbfb5..99d6eef 100644 --- a/lib/explore.mjs +++ b/lib/explore.mjs @@ -28,21 +28,22 @@ export const exploreVideos = async (videoId, onUpdate) => while (queue.length > 0) { const currentId = queue.shift(); - const config = await api.getPlayerConfig(currentId); - const meta = api.getVideoMeta(config); - videosNodes[currentId] = meta; - nextVideos[currentId] = new Set(); - - // Add links between this video and the linked ones - api.getEndScreenVideos(config) - .forEach(nextId => nextVideos[meta.videoId].add(nextId)); - api.getCardVideos(config) - .forEach(nextId => nextVideos[meta.videoId].add(nextId)); - - for (let nextId of nextVideos[meta.videoId]) + if (!(currentId in videosNodes)) { - if (!(nextId in videosNodes)) + const config = await api.getPlayerConfig(currentId); + const meta = api.getVideoMeta(config); + + videosNodes[currentId] = meta; + nextVideos[currentId] = new Set(); + + // Add links between this video and the linked ones + api.getEndScreenVideos(config) + .forEach(nextId => nextVideos[meta.videoId].add(nextId)); + api.getCardVideos(config) + .forEach(nextId => nextVideos[meta.videoId].add(nextId)); + + for (let nextId of nextVideos[meta.videoId]) { queue.push(nextId); }