diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/tools/peertube-import-videos.ts | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/server/tools/peertube-import-videos.ts b/server/tools/peertube-import-videos.ts index 1f0350442..0ebfa7442 100644 --- a/server/tools/peertube-import-videos.ts +++ b/server/tools/peertube-import-videos.ts | |||
@@ -32,7 +32,9 @@ command | |||
32 | .option('-u, --url <url>', 'Server url') | 32 | .option('-u, --url <url>', 'Server url') |
33 | .option('-U, --username <username>', 'Username') | 33 | .option('-U, --username <username>', 'Username') |
34 | .option('-p, --password <token>', 'Password') | 34 | .option('-p, --password <token>', 'Password') |
35 | .option('-t, --target-url <targetUrl>', 'Video target URL') | 35 | .option('--target-url <targetUrl>', 'Video target URL') |
36 | .option('--since <since>', 'Publication date (inclusive) since which the videos can be imported (YYYY-MM-DD)', parseDate) | ||
37 | .option('--until <until>', 'Publication date (inclusive) until which the videos can be imported (YYYY-MM-DD)', parseDate) | ||
36 | .option('-v, --verbose', 'Verbose mode') | 38 | .option('-v, --verbose', 'Verbose mode') |
37 | .parse(process.argv) | 39 | .parse(process.argv) |
38 | 40 | ||
@@ -108,6 +110,21 @@ function processVideo (parameters: { | |||
108 | const videoInfo = await fetchObject(youtubeInfo) | 110 | const videoInfo = await fetchObject(youtubeInfo) |
109 | if (program[ 'verbose' ]) console.log('Fetched object.', videoInfo) | 111 | if (program[ 'verbose' ]) console.log('Fetched object.', videoInfo) |
110 | 112 | ||
113 | if (program[ 'since' ]) { | ||
114 | if (buildOriginallyPublishedAt(videoInfo).getTime() < program[ 'since' ].getTime()) { | ||
115 | console.log('Video "%s" has been published before "%s", don\'t upload it.\n', | ||
116 | videoInfo.title, formatDate(program[ 'since' ])); | ||
117 | return res(); | ||
118 | } | ||
119 | } | ||
120 | if (program[ 'until' ]) { | ||
121 | if (buildOriginallyPublishedAt(videoInfo).getTime() > program[ 'until' ].getTime()) { | ||
122 | console.log('Video "%s" has been published after "%s", don\'t upload it.\n', | ||
123 | videoInfo.title, formatDate(program[ 'until' ])); | ||
124 | return res(); | ||
125 | } | ||
126 | } | ||
127 | |||
111 | const result = await searchVideoWithSort(url, videoInfo.title, '-match') | 128 | const result = await searchVideoWithSort(url, videoInfo.title, '-match') |
112 | 129 | ||
113 | console.log('############################################################\n') | 130 | console.log('############################################################\n') |
@@ -342,3 +359,20 @@ async function getAccessTokenOrDie (url: string, user: UserInfo) { | |||
342 | process.exit(-1) | 359 | process.exit(-1) |
343 | } | 360 | } |
344 | } | 361 | } |
362 | |||
363 | function parseDate (dateAsStr: string): Date { | ||
364 | if (!/\d{4}-\d{2}-\d{2}/.test(dateAsStr)) { | ||
365 | console.error(`Invalid date passed: ${dateAsStr}. Expected format: YYYY-MM-DD. See help for usage.`); | ||
366 | process.exit(-1); | ||
367 | } | ||
368 | const date = new Date(dateAsStr); | ||
369 | if (isNaN(date.getTime())) { | ||
370 | console.error(`Invalid date passed: ${dateAsStr}. See help for usage.`); | ||
371 | process.exit(-1); | ||
372 | } | ||
373 | return date; | ||
374 | } | ||
375 | |||
376 | function formatDate (date: Date): string { | ||
377 | return date.toISOString().split('T')[0]; | ||
378 | } | ||