aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-16 09:45:51 +0200
committerChocobozzz <me@florianbigard.com>2018-08-16 09:45:51 +0200
commit4f1f6f038389ce9cdf0c77dfccdc63efc6948101 (patch)
tree8b00e3fedc2590613c1ad66a92dc7b394b03590a /server/helpers
parent8569a870e4cd662026dbf3f439c0bb460262b2b1 (diff)
downloadPeerTube-4f1f6f038389ce9cdf0c77dfccdc63efc6948101.tar.gz
PeerTube-4f1f6f038389ce9cdf0c77dfccdc63efc6948101.tar.zst
PeerTube-4f1f6f038389ce9cdf0c77dfccdc63efc6948101.zip
Ensure youtubedl binary exists in ydl helper
Diffstat (limited to 'server/helpers')
-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