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

Commit

Permalink
refactor: tweak style
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Feb 18, 2021
1 parent b181227 commit 51c619e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
17 changes: 9 additions & 8 deletions lib/downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const isWin = flags.includes('--platform=windows') || require('./util').isWin
const isOverwrite = flags.includes('--overwrite')

// First, look for the download link.
let dir, filePath
let dir
let filePath
const defaultBin = path.join(__dirname, '..', 'bin')

function download (url, callback) {
Expand Down Expand Up @@ -74,13 +75,13 @@ function downloader (binDir, callback) {
// handle overwritin
if (fs.existsSync(filePath)) {
if (!isOverwrite) {
return callback('File exists')
} else {
try {
fs.unlinkSync(filePath)
} catch (e) {
callback(e)
}
return callback(new Error('File exists'))
}

try {
fs.unlinkSync(filePath)
} catch (e) {
callback(e)
}
}

Expand Down
14 changes: 11 additions & 3 deletions lib/youtube-dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ let ytdlBinary = null
const execa = universalify.fromPromise(require('execa'))

function youtubeDl (args, options, cb) {
return execa(ytdl.getYtdlBinary(), args, options, function done (err, output) {
return execa(ytdl.getYtdlBinary(), args, options, function done (
err,
output
) {
if (err) return cb(err)
return cb(null, output.stdout ? output.stdout.trim().split(/\r?\n/) : undefined)
return cb(
null,
output.stdout ? output.stdout.trim().split(/\r?\n/) : undefined
)
})
}

Expand Down Expand Up @@ -208,7 +214,9 @@ ytdl.setYtdlBinary = function setYtdlBinary (path) {
* @param {String} path
*/
ytdl.getYtdlBinary = function getYtdlBinary () {
return ytdlBinary ? ytdlBinary : path.resolve(__dirname, '..', 'bin', 'youtube-dl')
return ytdlBinary
? ytdlBinary
: path.resolve(__dirname, '..', 'bin', 'youtube-dl')
}

/**
Expand Down
10 changes: 3 additions & 7 deletions scripts/download.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
var downloader = require('../lib/downloader')

downloader().then((message) => {
console.log(message);
}).catch((err) => {
console.error(err)
});
require('../lib/downloader')()
.then(message => console.log(message))
.catch(err => console.error(err.message || err))

0 comments on commit 51c619e

Please sign in to comment.