|
- package extractor
-
- import "testing"
-
- func TestExtractStreams(t *testing.T) {
- html := `
- <script>
- var streamsrc = 'https://example.com/live/stream.mp3';
- var streamhash="https://cdn.example.net/relay.m3u8";
- var audioUrl="https://example.com/audio.ogg";
- </script>
- <a href="https://streams.example.org/radio.aac?user=test">listen</a>
- <source src="//players.example.eu/ambient.ogg" type="audio/ogg" />
- <audio data-src="https://pod.example.com/episode.opus"></audio>
- <div data-value="https://example.com/secret.pls"></div>
- `
-
- streams := ExtractStreams(html)
- if len(streams) != 6 {
- t.Fatalf("wanted 6 streams, got %d: %v", len(streams), streams)
- }
- }
-
- func TestExtractPlaylistLinks(t *testing.T) {
- html := `
- <a href="https://example.com/stream.m3u">m3u</a>
- <a href="https://example.com/playlist.pls">pls</a>
- <a href="https://example.com/radio.xspf">xspf</a>
- <a href="https://example.com/data.json">json</a>
- `
- links := ExtractPlaylistLinks(html)
- if len(links) != 4 {
- t.Fatalf("wanted 4 playlist links, got %d: %v", len(links), links)
- }
- }
-
- func TestParsePlaylist(t *testing.T) {
- m3u := "#EXTM3U\nhttps://example.com/live.mp3\n"
- pls := "[playlist]\nFile1=https://example.com/stream.aac\n"
- xspf := "<playlist><location>https://example.com/hls.m3u8</location></playlist>"
-
- 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")
- }
- }
|