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 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")) != 1 {
t.Fatal("expected m3u playlist to yield 1 stream")
}
if len(ParsePlaylist(pls, "audio/x-scpls")) != 1 {
t.Fatal("expected pls playlist to yield 1 stream")
}
if len(ParsePlaylist(xspf, "application/xspf+xml")) != 1 {
t.Fatal("expected xspf playlist to yield 1 stream")
}
}