Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
Better process spawn (#265)
Browse files Browse the repository at this point in the history
Better process spawn
  • Loading branch information
Kikobeats authored Oct 29, 2019
2 parents 140f8fc + 8fb0e20 commit 2341826
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
26 changes: 12 additions & 14 deletions lib/youtube-dl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { execFile } = require('child_process')
const universalify = require('universalify')
const streamify = require('streamify')
const request = require('request')
const hms = require('hh-mm-ss')
Expand All @@ -17,20 +17,13 @@ const {

let ytdlBinary = require('./get-binary')()

const TEN_MEGABYTES = 1000 * 1000 * 10

const execFileOpts = { maxBuffer: TEN_MEGABYTES }
const execa = universalify.fromPromise(require('execa'))

function youtubeDl (args, options, cb) {
return execFile(
ytdlBinary,
args,
{ ...execFileOpts, ...options },
function done (err, stdout, stderr) {
if (err) return cb(err)
return cb(null, stdout.trim().split(/\r?\n/))
}
)
return execa(ytdlBinary, args, options, function done (err, output) {
if (err) return cb(err)
return cb(null, output.stdout.trim().split(/\r?\n/))
})
}

/**
Expand All @@ -54,7 +47,12 @@ function processData (data, options, stream) {
headers.Range = 'bytes=' + options.start + '-' + options.end
}

const req = request({ url: item.url, headers: headers, ecdhCurve: 'auto', timeout: 30000 })
const req = request({
url: item.url,
headers: headers,
ecdhCurve: 'auto',
timeout: 30000
})

req.on('response', function response (res) {
const size = parseInt(res.headers['content-length'], 10)
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@
"youtube"
],
"dependencies": {
"execa": "~3.2.0",
"hh-mm-ss": "~1.2.0",
"mkdirp": "~0.5.1",
"request": "~2.88.0",
"streamify": "~0.2.9"
"streamify": "~0.2.9",
"universalify": "~0.1.2"
},
"devDependencies": {
"@commitlint/cli": "latest",
Expand Down

1 comment on commit 2341826

@EthanSK
Copy link

@EthanSK EthanSK commented on 2341826 Dec 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks it when using electron and asar unpack. Please go back to using execFile, or allow us to update the path to youtube-dl.

Please sign in to comment.