From: mj-saunders <34356259+mj-saunders@users.noreply.github.com> Date: Mon, 22 Nov 2021 15:10:00 +0000 (+0400) Subject: Apply import interval only when reasonable (#4552) X-Git-Tag: v4.0.0-rc.1~36 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=e291096f78a4e86deb7c2a53b379f4c6f83c1ec6;p=github%2FChocobozzz%2FPeerTube.git Apply import interval only when reasonable (#4552) * Apply import interval only when reasonable When importing videos from another service, an interval can be applied between each download. It only really makes sense to apply this interval when the last attempted download actually happened, and not when it was skipped. * Fix boolean notation --- diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts index 54ac910e6..a758beef9 100644 --- a/server/tools/peertube-import-videos.ts +++ b/server/tools/peertube-import-videos.ts @@ -95,14 +95,15 @@ async function run (url: string, username: string, password: string) { log.info('Will download and upload %d videos.\n', infoArray.length) + let skipInterval = true for (const [ index, info ] of infoArray.entries()) { try { - if (index > 0 && options.waitInterval) { + if (index > 0 && options.waitInterval && !skipInterval) { log.info("Wait for %d seconds before continuing.", options.waitInterval / 1000) await wait(options.waitInterval) } - await processVideo({ + skipInterval = await processVideo({ cwd: options.tmpdir, url, username, @@ -134,12 +135,12 @@ async function processVideo (parameters: { if (options.since && videoInfo.originallyPublishedAt && videoInfo.originallyPublishedAt.getTime() < options.since.getTime()) { log.info('Video "%s" has been published before "%s", don\'t upload it.\n', videoInfo.name, formatDate(options.since)) - return + return true } if (options.until && videoInfo.originallyPublishedAt && videoInfo.originallyPublishedAt.getTime() > options.until.getTime()) { log.info('Video "%s" has been published after "%s", don\'t upload it.\n', videoInfo.name, formatDate(options.until)) - return + return true } const server = buildServer(url) @@ -155,7 +156,7 @@ async function processVideo (parameters: { if (data.find(v => v.name === videoInfo.name)) { log.info('Video "%s" already exists, don\'t reupload it.\n', videoInfo.name) - return + return true } const path = join(cwd, sha256(videoInfo.url) + '.mp4') @@ -184,6 +185,8 @@ async function processVideo (parameters: { } catch (err) { log.error(err.message) } + + return false } async function uploadVideoOnPeerTube (parameters: {