1
0
Fork 0

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
This commit is contained in:
mj-saunders 2021-11-22 19:10:00 +04:00 committed by GitHub
parent 1622e09523
commit e291096f78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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: {