From: Florent F Date: Thu, 1 Aug 2019 08:21:55 +0000 (+0200) Subject: Add since parameter to peertube-import-videos (#1991) X-Git-Tag: v1.4.0-rc.1~40 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=d0198ff99f968739aa0c87ed4ea7553dd9796265;p=github%2FChocobozzz%2FPeerTube.git Add since parameter to peertube-import-videos (#1991) * Add since parameter to peertube-import-videos * PR remarks + --until --- 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 .option('-u, --url ', 'Server url') .option('-U, --username ', 'Username') .option('-p, --password ', 'Password') - .option('-t, --target-url ', 'Video target URL') + .option('--target-url ', 'Video target URL') + .option('--since ', 'Publication date (inclusive) since which the videos can be imported (YYYY-MM-DD)', parseDate) + .option('--until ', 'Publication date (inclusive) until which the videos can be imported (YYYY-MM-DD)', parseDate) .option('-v, --verbose', 'Verbose mode') .parse(process.argv) @@ -108,6 +110,21 @@ function processVideo (parameters: { const videoInfo = await fetchObject(youtubeInfo) if (program[ 'verbose' ]) console.log('Fetched object.', videoInfo) + if (program[ 'since' ]) { + if (buildOriginallyPublishedAt(videoInfo).getTime() < program[ 'since' ].getTime()) { + console.log('Video "%s" has been published before "%s", don\'t upload it.\n', + videoInfo.title, formatDate(program[ 'since' ])); + return res(); + } + } + if (program[ 'until' ]) { + if (buildOriginallyPublishedAt(videoInfo).getTime() > program[ 'until' ].getTime()) { + console.log('Video "%s" has been published after "%s", don\'t upload it.\n', + videoInfo.title, formatDate(program[ 'until' ])); + return res(); + } + } + const result = await searchVideoWithSort(url, videoInfo.title, '-match') console.log('############################################################\n') @@ -342,3 +359,20 @@ async function getAccessTokenOrDie (url: string, user: UserInfo) { process.exit(-1) } } + +function parseDate (dateAsStr: string): Date { + if (!/\d{4}-\d{2}-\d{2}/.test(dateAsStr)) { + console.error(`Invalid date passed: ${dateAsStr}. Expected format: YYYY-MM-DD. See help for usage.`); + process.exit(-1); + } + const date = new Date(dateAsStr); + if (isNaN(date.getTime())) { + console.error(`Invalid date passed: ${dateAsStr}. See help for usage.`); + process.exit(-1); + } + return date; +} + +function formatDate (date: Date): string { + return date.toISOString().split('T')[0]; +}