aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-import-videos.ts
diff options
context:
space:
mode:
authormj-saunders <34356259+mj-saunders@users.noreply.github.com>2021-11-22 19:10:00 +0400
committerGitHub <noreply@github.com>2021-11-22 16:10:00 +0100
commite291096f78a4e86deb7c2a53b379f4c6f83c1ec6 (patch)
treeed0fb9f39a2b73275fd0515cb9df5d9a0ed008c8 /server/tools/peertube-import-videos.ts
parent1622e095232eb0c619d8092ddd48bfb95218faab (diff)
downloadPeerTube-e291096f78a4e86deb7c2a53b379f4c6f83c1ec6.tar.gz
PeerTube-e291096f78a4e86deb7c2a53b379f4c6f83c1ec6.tar.zst
PeerTube-e291096f78a4e86deb7c2a53b379f4c6f83c1ec6.zip
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
Diffstat (limited to 'server/tools/peertube-import-videos.ts')
-rw-r--r--server/tools/peertube-import-videos.ts13
1 files changed, 8 insertions, 5 deletions
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) {
95 95
96 log.info('Will download and upload %d videos.\n', infoArray.length) 96 log.info('Will download and upload %d videos.\n', infoArray.length)
97 97
98 let skipInterval = true
98 for (const [ index, info ] of infoArray.entries()) { 99 for (const [ index, info ] of infoArray.entries()) {
99 try { 100 try {
100 if (index > 0 && options.waitInterval) { 101 if (index > 0 && options.waitInterval && !skipInterval) {
101 log.info("Wait for %d seconds before continuing.", options.waitInterval / 1000) 102 log.info("Wait for %d seconds before continuing.", options.waitInterval / 1000)
102 await wait(options.waitInterval) 103 await wait(options.waitInterval)
103 } 104 }
104 105
105 await processVideo({ 106 skipInterval = await processVideo({
106 cwd: options.tmpdir, 107 cwd: options.tmpdir,
107 url, 108 url,
108 username, 109 username,
@@ -134,12 +135,12 @@ async function processVideo (parameters: {
134 135
135 if (options.since && videoInfo.originallyPublishedAt && videoInfo.originallyPublishedAt.getTime() < options.since.getTime()) { 136 if (options.since && videoInfo.originallyPublishedAt && videoInfo.originallyPublishedAt.getTime() < options.since.getTime()) {
136 log.info('Video "%s" has been published before "%s", don\'t upload it.\n', videoInfo.name, formatDate(options.since)) 137 log.info('Video "%s" has been published before "%s", don\'t upload it.\n', videoInfo.name, formatDate(options.since))
137 return 138 return true
138 } 139 }
139 140
140 if (options.until && videoInfo.originallyPublishedAt && videoInfo.originallyPublishedAt.getTime() > options.until.getTime()) { 141 if (options.until && videoInfo.originallyPublishedAt && videoInfo.originallyPublishedAt.getTime() > options.until.getTime()) {
141 log.info('Video "%s" has been published after "%s", don\'t upload it.\n', videoInfo.name, formatDate(options.until)) 142 log.info('Video "%s" has been published after "%s", don\'t upload it.\n', videoInfo.name, formatDate(options.until))
142 return 143 return true
143 } 144 }
144 145
145 const server = buildServer(url) 146 const server = buildServer(url)
@@ -155,7 +156,7 @@ async function processVideo (parameters: {
155 156
156 if (data.find(v => v.name === videoInfo.name)) { 157 if (data.find(v => v.name === videoInfo.name)) {
157 log.info('Video "%s" already exists, don\'t reupload it.\n', videoInfo.name) 158 log.info('Video "%s" already exists, don\'t reupload it.\n', videoInfo.name)
158 return 159 return true
159 } 160 }
160 161
161 const path = join(cwd, sha256(videoInfo.url) + '.mp4') 162 const path = join(cwd, sha256(videoInfo.url) + '.mp4')
@@ -184,6 +185,8 @@ async function processVideo (parameters: {
184 } catch (err) { 185 } catch (err) {
185 log.error(err.message) 186 log.error(err.message)
186 } 187 }
188
189 return false
187} 190}
188 191
189async function uploadVideoOnPeerTube (parameters: { 192async function uploadVideoOnPeerTube (parameters: {