aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/peertube-import-videos.ts
diff options
context:
space:
mode:
authorFlorent F <florent.fayolle69@gmail.com>2019-08-01 10:21:55 +0200
committerChocobozzz <me@florianbigard.com>2019-08-01 10:21:55 +0200
commitd0198ff99f968739aa0c87ed4ea7553dd9796265 (patch)
tree8976ed80e613f3252d0b3b9867781d363c0dbed2 /server/tools/peertube-import-videos.ts
parent970ceac0a6bf4990b8924738591df4949491ec9b (diff)
downloadPeerTube-d0198ff99f968739aa0c87ed4ea7553dd9796265.tar.gz
PeerTube-d0198ff99f968739aa0c87ed4ea7553dd9796265.tar.zst
PeerTube-d0198ff99f968739aa0c87ed4ea7553dd9796265.zip
Add since parameter to peertube-import-videos (#1991)
* Add since parameter to peertube-import-videos * PR remarks + --until <date>
Diffstat (limited to 'server/tools/peertube-import-videos.ts')
-rw-r--r--server/tools/peertube-import-videos.ts36
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
363function 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
376function formatDate (date: Date): string {
377 return date.toISOString().split('T')[0];
378}