Skip to content

Commit

Permalink
Add ffmpegPath option (#1933)
Browse files Browse the repository at this point in the history
* Add ffmpegPath option

* Reorder ffmpegPath option to the top

* Test for ffmpeg

* Add: ffmpeg tests

* Remove useless imports
  • Loading branch information
retrouser955 authored Aug 4, 2024
1 parent 5a5da80 commit 5760b85
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/discord-player/__test__/Player.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterEach, describe, expect, it } from 'vitest';
import { afterEach, describe, expect, it, test } from 'vitest';
import { Player, SearchResult } from '../src/index';
import { Client, IntentsBitField } from 'discord.js';

Expand Down Expand Up @@ -38,4 +38,14 @@ describe('Player', () => {

expect(response).toBeInstanceOf(SearchResult);
});

test("should set process.env.FFMPEG_PATH to given path", () => {
// not actual ffmpeg path. just dummy
new Player(client, {
ffmpegPath: "./packages/ffmpeg",
ignoreInstance: true
})

expect(process.env.FFMPEG_PATH).toBe("./packages/ffmpeg")
})
});
6 changes: 6 additions & 0 deletions packages/discord-player/src/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ export class Player extends PlayerEventsEmitter<PlayerEvents> {

super([PlayerEvent.Error]);

if(options.ffmpegPath) {
if(typeof options.ffmpegPath !== "string") throw new TypeError(`Expected type "string" for options.ffmpegPath. Got ${typeof options.ffmpegPath} instead`)

process.env.FFMPEG_PATH = options.ffmpegPath
}

/**
* The discord.js client
* @type {Client}
Expand Down
4 changes: 4 additions & 0 deletions packages/discord-player/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,4 +531,8 @@ export interface PlayerInitOptions {
* The probe timeout in milliseconds. Defaults to 5000.
*/
probeTimeout?: number;
/**
* Configure ffmpeg path
*/
ffmpegPath?: string;
}

0 comments on commit 5760b85

Please sign in to comment.