]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
More robust import script when using since/until
authorChocobozzz <me@florianbigard.com>
Mon, 14 Dec 2020 08:40:31 +0000 (09:40 +0100)
committerChocobozzz <me@florianbigard.com>
Mon, 14 Dec 2020 08:55:30 +0000 (09:55 +0100)
server/tools/peertube-import-videos.ts

index d04ddfe06dbd69f73cc2caa4b24072b5e4001ce0..1b2c63af2628af8ffd489df5dca283811a7e80e3 100644 (file)
@@ -124,19 +124,18 @@ function processVideo (parameters: {
     const videoInfo = await fetchObject(youtubeInfo)
     log.debug('Fetched object.', videoInfo)
 
-    if (program['since']) {
-      if (buildOriginallyPublishedAt(videoInfo).getTime() < program['since'].getTime()) {
-        log.info('Video "%s" has been published before "%s", don\'t upload it.\n',
-          videoInfo.title, formatDate(program['since']))
-        return res()
-      }
+    const originallyPublishedAt = buildOriginallyPublishedAt(videoInfo)
+
+    if (program['since'] && originallyPublishedAt && originallyPublishedAt.getTime() < program['since'].getTime()) {
+      log.info('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()) {
-        log.info('Video "%s" has been published after "%s", don\'t upload it.\n',
-          videoInfo.title, formatDate(program['until']))
-        return res()
-      }
+
+    if (program['until'] && originallyPublishedAt && originallyPublishedAt.getTime() > program['until'].getTime()) {
+      log.info('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')