Correctly fix subtitles import
authorChocobozzz <me@florianbigard.com>
Wed, 17 Jun 2020 07:42:00 +0000 (09:42 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 17 Jun 2020 07:42:00 +0000 (09:42 +0200)
server/helpers/youtube-dl.ts

index 2014aab0a486ae5f0007bbb35c638594e6f6a95c..bb593095205223d0f618ddcc8ef88b5d6c7b16f5 100644 (file)
@@ -67,17 +67,16 @@ function getYoutubeDLSubs (url: string, opts?: object): Promise<YoutubeDLSubs> {
 
           const subtitles = files.reduce((acc, filename) => {
             const matched = filename.match(/\.([a-z]{2})\.(vtt|ttml)/i)
-
-            if (matched[1]) {
-              return [
-                ...acc,
-                {
-                  language: matched[1],
-                  path: join(cwd, filename),
-                  filename
-                }
-              ]
-            }
+            if (!matched || !matched[1]) return acc
+
+            return [
+              ...acc,
+              {
+                language: matched[1],
+                path: join(cwd, filename),
+                filename
+              }
+            ]
           }, [])
 
           return res(subtitles)