102 lines
2.8 KiB
Go
102 lines
2.8 KiB
Go
package metadata
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestScanEpisodes(t *testing.T) {
|
|
root := t.TempDir()
|
|
seasonDir := filepath.Join(root, "s2024")
|
|
if err := os.MkdirAll(seasonDir, 0o755); err != nil {
|
|
t.Fatalf("mkdir: %v", err)
|
|
}
|
|
|
|
base := filepath.Join(seasonDir, "TestChannel.s2024Se0210S.Sample.abc123")
|
|
infoPath := base + ".info.json"
|
|
videoPath := base + ".mp4"
|
|
thumbPath := base + ".jpg"
|
|
|
|
epJSON := `{"title":"Episode","channel":"Test Channel","id":"abc123","description":"Episode description","upload_date":"20240210","ext":"mp4"}`
|
|
if err := os.WriteFile(infoPath, []byte(epJSON), 0o644); err != nil {
|
|
t.Fatalf("write info: %v", err)
|
|
}
|
|
if err := os.WriteFile(videoPath, []byte("video"), 0o644); err != nil {
|
|
t.Fatalf("write video: %v", err)
|
|
}
|
|
if err := os.WriteFile(thumbPath, []byte("thumb"), 0o644); err != nil {
|
|
t.Fatalf("write thumbnail: %v", err)
|
|
}
|
|
|
|
assets, err := ScanEpisodes(root)
|
|
if err != nil {
|
|
t.Fatalf("ScanEpisodes error: %v", err)
|
|
}
|
|
if len(assets) != 1 {
|
|
t.Fatalf("expected 1 asset, got %d", len(assets))
|
|
}
|
|
|
|
asset := assets[0]
|
|
if asset.MediaPath != videoPath {
|
|
t.Fatalf("unexpected media path: %s", asset.MediaPath)
|
|
}
|
|
if len(asset.Sidecars) != 1 || asset.Sidecars[0] != thumbPath {
|
|
t.Fatalf("unexpected sidecars: %#v", asset.Sidecars)
|
|
}
|
|
}
|
|
|
|
func TestScanShows(t *testing.T) {
|
|
root := t.TempDir()
|
|
showDir := filepath.Join(root, "sNA")
|
|
if err := os.MkdirAll(showDir, 0o755); err != nil {
|
|
t.Fatalf("mkdir: %v", err)
|
|
}
|
|
|
|
base := filepath.Join(showDir, "test-channel")
|
|
infoPath := base + ".info.json"
|
|
posterPath := base + ".jpg"
|
|
|
|
showJSON := `{"channel":"Test Channel","channel_id":"chan123","description":"Show description","thumbnails":[]}`
|
|
if err := os.WriteFile(infoPath, []byte(showJSON), 0o644); err != nil {
|
|
t.Fatalf("write show info: %v", err)
|
|
}
|
|
if err := os.WriteFile(posterPath, []byte("poster"), 0o644); err != nil {
|
|
t.Fatalf("write poster: %v", err)
|
|
}
|
|
|
|
assets, err := ScanShows(root)
|
|
if err != nil {
|
|
t.Fatalf("ScanShows error: %v", err)
|
|
}
|
|
if len(assets) != 1 {
|
|
t.Fatalf("expected 1 show asset, got %d", len(assets))
|
|
}
|
|
|
|
asset := assets[0]
|
|
if asset.InfoPath != infoPath {
|
|
t.Fatalf("unexpected info path: %s", asset.InfoPath)
|
|
}
|
|
if len(asset.Images) != 1 || asset.Images[0] != posterPath {
|
|
t.Fatalf("unexpected images: %#v", asset.Images)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeEpisodeThumbnail(t *testing.T) {
|
|
got := NormalizeEpisodeThumbnail("file.jpg")
|
|
expected := "file-thumb.jpg"
|
|
if got != expected {
|
|
t.Fatalf("expected %s, got %s", expected, got)
|
|
}
|
|
|
|
got = NormalizeEpisodeThumbnail("file-thumb.jpg")
|
|
if got != "file-thumb.jpg" {
|
|
t.Fatalf("normalization should keep thumb suffix, got %s", got)
|
|
}
|
|
|
|
got = NormalizeEpisodeThumbnail("file.jpeg")
|
|
if got != "file-thumb.jpeg" {
|
|
t.Fatalf("unexpected jpeg normalization: %s", got)
|
|
}
|
|
}
|