@ryuu-reinzz/haruka-lib 2.3.0-beta.1 → 2.4.0
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 +40 -0
- package/main/index.js +17 -4
- package/main/socket.js +602 -581
- package/main/sqliteAuth.js +82 -78
- package/main/sticker-engine/image-to-webp.js +46 -44
- package/main/sticker-engine/index.js +10 -3
- package/main/sticker-engine/main-sticker.js +83 -77
- package/main/sticker-engine/video-to-webp.js +56 -54
- package/package.json +30 -30
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import ffmpeg from "fluent-ffmpeg";
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import {
|
|
4
|
+
tmpdir
|
|
5
|
+
} from 'os';
|
|
6
|
+
import Crypto from 'crypto';
|
|
7
|
+
import fs from "fs-extra";
|
|
8
|
+
|
|
9
|
+
async function bufferToTmp(buffer, ext = '.bin') {
|
|
10
|
+
const tmp = path.join(
|
|
11
|
+
tmpdir(),
|
|
12
|
+
Crypto.randomBytes(6).toString('hex') + ext
|
|
13
|
+
)
|
|
14
|
+
await fs.writeFile(tmp, buffer)
|
|
15
|
+
return tmp
|
|
16
|
+
}
|
|
17
|
+
export default async function AudioToOpus(buff) {
|
|
18
|
+
const input = await bufferToTmp(buff, '.mp3')
|
|
19
|
+
const output = path.join(
|
|
20
|
+
tmpdir(),
|
|
21
|
+
Crypto.randomBytes(6).toString('hex') + '.opus'
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
await new Promise((resolve, reject) => {
|
|
25
|
+
ffmpeg(input)
|
|
26
|
+
.audioCodec('libopus')
|
|
27
|
+
.audioBitrate(128)
|
|
28
|
+
.format('opus')
|
|
29
|
+
.save(output)
|
|
30
|
+
.on('end', resolve)
|
|
31
|
+
.on('error', reject)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
const result = await fs.readFile(output)
|
|
35
|
+
|
|
36
|
+
await fs.unlink(input)
|
|
37
|
+
await fs.unlink(output)
|
|
38
|
+
|
|
39
|
+
return result
|
|
40
|
+
}
|
package/main/index.js
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import addProperty from "./socket.js";
|
|
2
2
|
import useSQLiteAuthState from "./sqliteAuth.js";
|
|
3
3
|
import Sticker from './sticker-engine/index.js';
|
|
4
|
+
import {
|
|
5
|
+
stickerVid
|
|
6
|
+
} from './sticker-engine/video-to-webp.js';
|
|
7
|
+
import {
|
|
8
|
+
stickerImg
|
|
9
|
+
} from './sticker-engine/image-to-webp.js';
|
|
10
|
+
import {
|
|
11
|
+
AudioToOpus
|
|
12
|
+
} from './audio-to-opus.js';
|
|
4
13
|
|
|
5
14
|
const haruka = {
|
|
6
|
-
|
|
7
|
-
|
|
15
|
+
addProperty,
|
|
16
|
+
useSQLiteAuthState
|
|
8
17
|
};
|
|
9
18
|
|
|
10
19
|
export default haruka;
|
|
11
|
-
|
|
12
|
-
|
|
20
|
+
export {
|
|
21
|
+
Sticker,
|
|
22
|
+
stickerVid,
|
|
23
|
+
stickerImg,
|
|
24
|
+
AudioToOpus
|
|
25
|
+
};
|