package extractor import ( "reflect" "testing" ) func TestExtractStreams(t *testing.T) { html := ` listen
` streams := ExtractStreams(html) if len(streams) != 7 { t.Fatalf("wanted 7 streams, got %d: %v", len(streams), streams) } found := false for _, s := range streams { if s == "https://stream.example.com/live" { found = true break } } if !found { t.Fatalf("expected audio tag stream to be present: %v", streams) } } func TestExtractPlaylistLinks(t *testing.T) { html := ` m3u pls xspf json ` links := ExtractPlaylistLinks(html) if len(links) != 4 { t.Fatalf("wanted 4 playlist links, got %d: %v", len(links), links) } } func TestExtractEmbedURLs(t *testing.T) { html := `` urls := ExtractEmbedURLs(html) want := []string{"https://example.com/embed", "https://example.org/player"} if !reflect.DeepEqual(urls, want) { t.Fatalf("wanted iframe URLs %v, got %v", want, urls) } } func TestExtractScriptURLs(t *testing.T) { html := `` urls := ExtractScriptURLs(html) want := []string{"/js/app.js", "https://example.org/player.js"} if !reflect.DeepEqual(urls, want) { t.Fatalf("wanted script URLs %v, got %v", want, urls) } } func TestParsePlaylist(t *testing.T) { m3u := "#EXTM3U\nhttps://example.com/live.mp3\n" pls := "[playlist]\nFile1=https://example.com/stream.aac\n" xspf := "https://example.com/hls.m3u8" if len(ParsePlaylist(m3u, "audio/x-mpegurl", "https://example.com/playlist.m3u")) != 1 { t.Fatal("expected m3u playlist to yield 1 stream") } if len(ParsePlaylist(pls, "audio/x-scpls", "https://example.com/playlist.pls")) != 1 { t.Fatal("expected pls playlist to yield 1 stream") } if len(ParsePlaylist(xspf, "application/xspf+xml", "https://example.com/playlist.xspf")) != 1 { t.Fatal("expected xspf playlist to yield 1 stream") } relative := "stream/live.mp3\n" resolved := ParsePlaylist(relative, "audio/x-mpegurl", "https://example.com/radio/list.m3u") if len(resolved) != 1 || resolved[0] != "https://example.com/radio/stream/live.mp3" { t.Fatalf("expected relative URL to resolve against base: %v", resolved) } }