aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/youtube-dl.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/youtube-dl.ts')
-rw-r--r--server/helpers/youtube-dl.ts22
1 files changed, 19 insertions, 3 deletions
diff --git a/server/helpers/youtube-dl.ts b/server/helpers/youtube-dl.ts
index 77986f407..0afc54fd2 100644
--- a/server/helpers/youtube-dl.ts
+++ b/server/helpers/youtube-dl.ts
@@ -1,8 +1,8 @@
1import * as youtubeDL from 'youtube-dl'
2import { truncate } from 'lodash' 1import { truncate } from 'lodash'
3import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES } from '../initializers' 2import { CONSTRAINTS_FIELDS, VIDEO_CATEGORIES } from '../initializers'
4import { logger } from './logger' 3import { logger } from './logger'
5import { generateVideoTmpPath } from './utils' 4import { generateVideoTmpPath } from './utils'
5import { YoutubeDlUpdateScheduler } from '../lib/schedulers/youtube-dl-update-scheduler'
6 6
7export type YoutubeDLInfo = { 7export type YoutubeDLInfo = {
8 name?: string 8 name?: string
@@ -15,9 +15,10 @@ export type YoutubeDLInfo = {
15} 15}
16 16
17function getYoutubeDLInfo (url: string): Promise<YoutubeDLInfo> { 17function getYoutubeDLInfo (url: string): Promise<YoutubeDLInfo> {
18 return new Promise<YoutubeDLInfo>((res, rej) => { 18 return new Promise<YoutubeDLInfo>(async (res, rej) => {
19 const options = [ '-j', '--flat-playlist' ] 19 const options = [ '-j', '--flat-playlist' ]
20 20
21 const youtubeDL = await safeGetYoutubeDL()
21 youtubeDL.getInfo(url, options, (err, info) => { 22 youtubeDL.getInfo(url, options, (err, info) => {
22 if (err) return rej(err) 23 if (err) return rej(err)
23 24
@@ -35,7 +36,8 @@ function downloadYoutubeDLVideo (url: string) {
35 36
36 const options = [ '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best', '-o', path ] 37 const options = [ '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best', '-o', path ]
37 38
38 return new Promise<string>((res, rej) => { 39 return new Promise<string>(async (res, rej) => {
40 const youtubeDL = await safeGetYoutubeDL()
39 youtubeDL.exec(url, options, async (err, output) => { 41 youtubeDL.exec(url, options, async (err, output) => {
40 if (err) return rej(err) 42 if (err) return rej(err)
41 43
@@ -53,6 +55,20 @@ export {
53 55
54// --------------------------------------------------------------------------- 56// ---------------------------------------------------------------------------
55 57
58async function safeGetYoutubeDL () {
59 let youtubeDL
60
61 try {
62 youtubeDL = require('youtube-dl')
63 } catch (e) {
64 // Download binary
65 await YoutubeDlUpdateScheduler.Instance.execute()
66 youtubeDL = require('youtube-dl')
67 }
68
69 return youtubeDL
70}
71
56function normalizeObject (obj: any) { 72function normalizeObject (obj: any) {
57 const newObj: any = {} 73 const newObj: any = {}
58 74