@ryuu-reinzz/haruka-lib 2.4.0 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/main/audio-to-opus.js
CHANGED
|
@@ -14,7 +14,7 @@ async function bufferToTmp(buffer, ext = '.bin') {
|
|
|
14
14
|
await fs.writeFile(tmp, buffer)
|
|
15
15
|
return tmp
|
|
16
16
|
}
|
|
17
|
-
export
|
|
17
|
+
export async function AudioToOpus(buff) {
|
|
18
18
|
const input = await bufferToTmp(buff, '.mp3')
|
|
19
19
|
const output = path.join(
|
|
20
20
|
tmpdir(),
|
|
@@ -6,8 +6,16 @@ import Crypto from 'crypto'
|
|
|
6
6
|
import {
|
|
7
7
|
tmpdir
|
|
8
8
|
} from 'os'
|
|
9
|
-
|
|
9
|
+
function isWebp(buffer) {
|
|
10
|
+
return (
|
|
11
|
+
buffer.slice(0, 4).toString() === 'RIFF' &&
|
|
12
|
+
buffer.slice(8, 12).toString() === 'WEBP'
|
|
13
|
+
);
|
|
14
|
+
}
|
|
10
15
|
async function videoToWebp(media) {
|
|
16
|
+
if (isWebp(media)) {
|
|
17
|
+
return media;
|
|
18
|
+
}
|
|
11
19
|
const tmpFileOut = path.join(tmpdir(), `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp`);
|
|
12
20
|
const tmpFileIn = path.join(tmpdir(), `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.mp4`);
|
|
13
21
|
fs.writeFile(tmpFileIn, media);
|