From d8794cf85554a17e1f110f49a0c965be825a9b4a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 14 Dec 2020 09:40:31 +0100 Subject: More robust import script when using since/until --- server/tools/peertube-import-videos.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts index d04ddfe06..1b2c63af2 100644 --- a/server/tools/peertube-import-videos.ts +++ b/server/tools/peertube-import-videos.ts @@ -124,19 +124,18 @@ function processVideo (parameters: { const videoInfo = await fetchObject(youtubeInfo) log.debug('Fetched object.', videoInfo) - if (program['since']) { - if (buildOriginallyPublishedAt(videoInfo).getTime() < program['since'].getTime()) { - log.info('Video "%s" has been published before "%s", don\'t upload it.\n', - videoInfo.title, formatDate(program['since'])) - return res() - } + const originallyPublishedAt = buildOriginallyPublishedAt(videoInfo) + + if (program['since'] && originallyPublishedAt && originallyPublishedAt.getTime() < program['since'].getTime()) { + log.info('Video "%s" has been published before "%s", don\'t upload it.\n', + videoInfo.title, formatDate(program['since'])) + return res() } - if (program['until']) { - if (buildOriginallyPublishedAt(videoInfo).getTime() > program['until'].getTime()) { - log.info('Video "%s" has been published after "%s", don\'t upload it.\n', - videoInfo.title, formatDate(program['until'])) - return res() - } + + if (program['until'] && originallyPublishedAt && originallyPublishedAt.getTime() > program['until'].getTime()) { + log.info('Video "%s" has been published after "%s", don\'t upload it.\n', + videoInfo.title, formatDate(program['until'])) + return res() } const result = await searchVideoWithSort(url, videoInfo.title, '-match') -- cgit v1.2.3