fix #456 catching errors in import-videos (#457)
authormemorybox <memoryboxes@gmail.com>
Mon, 2 Apr 2018 18:28:25 +0000 (02:28 +0800)
committerRigel Kent <par@rigelk.eu>
Mon, 2 Apr 2018 18:28:25 +0000 (20:28 +0200)
server/tools/import-videos.ts

index 809d69e4c6cfb6ce8ce74dbd804d0319c2d59291..2f38ea7c77e9f079db666035fd5cafe365f80b71 100644 (file)
@@ -76,7 +76,6 @@ async function run () {
       await processVideo(info, program['language'])
     }
 
-    // https://www.youtube.com/watch?v=2Upx39TBc1s
     console.log('I\'m finished!')
     process.exit(0)
   })
@@ -103,15 +102,21 @@ function processVideo (info: any, languageCode: number) {
     console.log('Downloading video "%s"...', videoInfo.title)
 
     const options = [ '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best', '-o', path ]
-    youtubeDL.exec(videoInfo.url, options, processOptions, async (err, output) => {
-      if (err) return console.error(err)
-
-      console.log(output.join('\n'))
-
-      await uploadVideoOnPeerTube(normalizeObject(videoInfo), path, languageCode)
-
+    try {
+      youtubeDL.exec(videoInfo.url, options, processOptions, async (err, output) => {
+        if (err) {
+          console.error(err)
+          return res()
+        }
+
+        console.log(output.join('\n'))
+        await uploadVideoOnPeerTube(normalizeObject(videoInfo), path, languageCode)
+        return res()
+      })
+    } catch (err) {
+      console.log(err.message)
       return res()
-    })
+    }
   })
 }