aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools
diff options
context:
space:
mode:
Diffstat (limited to 'server/tools')
-rw-r--r--server/tools/peertube-import-videos.ts41
1 files changed, 24 insertions, 17 deletions
diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts
index b3c3aee3e..39e8221c0 100644
--- a/server/tools/peertube-import-videos.ts
+++ b/server/tools/peertube-import-videos.ts
@@ -1,4 +1,5 @@
1import { registerTSPaths } from '../helpers/register-ts-paths' 1import { registerTSPaths } from '../helpers/register-ts-paths'
2
2registerTSPaths() 3registerTSPaths()
3 4
4// FIXME: https://github.com/nodejs/node/pull/16853 5// FIXME: https://github.com/nodejs/node/pull/16853
@@ -57,8 +58,8 @@ getServerCredentials(command)
57 exitError('--tmpdir %s: directory does not exist or is not accessible', program[ 'tmpdir' ]) 58 exitError('--tmpdir %s: directory does not exist or is not accessible', program[ 'tmpdir' ])
58 } 59 }
59 60
60 url = removeEndSlashes(url) 61 url = normalizeTargetUrl(url)
61 program[ 'targetUrl' ] = removeEndSlashes(program[ 'targetUrl' ]) 62 program[ 'targetUrl' ] = normalizeTargetUrl(program[ 'targetUrl' ])
62 63
63 const user = { username, password } 64 const user = { username, password }
64 65
@@ -84,11 +85,11 @@ async function run (url: string, user: UserInfo) {
84 let infoArray: any[] 85 let infoArray: any[]
85 86
86 // Normalize utf8 fields 87 // Normalize utf8 fields
87 infoArray = [].concat(info); 88 infoArray = [].concat(info)
88 if (program[ 'first' ]) { 89 if (program[ 'first' ]) {
89 infoArray = infoArray.slice(0, program[ 'first' ]) 90 infoArray = infoArray.slice(0, program[ 'first' ])
90 } else if (program[ 'last' ]) { 91 } else if (program[ 'last' ]) {
91 infoArray = infoArray.slice(- program[ 'last' ]) 92 infoArray = infoArray.slice(-program[ 'last' ])
92 } 93 }
93 infoArray = infoArray.map(i => normalizeObject(i)) 94 infoArray = infoArray.map(i => normalizeObject(i))
94 95
@@ -125,15 +126,15 @@ function processVideo (parameters: {
125 if (program[ 'since' ]) { 126 if (program[ 'since' ]) {
126 if (buildOriginallyPublishedAt(videoInfo).getTime() < program[ 'since' ].getTime()) { 127 if (buildOriginallyPublishedAt(videoInfo).getTime() < program[ 'since' ].getTime()) {
127 log.info('Video "%s" has been published before "%s", don\'t upload it.\n', 128 log.info('Video "%s" has been published before "%s", don\'t upload it.\n',
128 videoInfo.title, formatDate(program[ 'since' ])); 129 videoInfo.title, formatDate(program[ 'since' ]))
129 return res(); 130 return res()
130 } 131 }
131 } 132 }
132 if (program[ 'until' ]) { 133 if (program[ 'until' ]) {
133 if (buildOriginallyPublishedAt(videoInfo).getTime() > program[ 'until' ].getTime()) { 134 if (buildOriginallyPublishedAt(videoInfo).getTime() > program[ 'until' ].getTime()) {
134 log.info('Video "%s" has been published after "%s", don\'t upload it.\n', 135 log.info('Video "%s" has been published after "%s", don\'t upload it.\n',
135 videoInfo.title, formatDate(program[ 'until' ])); 136 videoInfo.title, formatDate(program[ 'until' ]))
136 return res(); 137 return res()
137 } 138 }
138 } 139 }
139 140
@@ -329,8 +330,14 @@ function isNSFW (info: any) {
329 return info.age_limit && info.age_limit >= 16 330 return info.age_limit && info.age_limit >= 16
330} 331}
331 332
332function removeEndSlashes (url: string) { 333function normalizeTargetUrl (url: string) {
333 return url.replace(/\/+$/, '') 334 let normalizedUrl = url.replace(/\/+$/, '')
335
336 if (!normalizedUrl.startsWith('http://') || !normalizedUrl.startsWith('https://')) {
337 normalizedUrl = 'https://' + normalizedUrl
338 }
339
340 return normalizedUrl
334} 341}
335 342
336async function promptPassword () { 343async function promptPassword () {
@@ -370,21 +377,21 @@ async function getAccessTokenOrDie (url: string, user: UserInfo) {
370 377
371function parseDate (dateAsStr: string): Date { 378function parseDate (dateAsStr: string): Date {
372 if (!/\d{4}-\d{2}-\d{2}/.test(dateAsStr)) { 379 if (!/\d{4}-\d{2}-\d{2}/.test(dateAsStr)) {
373 exitError(`Invalid date passed: ${dateAsStr}. Expected format: YYYY-MM-DD. See help for usage.`); 380 exitError(`Invalid date passed: ${dateAsStr}. Expected format: YYYY-MM-DD. See help for usage.`)
374 } 381 }
375 const date = new Date(dateAsStr); 382 const date = new Date(dateAsStr)
376 date.setHours(0, 0, 0); 383 date.setHours(0, 0, 0)
377 if (isNaN(date.getTime())) { 384 if (isNaN(date.getTime())) {
378 exitError(`Invalid date passed: ${dateAsStr}. See help for usage.`); 385 exitError(`Invalid date passed: ${dateAsStr}. See help for usage.`)
379 } 386 }
380 return date; 387 return date
381} 388}
382 389
383function formatDate (date: Date): string { 390function formatDate (date: Date): string {
384 return date.toISOString().split('T')[0]; 391 return date.toISOString().split('T')[ 0 ]
385} 392}
386 393
387function exitError (message:string, ...meta: any[]) { 394function exitError (message: string, ...meta: any[]) {
388 // use console.error instead of log.error here 395 // use console.error instead of log.error here
389 console.error(message, ...meta) 396 console.error(message, ...meta)
390 process.exit(-1) 397 process.exit(-1)