Telegram bot for downloading media from any site using yt-dlp. Supports audio/video/both, quality selection, language picker, container format selection, playlist pagination, progress updates, per-user quotas, user preferences, download history, cancel at any step, polling and webhook modes, proxy support, and SQLite persistence.
104 lines
3.0 KiB
Go
104 lines
3.0 KiB
Go
package dl
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"uptodownBot/internal/domain"
|
|
)
|
|
|
|
func TestFilterFormatsByType(t *testing.T) {
|
|
formats := []domain.Format{
|
|
{ID: "1", HasVideo: true, HasAudio: false, IsVideoOnly: true, IsAudioOnly: false},
|
|
{ID: "2", HasVideo: false, HasAudio: true, IsVideoOnly: false, IsAudioOnly: true},
|
|
{ID: "3", HasVideo: true, HasAudio: true, IsVideoOnly: false, IsAudioOnly: false},
|
|
{ID: "4", HasVideo: true, HasAudio: false, IsVideoOnly: true, IsAudioOnly: false},
|
|
{ID: "5", HasVideo: false, HasAudio: true, IsVideoOnly: false, IsAudioOnly: true},
|
|
}
|
|
|
|
tests := []struct {
|
|
mediaType domain.MediaType
|
|
wantIDs []string
|
|
}{
|
|
{domain.MediaTypeAudio, []string{"2", "5"}},
|
|
{domain.MediaTypeVideo, []string{"1", "4"}},
|
|
{domain.MediaTypeVideoAudio, []string{"3"}},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
got := FilterFormatsByType(formats, tt.mediaType)
|
|
if len(got) != len(tt.wantIDs) {
|
|
t.Errorf("FilterFormatsByType(%v) = %d results, want %d", tt.mediaType, len(got), len(tt.wantIDs))
|
|
continue
|
|
}
|
|
for i, f := range got {
|
|
if f.ID != tt.wantIDs[i] {
|
|
t.Errorf("FilterFormatsByType(%v)[%d].ID = %s, want %s", tt.mediaType, i, f.ID, tt.wantIDs[i])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDeduplicateResolutions(t *testing.T) {
|
|
formats := []domain.Format{
|
|
{ID: "1", Resolution: "1920x1080", Height: 1080, IsVideoOnly: true},
|
|
{ID: "2", Resolution: "1920x1080", Height: 1080, IsVideoOnly: true},
|
|
{ID: "3", Resolution: "1280x720", Height: 720, IsVideoOnly: true},
|
|
{ID: "4", Bitrate: "128k", IsAudioOnly: true},
|
|
{ID: "5", Bitrate: "128k", IsAudioOnly: true},
|
|
}
|
|
got := DeduplicateResolutions(formats)
|
|
if len(got) != 3 {
|
|
t.Errorf("DeduplicateResolutions = %d results, want 3", len(got))
|
|
}
|
|
}
|
|
|
|
func TestContainerOptions(t *testing.T) {
|
|
tests := []struct {
|
|
mt domain.MediaType
|
|
want []string
|
|
}{
|
|
{domain.MediaTypeAudio, []string{"mp3", "m4a", "opus"}},
|
|
{domain.MediaTypeVideo, []string{"mp4", "mkv", "webm"}},
|
|
{domain.MediaTypeVideoAudio, []string{"mp4", "mkv"}},
|
|
}
|
|
for _, tt := range tests {
|
|
got := ContainerOptions(tt.mt)
|
|
if len(got) != len(tt.want) {
|
|
t.Errorf("ContainerOptions(%v) = %v, want %v", tt.mt, got, tt.want)
|
|
continue
|
|
}
|
|
for i, c := range got {
|
|
if c != tt.want[i] {
|
|
t.Errorf("ContainerOptions(%v)[%d] = %s, want %s", tt.mt, i, c, tt.want[i])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestContainerOptionsZeroValue(t *testing.T) {
|
|
got := ContainerOptions(domain.MediaType(0))
|
|
want := []string{"mp4"}
|
|
if len(got) != 1 || got[0] != want[0] {
|
|
t.Errorf("ContainerOptions(0) = %v, want %v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestFormatLabel(t *testing.T) {
|
|
tests := []struct {
|
|
f domain.Format
|
|
want string
|
|
}{
|
|
{domain.Format{IsAudioOnly: true, Bitrate: "128k"}, "128k"},
|
|
{domain.Format{IsAudioOnly: true}, "audio"},
|
|
{domain.Format{Resolution: "1920x1080", Height: 1080}, "1920x1080"},
|
|
{domain.Format{Height: 720}, "720p"},
|
|
{domain.Format{ID: "137"}, "137"},
|
|
}
|
|
for _, tt := range tests {
|
|
got := formatLabel(tt.f)
|
|
if got != tt.want {
|
|
t.Errorf("formatLabel(%+v) = %q, want %q", tt.f, got, tt.want)
|
|
}
|
|
}
|
|
}
|