Skip to content

Commit

Permalink
Merge pull request #299 from manuel-rw/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rw authored May 31, 2024
2 parents 649742b + cd52f70 commit 1ec10f9
Show file tree
Hide file tree
Showing 6 changed files with 549 additions and 660 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16.13.1-alpine3.12
FROM node:18-alpine
RUN apk add ffmpeg

COPY . /app
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jellyfin-discord-music-bot",
"version": "0.1.1",
"version": "1.0.0",
"description": "A simple and leightweight Discord Bot, that integrates with your Jellyfin Media server and enables you to listen to your favourite music directly from discord.",
"author": "manuel-rw",
"private": true,
Expand All @@ -22,25 +22,25 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@discord-nestjs/common": "^5.2.8",
"@discord-nestjs/common": "^5.2.12",
"@discord-nestjs/core": "^5.3.10",
"@discordjs/opus": "^0.9.0",
"@discordjs/voice": "^0.16.0",
"@discordjs/voice": "^0.17.0",
"@jellyfin/sdk": "^0.7.0",
"@nestjs/common": "^9.4.0",
"@nestjs/config": "^3.0.0",
"@nestjs/core": "^9.4.0",
"@nestjs/event-emitter": "^2.0.3",
"@nestjs/platform-express": "^9.4.2",
"@nestjs/schedule": "^4.0.0",
"@nestjs/serve-static": "^4.0.0",
"@nestjs/serve-static": "^4.0.2",
"@nestjs/terminus": "^9.2.2",
"date-fns": "^2.30.0",
"discord.js": "^14.11.0",
"joi": "^17.9.2",
"discord.js": "^14.15.2",
"joi": "^17.12.3",
"libsodium-wrappers": "^0.7.10",
"opusscript": "^0.1.1",
"reflect-metadata": "^0.1.13",
"reflect-metadata": "^0.1.14",
"rimraf": "^5.0.1",
"rxjs": "^7.8.1",
"uuid": "^9.0.0",
Expand All @@ -49,19 +49,19 @@
"zod-validation-error": "^2.1.0"
},
"devDependencies": {
"@nestjs/cli": "^9.4.2",
"@nestjs/schematics": "^10.0.1",
"@nestjs/cli": "^10.3.2",
"@nestjs/schematics": "^10.1.1",
"@nestjs/testing": "^9.4.0",
"@types/cron": "^2.0.1",
"@types/express": "^4.17.13",
"@types/jest": "29.5.11",
"@types/node": "^20.10.6",
"@types/node": "^20.11.0",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"eslint": "^8.56.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-prettier": "^5.1.3",
"jest": "29.7.0",
"prettier": "^3.0.2",
"source-map-support": "^0.5.20",
Expand Down
43 changes: 18 additions & 25 deletions src/clients/discord/discord.voice.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class DiscordVoiceService {
}
this.voiceConnection?.on(VoiceConnectionStatus.Disconnected, () => {
if (this.voiceConnection !== undefined) {
const playlist = this.playbackService.getPlaylistOrDefault().clear();
this.playbackService.getPlaylistOrDefault().clear();
this.disconnect();
}
});
Expand All @@ -122,11 +122,17 @@ export class DiscordVoiceService {
playResource(resource: AudioResource<unknown>) {
this.logger.debug(
`Playing audio resource with volume ${
resource.volume?.volume ?? 'unknown'
}`,
resource.volume?.volume
} (${resource.playbackDuration}) (readable: ${resource.readable}) (volume: ${resource.volume?.volume} (${resource.volume?.volumeDecibels}dB)) (silence remaining: ${resource.silenceRemaining}) (silence padding frames: ${resource.silencePaddingFrames}) (metadata: ${resource.metadata})`,
);
this.createAndReturnOrGetAudioPlayer().play(resource);
this.audioResource = resource;

const isPlayable = this.audioPlayer?.checkPlayable();
if (isPlayable) {
return;
}
this.logger.warn(`Current resource is is not playable. This means playback will get stuck. Please report this issue.`)
}

/**
Expand Down Expand Up @@ -179,14 +185,6 @@ export class DiscordVoiceService {
);
}

/**
* Gets the current audio player status
* @returns The current audio player status
*/
getPlayerStatus(): AudioPlayerStatus {
return this.createAndReturnOrGetAudioPlayer().state.status;
}

/**
* Checks if the current state is paused or not and toggles the states to the opposite.
* @returns The new paused state - true: paused, false: unpaused
Expand Down Expand Up @@ -280,25 +278,22 @@ export class DiscordVoiceService {
}

this.voiceConnection.on('debug', (message) => {
if (process.env.DEBUG?.toLowerCase() !== 'true') {
return;
}
this.logger.debug(message);
this.logger.debug('Voice connection debug', message);
});
this.voiceConnection.on('error', (err) => {
this.logger.error(`Voice connection error: ${err}`);
this.logger.error('Voice connection error', err);
});

this.audioPlayer.on('debug', (message) => {
this.logger.debug(message);
this.logger.debug('Audio player debug', message);
});
this.audioPlayer.on('error', (message) => {
this.logger.error(message);
this.logger.error('Audio player error', message);
});
this.audioPlayer.on('stateChange', (previousState) => {
if (!this.audioPlayer) {
this.logger.error(
"Unable to process state change from audio player, because the current audio player in the callback was undefined",
'Unable to process state change from audio player, because the current audio player in the callback was undefined',
);
return;
}
Expand Down Expand Up @@ -346,13 +341,11 @@ export class DiscordVoiceService {
return;
}

const progress = this.audioResource.playbackDuration;

const playlist = this.playbackService.getPlaylistOrDefault();

if (!playlist) {
this.logger.error(
"Failed to update ellapsed audio time because playlist was unexpectitly undefined",
'Failed to update elapsed audio time because playlist was unexpectedly undefined',
);
return;
}
Expand All @@ -363,9 +356,9 @@ export class DiscordVoiceService {
return;
}

activeTrack.updatePlaybackProgress(progress);
this.logger.verbose(
`Reporting progress: ${progress} on track ${activeTrack.id}`,
activeTrack.updatePlaybackProgress(this.audioResource.playbackDuration);
this.logger.debug(
`Reporting progress: ${this.audioResource.playbackDuration} on track ${activeTrack.id} (ended: ${this.audioResource.ended}) (started: ${this.audioResource.started}) (silence remaining: ${this.audioResource.silenceRemaining})`,
);
}
}
9 changes: 9 additions & 0 deletions src/clients/jellyfin/jellyfin.stream.builder.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ export class JellyfinStreamBuilderService {
this.jellyfinService.getJellyfin().clientInfo.name,
);
url.searchParams.set('MaxStreamingBitrate', `${bitrate}`);
/*
url.searchParams.set(
'Container',
'opus,webm|opus,mp3,aac,m4a|aac,m4b|aac,flac,webma,webm|webma,wav,ogg',
);
url.searchParams.set('AudioCodec', 'aac');
url.searchParams.set('TranscodingContainer', 'mp4');
*/

url.searchParams.set('Container', 'ogg,opus');
url.searchParams.set('AudioCodec', 'opus');
url.searchParams.set('TranscodingContainer', 'ts');
Expand Down
6 changes: 3 additions & 3 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const Constants = {
Metadata: {
Version: {
Major: 0,
Minor: 1,
Patch: 1,
Major: 1,
Minor: 0,
Patch: 0,
All: () =>
`${Constants.Metadata.Version.Major}.${Constants.Metadata.Version.Minor}.${Constants.Metadata.Version.Patch}`,
},
Expand Down
Loading

0 comments on commit 1ec10f9

Please sign in to comment.