Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ytdl-core Dependency and Rebuild #1221

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ jobs:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v2
with:
node-version: '18'
cache: 'yarn'
- name: Install dependencies
run: yarn install
- name: Generate Prisma client
run: yarn prisma generate
- name: Run lint
run: yarn lint
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Generate Prisma client
run: yarn prisma generate

- name: Run lint
run: yarn lint
28 changes: 17 additions & 11 deletions .github/workflows/type-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ jobs:
name: Type Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v2
with:
node-version: '18'
cache: 'yarn'
- name: Install dependencies
run: yarn install
- name: Generate Prisma client
run: yarn prisma generate
- name: Run type check
run: yarn tsc
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Generate Prisma client
run: yarn prisma generate

- name: Run type check
run: yarn tsc
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
FROM node:18-bullseye-slim AS base
FROM node:22-bullseye-slim AS base

# openssl will be a required package if base is updated to 18.16+ due to node:*-slim base distro change
# https://github.com/prisma/prisma/issues/19729#issuecomment-1591270599
# Install ffmpeg
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
build-essential \
python3 \
python3-distutils \
python3-venv \
ffmpeg \
tini \
openssl \
Expand All @@ -13,6 +17,8 @@
&& apt-get autoremove \
&& rm -rf /var/lib/apt/lists/*

ENV PYTHON /usr/bin/python3

Check warning on line 20 in Dockerfile

View workflow job for this annotation

GitHub Actions / Build snapshot (ubuntu-latest)

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

# Install dependencies
FROM base AS dependencies

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"@discordjs/opus": "^0.8.0",
"@discordjs/rest": "1.0.1",
"@discordjs/voice": "0.17.0",
"@distube/ytdl-core": "^4.15.9",
"@distube/ytdl-core": "^4.16.2",
"@distube/ytsr": "^2.0.4",
"@prisma/client": "4.16.0",
"@types/libsodium-wrappers": "^0.7.9",
Expand Down
16 changes: 11 additions & 5 deletions src/services/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,17 +665,23 @@ export default class {
}
}

private async createReadStream(options: {url: string; cacheKey: string; ffmpegInputOptions?: string[]; cache?: boolean; volumeAdjustment?: string}): Promise<Readable> {
private async createReadStream(options: {
url: string;
cacheKey: string;
ffmpegInputOptions?: string[];
cache?: boolean;
volumeAdjustment?: string;
}): Promise<Readable> {
return new Promise((resolve, reject) => {
const capacitor = new WriteStream();
let hasReturnedStreamClosed = false;

if (options?.cache) {
const cacheStream = this.fileCache.createWriteStream(this.getHashForCache(options.cacheKey));
capacitor.createReadStream().pipe(cacheStream);
capacitor.createReadStream()?.pipe(cacheStream);
}

const returnedStream = capacitor.createReadStream();
let hasReturnedStreamClosed = false;

const stream = ffmpeg(options.url)
.inputOptions(options?.ffmpegInputOptions ?? ['-re'])
Expand All @@ -689,13 +695,13 @@ export default class {
}
})
.on('start', command => {
debug(`Spawned ffmpeg with ${command as string}`);
debug(`Spawned ffmpeg with ${command}`);
});

stream.pipe(capacitor);

returnedStream.on('close', () => {
if (!options.cache) {
if (!options?.cache) {
stream.kill('SIGKILL');
}

Expand Down
Loading