feat: add thumbnail preview, audio-only detection, /download command, tests, and bugfixes

- Add thumbnail preview with metadata (title, uploader, duration) before download
- Auto-detect audio-only sites (Spotify, SoundCloud, etc.) and skip type selection
- Add /download command for feature parity with UI button
- Fix yt-dlp defer bug: StatusFailed was overwritten to StatusCompleted
- Fix handleURLInput using editText with msgID=0 (now uses sendWithKB)
- Fix filename detection: use job ID prefix for reliable file finding
- Fix double answerCb between handleBackStep and handleDownloadPrompt
- Fix runDownload unused msgID parameter
- Fix context for download goroutine (use context.Background)
- Remove unused startWebhook h parameter
- Remove dead buildToggleKeyboard function
- Add formatBytes, formatDuration, formatLabelForDisplay tests
- Add IsAudioOnlyContent, MediaType.String tests
- Add repo integration tests (users, preferences, quotas, history, delete)
- Add cmd/bot tests (parseAllowedUsers, env helpers)
- Add edge case tests for progress parser
- Add zero/negative safety guard in formatDuration
- Add .gitea, TODO.md, opencode.json to gitignore
This commit is contained in:
2026-06-25 15:07:31 +03:30
parent 05fcdf7458
commit cd27b4d28d
15 changed files with 631 additions and 64 deletions

View File

@@ -46,6 +46,35 @@ func TestParseProgressLine(t *testing.T) {
line: "some random log line",
hasRes: false,
},
{
line: "[download] 0.0% of 1.00GiB at 0.00B/s ETA 00:00",
pct: 0.0,
speed: "0.00B/s",
eta: "00:00",
hasRes: true,
},
{
line: "[download] 0.0% of 1.00KiB at 100.00KiB/s ETA 00:01",
pct: 0.0,
speed: "100.00KiB/s",
eta: "00:01",
hasRes: true,
},
{
line: "[download] 50.5% of 2.00MiB at 500.00KiB/s ETA 00:02",
pct: 50.5,
speed: "500.00KiB/s",
eta: "00:02",
hasRes: true,
},
{
line: "[download] 1.2% of unknown size at 0.00B/s ETA Unknown",
hasRes: false,
},
{
line: "[Merge] Merging video and audio...",
hasRes: false,
},
}
for _, tt := range tests {
got := parseProgressLine(tt.line)
@@ -70,3 +99,23 @@ func TestParseProgressLine(t *testing.T) {
}
}
}
func TestParseProgressLineEdgeCases(t *testing.T) {
tests := []struct {
line string
name string
hasRes bool
}{
{"[download] 0.0% of 1.00GiB at 0.00B/s ETA 00:00", "multiple spaces", true},
{"[download] 100.0% of 1.00GiB at 999.99MiB/s ETA 00:00", "high speed", true},
{"[download] 100.0% of 999.99TiB at 1.00TiB/s ETA 00:00", "large numbers", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := parseProgressLine(tt.line)
if tt.hasRes && got == nil {
t.Errorf("parseProgressLine(%q) = nil, want result", tt.line)
}
})
}
}

View File

@@ -49,6 +49,8 @@ type ytdlpFormat struct {
type ytdlpInfo struct {
Title string `json:"title"`
Uploader string `json:"uploader"`
Thumbnail string `json:"thumbnail"`
Duration float64 `json:"duration"`
IsLive bool `json:"is_live"`
Formats []ytdlpFormat `json:"formats"`
@@ -95,6 +97,8 @@ func (c *Client) GetMediaInfo(url string) (*domain.MediaInfo, error) {
mi := &domain.MediaInfo{
URL: url,
Title: info.Title,
Uploader: info.Uploader,
Thumbnail: info.Thumbnail,
Duration: info.Duration,
IsPlaylist: info.Playlist != "",
}
@@ -146,6 +150,8 @@ func (c *Client) GetPlaylistInfo(url string) (*domain.MediaInfo, error) {
mi := &domain.MediaInfo{
URL: url,
Title: info.Title,
Uploader: info.Uploader,
Thumbnail: info.Thumbnail,
IsPlaylist: true,
PlaylistCount: info.PlaylistCount,
PlaylistEntries: c.parsePlaylistEntries(info.Entries),
@@ -226,8 +232,8 @@ func (c *Client) StartDownload(job *domain.DownloadJob, downloadDir string) (<-c
}
}
// Output template
outputPath := filepath.Join(downloadDir, "%(id)s.%(ext)s")
// Output template with job ID prefix for reliable file finding
outputPath := filepath.Join(downloadDir, job.ID+"_%(id)s.%(ext)s")
args = append(args, "--output", outputPath)
// Progress reporting
@@ -267,7 +273,6 @@ func (c *Client) StartDownload(job *domain.DownloadJob, downloadDir string) (<-c
go func() {
defer func() {
if job.Status != domain.StatusCancelled {
job.Status = domain.StatusCompleted
updates <- job
}
close(updates)