Skip to content
This repository was archived by the owner on May 2, 2026. It is now read-only.

Commit 6bd8d22

Browse files
committed
feat(dependencies): add @distube/ytdl-core for YouTube video duration retrieval
1 parent b528a77 commit 6bd8d22

5 files changed

Lines changed: 105 additions & 8 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"typescript": "5.3.3"
4040
},
4141
"dependencies": {
42+
"@distube/ytdl-core": "^4.16.12",
4243
"@gquittet/graceful-server": "^4.0.8",
4344
"@prisma/client": "^5.10.2",
4445
"@socket.io/postgres-emitter": "^0.1.0",

pnpm-lock.yaml

Lines changed: 94 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/messages/sendCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const sendCommand = () => ({
3737
mediaContentType = additionalContent.contentType;
3838
}
3939

40-
if ((mediaContentType === undefined || mediaDuration === null) && additionalContent?.mediaDuration) {
40+
if ((mediaDuration === undefined || mediaDuration === null) && additionalContent?.mediaDuration) {
4141
mediaDuration = additionalContent.mediaDuration;
4242
}
4343

src/services/content-utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fetch from 'node-fetch';
22
import { getVideoDurationInSeconds } from 'get-video-duration';
33
import { fileTypeFromBuffer } from 'file-type';
44
import mime from 'mime-types';
5+
import ytdl from '@distube/ytdl-core';
56

67
function getFileTypeWithRegex(url) {
78
const regex = /(?:\.([^.]+))?$/; // Regular expression to capture file extension
@@ -46,5 +47,12 @@ export const getContentInformationsFromUrl = async (url: string) => {
4647
mediaDuration = await getVideoDurationInSeconds(url, 'ffprobe');
4748
} catch (error) {}
4849

50+
//if it is a youtube video, get the duration from the url
51+
if (url.includes('youtube.com') || url.includes('youtu.be')) {
52+
const info = await ytdl.getInfo(url);
53+
mediaDuration = info.videoDetails.lengthSeconds;
54+
contentType = 'video/mp4';
55+
}
56+
4957
return { contentType, mediaDuration };
5058
};

src/services/i18n/fr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const frLang: typeof enLang = {
6363

6464
setDefaultTimeCommand: 'config-defaut',
6565
setDefaultTimeCommandDescription:
66-
"Définir le temps par défaut pour l'affichage (Par défaut : 5 seconds) (En secondes) | 0 remet la valeur par défaut",
66+
"Définir le temps par défaut pour l'affichage (Par défaut : 5 seconds) (En secondes)",
6767
setDefaultTimeCommandOptionText: 'nombre',
6868
setDefaultTimeCommandOptionTextDescription: 'Nombre de seconds',
6969
setDefaultTimeCommandAnswer: 'Le temps par défaut défini !',

0 commit comments

Comments
 (0)