Files
MichilisandClaude Fable 5.2 3b361c17a1 Phase 1: core bot
Link in, card, download, send, in private chats and groups.

- cmd/core with an embedded download worker
- Telegram front end on telego v1.13.0 (Bot API 10.4): link card with
  thumbnail and format buttons, one live status message, /dl /audio /thumb
  /info /queue /cancel, group support with requester-only buttons
- Database backed queue: paid and free lanes, leases with heartbeats, one
  automatic retry, cancel, queue position and wait estimate
- yt-dlp and ffprobe behind a Runner interface with classified, redacted
  errors mapped to friendly messages
- SQLite via modernc with goose migrations, portable schema
- Local file storage behind a Storage interface
- go-i18n with an English catalog, no literal text in handlers
- Free tier limits enforced before queueing and again on the real file
- Bot token and webhook secret are stripped from all log output
- Tests: URL parsing, job lifecycle, worker, yt-dlp wrapper, and end to end
  flows against a fake Bot API server; opt-in test with the real yt-dlp

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-18 07:33:32 +00:00

75 lines
3.1 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# A stand-in for yt-dlp used by exec_test.go. It prints the same line
# formats as the real tool. FAKE_MODE selects the scenario.
set -u
args=("$@")
dir=""
is_probe=0
url="${args[$((${#args[@]} - 1))]}"
for ((i = 0; i < ${#args[@]}; i++)); do
case "${args[$i]}" in
-P) dir="${args[$((i + 1))]}" ;;
-J) is_probe=1 ;;
--version) echo "2026.01.01"; exit 0 ;;
esac
done
if [[ -n "${FAKE_ARGS_FILE:-}" ]]; then
printf '%s\n' "${args[@]}" > "$FAKE_ARGS_FILE"
fi
case "${FAKE_MODE:-ok}" in
error_private)
echo "ERROR: [youtube] abc: Private video. Sign in if you've been granted access to this video" >&2
exit 1 ;;
error_bot)
echo "ERROR: [youtube] abc: Sign in to confirm you’re not a bot. Use --cookies-from-browser or --cookies" >&2
exit 1 ;;
error_with_secret)
echo "ERROR: unable to download video data from https://cdn.example.com/v.mp4?token=TOPSECRET&id=1: HTTP Error 503" >&2
exit 1 ;;
hang)
sleep 30
exit 0 ;;
esac
if [[ $is_probe -eq 1 ]]; then
case "${FAKE_MODE:-ok}" in
playlist)
echo '{"_type": "playlist", "id": "PL1", "title": "A List", "entries": [{"id": "a", "title": "One", "url": "https://example.com/a"}, {"id": "b", "title": "Two", "url": "https://example.com/b"}]}' ;;
*)
# Numbers are deliberately loose: a float size, a null and a quoted one.
echo '{"id": "abc", "title": "Fake Title", "extractor": "youtube", "extractor_key": "Youtube", "webpage_url": "'"$url"'", "duration": 61.4, "thumbnail": "https://img.example.com/t.jpg", "uploader": "Someone", "is_live": false, "filesize": null, "filesize_approx": 1234.56, "formats": [{"format_id": "a", "ext": "m4a", "vcodec": "none", "acodec": "mp4a.40.2", "filesize": 1000000}, {"format_id": "v", "ext": "mp4", "vcodec": "avc1.64001F", "acodec": "none", "height": 720, "width": "1280", "filesize": null, "filesize_approx": 9000000.7, "tbr": 1200.5}], "subtitles": {"en": [{"ext": "vtt"}], "live_chat": [{"ext": "json"}]}, "automatic_captions": {"es": [{"ext": "vtt"}], "en": [{"ext": "vtt"}]}}' ;;
esac
exit 0
fi
echo 'INFO|{"id": "abc", "title": "Fake Title", "duration": 61.4, "extractor": "youtube", "extractor_key": "Youtube", "uploader": "Someone", "is_live": '"${FAKE_IS_LIVE:-false}"'}'
case "${FAKE_MODE:-ok}" in
filtered)
# yt-dlp exits 0 without a file when --match-filters rejects the item.
exit 0 ;;
max_filesize)
echo "[download] File is larger than max-filesize (99999999 bytes > 1000 bytes). Aborting."
exit 0 ;;
no_subs)
echo "[info] There are no subtitles for the requested languages"
exit 0 ;;
thumb)
head -c 300 /dev/zero > "$dir/media.jpg"
exit 0 ;;
esac
echo "[download] Destination: $dir/media.mp4"
echo "DLP|downloading|1000|4000|NA"
echo "DLP|downloading|4000|NA|4000.0"
echo "DLP|finished|4000|4000|NA"
echo "[Merger] Merging formats into \"$dir/media.mp4\""
head -c "${FAKE_SIZE:-4000}" /dev/zero > "$dir/media.mp4"
# Leftovers that must never be picked as the result.
head -c 9000 /dev/zero > "$dir/media.f137.mp4.part"
echo 'RESULT|{"width": 1280, "height": 720, "duration": 61.4, "ext": "mp4", "filepath": "'"$dir/media.mp4"'"}'
exit 0