Skip to content

Commit

Permalink
feat: attachment metadata reader
Browse files Browse the repository at this point in the history
  • Loading branch information
twlite committed Jul 19, 2023
1 parent 5abbc51 commit c5b52c3
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 69 deletions.
2 changes: 1 addition & 1 deletion packages/extractor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@types/node": "^18.11.18",
"@types/node-fetch": "^2.6.2",
"discord-player": "workspace:^",
"mediaplex": "^0.0.0",
"mediaplex": "^0.0.1",
"play-dl": "^1.9.6",
"yt-stream": "^1.4.7",
"ytdl-core": "^4.11.4"
Expand Down
31 changes: 25 additions & 6 deletions packages/extractor/src/extractors/AttachmentExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,19 @@ export class AttachmentExtractor extends BaseExtractor {
try {
// eslint-disable-next-line
const mediaplex = require('mediaplex') as typeof import('mediaplex');
const { result, stream } = await mediaplex.probeStream(data);

const result = await mediaplex.probeStream(data);
if (result.result) trackInfo.duration = result.result.duration * 1000;
result.stream.destroy();
if (result) {
trackInfo.duration = result.duration * 1000;

const metadata = mediaplex.readMetadata(result);
if (metadata.author) trackInfo.author = metadata.author;
if (metadata.title) trackInfo.title = metadata.title;

trackInfo.description = `${trackInfo.title} by ${trackInfo.author}`;
}

stream.destroy();
} catch {
//
}
Expand Down Expand Up @@ -112,14 +121,24 @@ export class AttachmentExtractor extends BaseExtractor {
// eslint-disable-next-line
const mediaplex = require('mediaplex') as typeof import('mediaplex');

const result = await mediaplex.probeStream(
const { result, stream } = await mediaplex.probeStream(
createReadStream(query, {
start: 0,
end: 1024
})
);
if (result.result) trackInfo.duration = result.result.duration * 1000;
result.stream.destroy();

if (result) {
trackInfo.duration = result.duration * 1000;

const metadata = mediaplex.readMetadata(result);
if (metadata.author) trackInfo.author = metadata.author;
if (metadata.title) trackInfo.title = metadata.title;

trackInfo.description = `${trackInfo.title} by ${trackInfo.author}`;
}

stream.destroy();
} catch {
//
}
Expand Down
124 changes: 62 additions & 62 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ __metadata:
discord-player: "workspace:^"
file-type: ^16.5.4
genius-lyrics: ^4.4.3
mediaplex: ^0.0.0
mediaplex: ^0.0.1
node-html-parser: ^6.1.4
play-dl: ^1.9.6
reverbnation-scraper: ^2.0.0
Expand Down Expand Up @@ -7639,122 +7639,122 @@ __metadata:
languageName: node
linkType: hard

"mediaplex-android-arm-eabi@npm:0.0.0":
version: 0.0.0
resolution: "mediaplex-android-arm-eabi@npm:0.0.0"
"mediaplex-android-arm-eabi@npm:0.0.1":
version: 0.0.1
resolution: "mediaplex-android-arm-eabi@npm:0.0.1"
conditions: os=android & cpu=arm
languageName: node
linkType: hard

"mediaplex-android-arm64@npm:0.0.0":
version: 0.0.0
resolution: "mediaplex-android-arm64@npm:0.0.0"
"mediaplex-android-arm64@npm:0.0.1":
version: 0.0.1
resolution: "mediaplex-android-arm64@npm:0.0.1"
conditions: os=android & cpu=arm64
languageName: node
linkType: hard

"mediaplex-darwin-arm64@npm:0.0.0":
version: 0.0.0
resolution: "mediaplex-darwin-arm64@npm:0.0.0"
"mediaplex-darwin-arm64@npm:0.0.1":
version: 0.0.1
resolution: "mediaplex-darwin-arm64@npm:0.0.1"
conditions: os=darwin & cpu=arm64
languageName: node
linkType: hard

"mediaplex-darwin-universal@npm:0.0.0":
version: 0.0.0
resolution: "mediaplex-darwin-universal@npm:0.0.0"
"mediaplex-darwin-universal@npm:0.0.1":
version: 0.0.1
resolution: "mediaplex-darwin-universal@npm:0.0.1"
conditions: os=darwin
languageName: node
linkType: hard

"mediaplex-darwin-x64@npm:0.0.0":
version: 0.0.0
resolution: "mediaplex-darwin-x64@npm:0.0.0"
"mediaplex-darwin-x64@npm:0.0.1":
version: 0.0.1
resolution: "mediaplex-darwin-x64@npm:0.0.1"
conditions: os=darwin & cpu=x64
languageName: node
linkType: hard

"mediaplex-freebsd-x64@npm:0.0.0":
version: 0.0.0
resolution: "mediaplex-freebsd-x64@npm:0.0.0"
"mediaplex-freebsd-x64@npm:0.0.1":
version: 0.0.1
resolution: "mediaplex-freebsd-x64@npm:0.0.1"
conditions: os=freebsd & cpu=x64
languageName: node
linkType: hard

"mediaplex-linux-arm-gnueabihf@npm:0.0.0":
version: 0.0.0
resolution: "mediaplex-linux-arm-gnueabihf@npm:0.0.0"
"mediaplex-linux-arm-gnueabihf@npm:0.0.1":
version: 0.0.1
resolution: "mediaplex-linux-arm-gnueabihf@npm:0.0.1"
conditions: os=linux & cpu=arm
languageName: node
linkType: hard

"mediaplex-linux-arm64-gnu@npm:0.0.0":
version: 0.0.0
resolution: "mediaplex-linux-arm64-gnu@npm:0.0.0"
"mediaplex-linux-arm64-gnu@npm:0.0.1":
version: 0.0.1
resolution: "mediaplex-linux-arm64-gnu@npm:0.0.1"
conditions: os=linux & cpu=arm64 & libc=glibc
languageName: node
linkType: hard

"mediaplex-linux-arm64-musl@npm:0.0.0":
version: 0.0.0
resolution: "mediaplex-linux-arm64-musl@npm:0.0.0"
"mediaplex-linux-arm64-musl@npm:0.0.1":
version: 0.0.1
resolution: "mediaplex-linux-arm64-musl@npm:0.0.1"
conditions: os=linux & cpu=arm64 & libc=musl
languageName: node
linkType: hard

"mediaplex-linux-x64-gnu@npm:0.0.0":
version: 0.0.0
resolution: "mediaplex-linux-x64-gnu@npm:0.0.0"
"mediaplex-linux-x64-gnu@npm:0.0.1":
version: 0.0.1
resolution: "mediaplex-linux-x64-gnu@npm:0.0.1"
conditions: os=linux & cpu=x64 & libc=glibc
languageName: node
linkType: hard

"mediaplex-linux-x64-musl@npm:0.0.0":
version: 0.0.0
resolution: "mediaplex-linux-x64-musl@npm:0.0.0"
"mediaplex-linux-x64-musl@npm:0.0.1":
version: 0.0.1
resolution: "mediaplex-linux-x64-musl@npm:0.0.1"
conditions: os=linux & cpu=x64 & libc=musl
languageName: node
linkType: hard

"mediaplex-win32-arm64-msvc@npm:0.0.0":
version: 0.0.0
resolution: "mediaplex-win32-arm64-msvc@npm:0.0.0"
"mediaplex-win32-arm64-msvc@npm:0.0.1":
version: 0.0.1
resolution: "mediaplex-win32-arm64-msvc@npm:0.0.1"
conditions: os=win32 & cpu=arm64
languageName: node
linkType: hard

"mediaplex-win32-ia32-msvc@npm:0.0.0":
version: 0.0.0
resolution: "mediaplex-win32-ia32-msvc@npm:0.0.0"
"mediaplex-win32-ia32-msvc@npm:0.0.1":
version: 0.0.1
resolution: "mediaplex-win32-ia32-msvc@npm:0.0.1"
conditions: os=win32 & cpu=ia32
languageName: node
linkType: hard

"mediaplex-win32-x64-msvc@npm:0.0.0":
version: 0.0.0
resolution: "mediaplex-win32-x64-msvc@npm:0.0.0"
"mediaplex-win32-x64-msvc@npm:0.0.1":
version: 0.0.1
resolution: "mediaplex-win32-x64-msvc@npm:0.0.1"
conditions: os=win32 & cpu=x64
languageName: node
linkType: hard

"mediaplex@npm:^0.0.0":
version: 0.0.0
resolution: "mediaplex@npm:0.0.0"
dependencies:
mediaplex-android-arm-eabi: 0.0.0
mediaplex-android-arm64: 0.0.0
mediaplex-darwin-arm64: 0.0.0
mediaplex-darwin-universal: 0.0.0
mediaplex-darwin-x64: 0.0.0
mediaplex-freebsd-x64: 0.0.0
mediaplex-linux-arm-gnueabihf: 0.0.0
mediaplex-linux-arm64-gnu: 0.0.0
mediaplex-linux-arm64-musl: 0.0.0
mediaplex-linux-x64-gnu: 0.0.0
mediaplex-linux-x64-musl: 0.0.0
mediaplex-win32-arm64-msvc: 0.0.0
mediaplex-win32-ia32-msvc: 0.0.0
mediaplex-win32-x64-msvc: 0.0.0
"mediaplex@npm:^0.0.1":
version: 0.0.1
resolution: "mediaplex@npm:0.0.1"
dependencies:
mediaplex-android-arm-eabi: 0.0.1
mediaplex-android-arm64: 0.0.1
mediaplex-darwin-arm64: 0.0.1
mediaplex-darwin-universal: 0.0.1
mediaplex-darwin-x64: 0.0.1
mediaplex-freebsd-x64: 0.0.1
mediaplex-linux-arm-gnueabihf: 0.0.1
mediaplex-linux-arm64-gnu: 0.0.1
mediaplex-linux-arm64-musl: 0.0.1
mediaplex-linux-x64-gnu: 0.0.1
mediaplex-linux-x64-musl: 0.0.1
mediaplex-win32-arm64-msvc: 0.0.1
mediaplex-win32-ia32-msvc: 0.0.1
mediaplex-win32-x64-msvc: 0.0.1
dependenciesMeta:
mediaplex-android-arm-eabi:
optional: true
Expand Down Expand Up @@ -7784,7 +7784,7 @@ __metadata:
optional: true
mediaplex-win32-x64-msvc:
optional: true
checksum: 0387d865d069d1d8827a36d55218f29858c9948f859a36186e82ef7bb07597a919c4bb700774e703f98b779f8d46a9616dab15c09f83b1e20ecdee05d3a805a6
checksum: dd7abe43d09fdad2cc9913af8405e53a3a2dc7989987568564410625d852941b69543972994f8bf3de09f46d0f91df7e6bc6e044c9c6898be5e4a64ab6544b9b
languageName: node
linkType: hard

Expand Down

0 comments on commit c5b52c3

Please sign in to comment.