hako/internal/archival/archiver/yt_dlp_test.go
Vibe Kanban 0afef05099
feat: add yt-dlp support for video downloads
Add a new archiver to download videos using yt-dlp. The new extractor should call the yt-dlp binary to download the video and we should track progress in the output and return code. The default rules should be updated so youtube videos are extracted using this extractor. The extractor default config should get the thumbnail as well (so we don't depend on the thumbnail extractor) and subtitles. Update the dockerfile accordingly so we not only have yt-dlp but it's required dependencies as well. Prefer installing from packages, if possible.
2026-01-29 12:52:29 +01:00

129 lines
3.2 KiB
Go

package archiver
import (
"testing"
)
func TestYtDlpArchiver_GetDefaultConfig(t *testing.T) {
archiver := NewYtDlpArchiver()
config := archiver.GetDefaultConfig()
cfg, ok := config.(YtDlpConfig)
if !ok {
t.Fatalf("Expected config to be YtDlpConfig, got %T", config)
}
if cfg.Timeout != "10m" {
t.Errorf("Expected timeout to be 10m, got %q", cfg.Timeout)
}
if !cfg.WriteThumbnail {
t.Error("Expected WriteThumbnail to be true by default")
}
if !cfg.WriteSubs {
t.Error("Expected WriteSubs to be true by default")
}
if !cfg.EmbedSubs {
t.Error("Expected EmbedSubs to be true by default")
}
}
func TestYtDlpArchiver_ApplyConfig_Timeout(t *testing.T) {
a := NewYtDlpArchiver()
err := a.ApplyConfig(map[string]any{"timeout": "5m"})
if err != nil {
t.Fatalf("ApplyConfig failed: %v", err)
}
if a.config.Timeout != "5m" {
t.Errorf("Expected timeout 5m, got %q", a.config.Timeout)
}
}
func TestYtDlpArchiver_ApplyConfig_InvalidTimeout(t *testing.T) {
a := NewYtDlpArchiver()
err := a.ApplyConfig(map[string]any{"timeout": "invalid"})
if err == nil {
t.Error("Expected error for invalid timeout format")
}
}
func TestYtDlpArchiver_ApplyConfig_WriteThumbnail(t *testing.T) {
a := NewYtDlpArchiver()
err := a.ApplyConfig(map[string]any{"write_thumbnail": false})
if err != nil {
t.Fatalf("ApplyConfig failed: %v", err)
}
if a.config.WriteThumbnail {
t.Error("Expected WriteThumbnail to be false after config")
}
}
func TestYtDlpArchiver_ApplyConfig_WriteSubs(t *testing.T) {
a := NewYtDlpArchiver()
err := a.ApplyConfig(map[string]any{"write_subs": false})
if err != nil {
t.Fatalf("ApplyConfig failed: %v", err)
}
if a.config.WriteSubs {
t.Error("Expected WriteSubs to be false after config")
}
}
func TestYtDlpArchiver_ApplyConfig_EmbedSubs(t *testing.T) {
a := NewYtDlpArchiver()
err := a.ApplyConfig(map[string]any{"embed_subs": true})
if err != nil {
t.Fatalf("ApplyConfig failed: %v", err)
}
if !a.config.EmbedSubs {
t.Error("Expected EmbedSubs to be true after config")
}
}
func TestYtDlpArchiver_ApplyConfig_AllFields(t *testing.T) {
a := NewYtDlpArchiver()
err := a.ApplyConfig(map[string]any{
"timeout": "15m",
"write_thumbnail": false,
"write_subs": false,
"embed_subs": true,
})
if err != nil {
t.Fatalf("ApplyConfig failed: %v", err)
}
if a.config.Timeout != "15m" {
t.Errorf("Expected timeout 15m, got %q", a.config.Timeout)
}
if a.config.WriteThumbnail {
t.Error("Expected WriteThumbnail to be false")
}
if a.config.WriteSubs {
t.Error("Expected WriteSubs to be false")
}
if !a.config.EmbedSubs {
t.Error("Expected EmbedSubs to be true")
}
}
func TestYtDlpConfig_ToMap(t *testing.T) {
cfg := YtDlpConfig{
Timeout: "15m",
WriteThumbnail: true,
WriteSubs: false,
EmbedSubs: true,
}
m := cfg.ToMap()
if m == nil {
t.Fatal("ToMap() returned nil")
}
if m["timeout"] != "15m" {
t.Errorf("Expected timeout 15m, got %v", m["timeout"])
}
if m["write_thumbnail"] != true {
t.Errorf("Expected write_thumbnail true, got %v", m["write_thumbnail"])
}
if m["write_subs"] != false {
t.Errorf("Expected write_subs false, got %v", m["write_subs"])
}
if m["embed_subs"] != true {
t.Errorf("Expected embed_subs true, got %v", m["embed_subs"])
}
}