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>
This commit is contained in:
Michilis
2026-11-18 07:33:32 +00:00
co-authored by Claude Fable 5.2
commit 3b361c17a1
63 changed files with 10715 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
package i18n
import (
"fmt"
"time"
)
// Size formats a byte count for humans in the user's locale, for example
// "61.9 MB" in English and "61,9 MB" in Spanish and Dutch.
func (b *Bundle) Size(lang string, bytes int64) string {
const unit = 1024
p := b.printer(lang)
switch {
case bytes < unit:
return p.Sprintf("%d B", bytes)
case bytes < unit*unit:
return p.Sprintf("%.0f KB", float64(bytes)/unit)
case bytes < unit*unit*unit:
v := float64(bytes) / (unit * unit)
if v >= 100 {
return p.Sprintf("%.0f MB", v)
}
return p.Sprintf("%.1f MB", v)
default:
return p.Sprintf("%.2f GB", float64(bytes)/(unit*unit*unit))
}
}
// Clock formats a media duration as 1:02:03 or 2:03.
func Clock(seconds int64) string {
if seconds < 0 {
seconds = 0
}
h, m, s := seconds/3600, seconds/60%60, seconds%60
if h > 0 {
return fmt.Sprintf("%d:%02d:%02d", h, m, s)
}
return fmt.Sprintf("%d:%02d", m, s)
}
// Span formats a length of time in words, such as "30 seconds", "5 minutes"
// or "2 hours", using the plural rules of the language.
func (b *Bundle) Span(lang string, d time.Duration) string {
switch {
case d < time.Minute:
n := int(d.Round(time.Second) / time.Second)
if n < 1 {
n = 1
}
return b.T(lang, "unit.seconds", Args{"Count": n})
case d < time.Hour:
return b.T(lang, "unit.minutes", Args{"Count": int(d.Round(time.Minute) / time.Minute)})
default:
return b.T(lang, "unit.hours", Args{"Count": int(d.Round(time.Hour) / time.Hour)})
}
}
// Percent formats a ratio in the 0 to 1 range as a whole percentage.
func (b *Bundle) Percent(lang string, ratio float64) string {
if ratio < 0 {
ratio = 0
}
if ratio > 1 {
ratio = 1
}
return b.printer(lang).Sprintf("%d%%", int(ratio*100+0.5))
}