aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/youtube-dl.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/server/helpers/youtube-dl.ts b/server/helpers/youtube-dl.ts
index 07c85797a..277422645 100644
--- a/server/helpers/youtube-dl.ts
+++ b/server/helpers/youtube-dl.ts
@@ -20,6 +20,12 @@ export type YoutubeDLInfo = {
20 originallyPublishedAt?: Date 20 originallyPublishedAt?: Date
21} 21}
22 22
23export type YoutubeDLSubs = {
24 language: string,
25 filename: string,
26 path: string
27}[]
28
23const processOptions = { 29const processOptions = {
24 maxBuffer: 1024 * 1024 * 10 // 10MB 30 maxBuffer: 1024 * 1024 * 10 // 10MB
25} 31}
@@ -45,6 +51,35 @@ function getYoutubeDLInfo (url: string, opts?: string[]): Promise<YoutubeDLInfo>
45 }) 51 })
46} 52}
47 53
54function getYoutubeDLSubs (url: string, opts?: object): Promise<YoutubeDLSubs> {
55 return new Promise<YoutubeDLSubs>((res, rej) => {
56 const cwd = CONFIG.STORAGE.TMP_DIR
57 const options = opts || { all: true, format: 'vtt', cwd }
58
59 safeGetYoutubeDL()
60 .then(youtubeDL => {
61 youtubeDL.getSubs(url, options, (err, files) => {
62 if (err) return rej(err)
63
64 const subtitles = files.reduce((acc, filename) => {
65 const matched = filename.match(/\.([a-z]{2})\.(vtt|ttml)/i)
66
67 if (matched[1]) {
68 return [...acc, {
69 language: matched[1],
70 path: join(cwd, filename),
71 filename
72 }]
73 }
74 }, [])
75
76 return res(subtitles)
77 })
78 })
79 .catch(err => rej(err))
80 })
81}
82
48function downloadYoutubeDLVideo (url: string, extension: string, timeout: number) { 83function downloadYoutubeDLVideo (url: string, extension: string, timeout: number) {
49 const path = generateVideoImportTmpPath(url, extension) 84 const path = generateVideoImportTmpPath(url, extension)
50 let timer 85 let timer
@@ -185,6 +220,7 @@ function buildOriginallyPublishedAt (obj: any) {
185export { 220export {
186 updateYoutubeDLBinary, 221 updateYoutubeDLBinary,
187 downloadYoutubeDLVideo, 222 downloadYoutubeDLVideo,
223 getYoutubeDLSubs,
188 getYoutubeDLInfo, 224 getYoutubeDLInfo,
189 safeGetYoutubeDL, 225 safeGetYoutubeDL,
190 buildOriginallyPublishedAt 226 buildOriginallyPublishedAt