Skip to content

Commit c302b9d

Browse files
feat: update function (#267)
1 parent 3443b2a commit c302b9d

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ setTimeout(subprocess.cancel, 30000)
181181

182182
It creates a `yt-dlp` using the `binaryPath` provided.
183183

184+
### youtubedl.update(binaryPath)
185+
186+
Updates the `yt-dlp` executable at the provided path. If not path is provided, the default instance will be updated.
187+
184188
## Environment variables
185189

186190
The environment variables are used to customize the [postinstall script](https://github.com/microlinkhq/youtube-dl-exec/blob/master/scripts/postinstall.js) behavior that will be triggered after `npm install` is performed.

src/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,11 @@ export type Flags = {
445445

446446
export type Exec = (url: string, flags?: Flags, options?: SpawnOptions) => TinyspawnPromise
447447
export type Create = (binaryPath: string) => { (url: string, flags?: Flags, options?: SpawnOptions): Promise<Payload>; exec: Exec }
448+
export type Update = (binaryPath: string) => TinyspawnPromise
448449
export const youtubeDl: ((...args: Parameters<Exec>) => Promise<Payload | string>) & { exec: Exec, create: Create }
449450

450451
export function exec(...args: Parameters<Exec>): ReturnType<Exec>
451452
export function create(...args: Parameters<Create>): ReturnType<Create>
453+
export function update(...args: Parameters<Update>): ReturnType<Update>
452454

453455
export default youtubeDl

src/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict'
22

3+
const { dirname, basename } = require('node:path')
4+
35
const dargs = require('dargs')
46
const $ = require('tinyspawn')
57

@@ -24,11 +26,16 @@ const create = binaryPath => {
2426
return fn
2527
}
2628

29+
const update = (binaryPath = constants.YOUTUBE_DL_PATH) => {
30+
return $(basename(binaryPath), ['-U'], { cwd: dirname(binaryPath) })
31+
}
32+
2733
const defaultInstance = create(constants.YOUTUBE_DL_PATH)
2834

2935
module.exports = defaultInstance
3036
module.exports.youtubeDl = defaultInstance
3137
module.exports.create = create
38+
module.exports.update = update
3239
module.exports.args = args
3340
module.exports.isJSON = isJSON
3441
module.exports.constants = constants

0 commit comments

Comments
 (0)