Skip to content

Commit 8786719

Browse files
authored
Merge pull request #44 from dapi/fix/ffprobe-path
Find ffprobe outside the wrapper's minimal PATH
2 parents f877212 + c320e1a commit 8786719

4 files changed

Lines changed: 28 additions & 5 deletions

File tree

‎docs/cli.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ For owner requests, `--timeout` also cancels Telegram RPCs and file uploads. Can
107107
- `--retries <n>` — retry transient network/transport failures for `send photo` (default: `2`).
108108
- `--retry-backoff` accepts either a millisecond value or `constant|linear|exponential`.
109109
- `--force-document` — send photo/video as uncompressed document. `send file` only. Without it `send file` sends `.mp4/.mov/.m4v/.webm/.mkv/.avi/.3gp` as a streamable video.
110-
- `send video` always sends a streamable video; `--width/--height/--duration` override metadata, otherwise it is read with `ffprobe` when installed. `--no-streaming` disables progressive playback.
110+
- `send video` always sends a streamable video; `--width/--height/--duration` override metadata, otherwise it is read with `ffprobe` when installed (PATH, Homebrew or `/usr/bin`; `TGCLI_FFPROBE` pins a binary). `--no-streaming` disables progressive playback.
111111

112112
## media
113113
- media download --chat <id|username> --id <msgId> [--output PATH]

‎package-lock.json‎

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

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dapi/tgcli",
3-
"version": "2.12.1",
3+
"version": "2.12.2",
44
"type": "module",
55
"description": "Telegram CLI + MCP server powered by MTProto and the official MCP SDK",
66
"main": "mcp-server.js",

‎telegram-client.js‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,33 @@ function parseVideoDimension(value, name) {
317317
// Reads width/height/duration with ffprobe when it is installed; silently returns {} otherwise.
318318
// Telegram renders a video without these fields, but with them the preview keeps its aspect
319319
// ratio and shows the duration before playback.
320+
// The tgcli wrapper runs with a minimal PATH, so look in the usual Homebrew/Linux
321+
// locations as well; TGCLI_FFPROBE pins an explicit binary.
322+
function resolveFfprobe() {
323+
const candidates = [
324+
process.env.TGCLI_FFPROBE,
325+
'ffprobe',
326+
'/opt/homebrew/bin/ffprobe',
327+
'/usr/local/bin/ffprobe',
328+
'/usr/bin/ffprobe',
329+
].filter(Boolean);
330+
for (const candidate of candidates) {
331+
if (candidate === 'ffprobe') {
332+
const check = spawnSync('ffprobe', ['-version'], { stdio: 'ignore', timeout: 5_000 });
333+
if (check.status === 0) return candidate;
334+
continue;
335+
}
336+
if (fs.existsSync(candidate)) return candidate;
337+
}
338+
return null;
339+
}
340+
320341
function probeVideoMetadata(filePath) {
321342
if (process.env.TGCLI_DISABLE_FFPROBE === '1') return {};
343+
const ffprobe = resolveFfprobe();
344+
if (!ffprobe) return {};
322345
try {
323-
const probe = spawnSync('ffprobe', [
346+
const probe = spawnSync(ffprobe, [
324347
'-v', 'error',
325348
'-select_streams', 'v:0',
326349
'-show_entries', 'stream=width,height:format=duration',

0 commit comments

Comments
 (0)