@boruto_vk7/opus-ogg 1.2.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/LICENSE +21 -0
- package/README.md +92 -0
- package/dist/cjs/index.js +177 -0
- package/dist/cjs/oggDemuxer.js +169 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/src/index.js +177 -0
- package/dist/cjs/src/oggDemuxer.js +169 -0
- package/dist/esm/index.js +139 -0
- package/dist/esm/oggDemuxer.js +165 -0
- package/dist/esm/package.json +1 -0
- package/dist/types/index.d.ts +29 -0
- package/dist/types/oggDemuxer.d.ts +19 -0
- package/dist/types/src/index.d.ts +29 -0
- package/dist/types/src/oggDemuxer.d.ts +19 -0
- package/package.json +39 -0
- package/scripts/install-ffmpeg.js +97 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const https = require('https');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const { execSync } = require('child_process');
|
|
6
|
+
|
|
7
|
+
const BIN_DIR = path.resolve(__dirname, '../bin');
|
|
8
|
+
const FFmpeg_BIN = path.join(BIN_DIR, os.platform() === 'win32' ? 'ffmpeg.exe' : 'ffmpeg');
|
|
9
|
+
|
|
10
|
+
// URLs for static binaries (using BtbN and other reliable sources)
|
|
11
|
+
const BINARIES = {
|
|
12
|
+
'linux-x64': 'https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz',
|
|
13
|
+
'linux-arm64': 'https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linuxarm64-gpl.tar.xz',
|
|
14
|
+
'win32-x64': 'https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip',
|
|
15
|
+
'darwin-x64': 'https://github.com/eugeneware/ffmpeg-static/releases/download/b5.0.1/darwin-x64',
|
|
16
|
+
'darwin-arm64': 'https://github.com/eugeneware/ffmpeg-static/releases/download/b5.0.1/darwin-arm64'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
async function download(url, dest) {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const file = fs.createWriteStream(dest);
|
|
22
|
+
https.get(url, { headers: { 'User-Agent': 'NodeJS' } }, res => {
|
|
23
|
+
if (res.statusCode === 302 || res.statusCode === 301) {
|
|
24
|
+
return download(res.headers.location, dest).then(resolve).catch(reject);
|
|
25
|
+
}
|
|
26
|
+
if (res.statusCode !== 200) return reject(new Error(`HTTP ${res.statusCode}`));
|
|
27
|
+
res.pipe(file);
|
|
28
|
+
file.on('finish', () => { file.close(); resolve(); });
|
|
29
|
+
}).on('error', reject);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function install() {
|
|
34
|
+
const isTermux = process.env.PREFIX === '/data/data/com.termux/files/usr' || fs.existsSync('/data/data/com.termux/files/usr/bin/ffmpeg');
|
|
35
|
+
|
|
36
|
+
if (isTermux) {
|
|
37
|
+
console.log('[@boruto_vk7/opus-ogg] Termux detected. Please use system FFmpeg: "pkg install ffmpeg"');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (fs.existsSync(FFmpeg_BIN)) {
|
|
42
|
+
console.log('[@boruto_vk7/opus-ogg] FFmpeg already installed.');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const platform = os.platform();
|
|
47
|
+
const arch = os.arch();
|
|
48
|
+
const key = `${platform}-${arch}`;
|
|
49
|
+
const url = BINARIES[key];
|
|
50
|
+
|
|
51
|
+
if (!url) {
|
|
52
|
+
console.log(`[@boruto_vk7/opus-ogg] No pre-built binary for ${key}. Falling back to system ffmpeg.`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!fs.existsSync(BIN_DIR)) fs.mkdirSync(BIN_DIR, { recursive: true });
|
|
57
|
+
|
|
58
|
+
console.log(`[@boruto_vk7/opus-ogg] Downloading FFmpeg for ${key}...`);
|
|
59
|
+
const tempFile = path.join(BIN_DIR, 'ffmpeg-temp' + (url.endsWith('.zip') ? '.zip' : url.endsWith('.xz') ? '.tar.xz' : ''));
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
await download(url, tempFile);
|
|
63
|
+
|
|
64
|
+
// Extraction logic based on file type
|
|
65
|
+
if (url.endsWith('.zip')) {
|
|
66
|
+
console.log('[@boruto_vk7/opus-ogg] Extracting ZIP...');
|
|
67
|
+
try {
|
|
68
|
+
execSync(`unzip -o ${tempFile} -d ${BIN_DIR}`);
|
|
69
|
+
// Find ffmpeg.exe in subfolders and move to root
|
|
70
|
+
const found = execSync(`find ${BIN_DIR} -name ffmpeg.exe`).toString().trim();
|
|
71
|
+
if (found && found !== FFmpeg_BIN) fs.renameSync(found, FFmpeg_BIN);
|
|
72
|
+
} catch { console.error('Failed to unzip. Please install unzip.'); }
|
|
73
|
+
} else if (url.endsWith('.tar.xz')) {
|
|
74
|
+
console.log('[@boruto_vk7/opus-ogg] Extracting TAR.XZ...');
|
|
75
|
+
try {
|
|
76
|
+
execSync(`tar -xJf ${tempFile} -C ${BIN_DIR} --strip-components=1`);
|
|
77
|
+
// After strip-components=1, the binary might be in bin/ffmpeg
|
|
78
|
+
const internalBin = path.join(BIN_DIR, 'bin', 'ffmpeg');
|
|
79
|
+
if (fs.existsSync(internalBin)) {
|
|
80
|
+
fs.renameSync(internalBin, FFmpeg_BIN);
|
|
81
|
+
}
|
|
82
|
+
} catch { console.error('Failed to extract tar.xz. Please install tar.'); }
|
|
83
|
+
} else {
|
|
84
|
+
// Direct binary
|
|
85
|
+
fs.renameSync(tempFile, FFmpeg_BIN);
|
|
86
|
+
fs.chmodSync(FFmpeg_BIN, 0o755);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
console.log('[@boruto_vk7/opus-ogg] FFmpeg installed successfully.');
|
|
90
|
+
} catch (err) {
|
|
91
|
+
console.error(`[@boruto_vk7/opus-ogg] Download failed: ${err.message}`);
|
|
92
|
+
} finally {
|
|
93
|
+
if (fs.existsSync(tempFile)) fs.unlinkSync(tempFile);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
install();
|