mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
167 lines
4.6 KiB
Go
167 lines
4.6 KiB
Go
package urlparse
|
|
|
|
import "testing"
|
|
|
|
func TestDeezerDynamicURL(t *testing.T) {
|
|
url := "https://dzr.page.link/SnV6hCyHihkmCCwUA"
|
|
result := Parse(url)
|
|
if result == nil {
|
|
t.Fatalf("expected parsed url")
|
|
}
|
|
if result.Source != "deezer" {
|
|
t.Fatalf("source = %q, want deezer", result.Source)
|
|
}
|
|
if result.Kind != KindDeezerDynamic {
|
|
t.Fatalf("kind = %q, want %q", result.Kind, KindDeezerDynamic)
|
|
}
|
|
}
|
|
|
|
func TestQobuzAlbumURL(t *testing.T) {
|
|
url := "https://www.qobuz.com/fr-fr/album/bizarre-ride-ii-the-pharcyde-the-pharcyde/0066991040005"
|
|
result := Parse(url)
|
|
if result == nil {
|
|
t.Fatalf("expected parsed url")
|
|
}
|
|
if result.Source != "qobuz" || result.MediaType != "album" || result.ID != "0066991040005" {
|
|
t.Fatalf("unexpected parse result: %+v", result)
|
|
}
|
|
}
|
|
|
|
func TestQobuzInterpreterURLParsesAsArtist(t *testing.T) {
|
|
inputs := []string{
|
|
"https://www.qobuz.com/us-en/interpreter/odezenne/739874",
|
|
"https://play.qobuz.com/artist/739874",
|
|
}
|
|
for _, input := range inputs {
|
|
result := Parse(input)
|
|
if result == nil {
|
|
t.Fatalf("expected parsed url for %q", input)
|
|
}
|
|
if result.Source != "qobuz" || result.MediaType != "artist" || result.ID != "739874" {
|
|
t.Fatalf("unexpected parse result for %q: %+v", input, result)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestTidalTrackURL(t *testing.T) {
|
|
inputs := []string{
|
|
"https://tidal.com/browse/track/3083287",
|
|
"https://tidal.com/us/browse/track/3083287",
|
|
"https://tidal.com/us/track/3083287",
|
|
}
|
|
for _, url := range inputs {
|
|
result := Parse(url)
|
|
if result == nil {
|
|
t.Fatalf("expected parsed url for %q", url)
|
|
}
|
|
if result.Source != "tidal" || result.MediaType != "track" || result.ID != "3083287" {
|
|
t.Fatalf("unexpected parse result for %q: %+v", url, result)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestTidalVideoURL(t *testing.T) {
|
|
url := "https://tidal.com/browse/video/59727844"
|
|
result := Parse(url)
|
|
if result == nil {
|
|
t.Fatalf("expected parsed url")
|
|
}
|
|
if result.Source != "tidal" || result.MediaType != "video" || result.ID != "59727844" {
|
|
t.Fatalf("unexpected parse result: %+v", result)
|
|
}
|
|
}
|
|
|
|
func TestDeezerTrackURL(t *testing.T) {
|
|
url := "https://www.deezer.com/track/4195713"
|
|
result := Parse(url)
|
|
if result == nil {
|
|
t.Fatalf("expected parsed url")
|
|
}
|
|
if result.Source != "deezer" || result.MediaType != "track" || result.ID != "4195713" {
|
|
t.Fatalf("unexpected parse result: %+v", result)
|
|
}
|
|
}
|
|
|
|
func TestInvalidURL(t *testing.T) {
|
|
inputs := []string{
|
|
"https://example.com",
|
|
"not a url",
|
|
"https://spotify.com/track/123456",
|
|
"https://tidal.com/invalid/3083287",
|
|
}
|
|
for _, input := range inputs {
|
|
if result := Parse(input); result != nil {
|
|
t.Fatalf("expected nil for %q, got %+v", input, result)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAlternateURLFormats(t *testing.T) {
|
|
inputs := []string{
|
|
"https://open.tidal.com/track/3083287",
|
|
"https://play.qobuz.com/album/0066991040005",
|
|
"https://listen.tidal.com/track/3083287",
|
|
}
|
|
for _, input := range inputs {
|
|
if result := Parse(input); result == nil {
|
|
t.Fatalf("expected parse for %q", input)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestURLWithLanguageCode(t *testing.T) {
|
|
inputs := []string{
|
|
"https://www.qobuz.com/us-en/album/name/id123456",
|
|
"https://www.qobuz.com/gb-en/album/name/id123456",
|
|
"https://www.deezer.com/en/track/4195713",
|
|
"https://www.deezer.com/fr/track/4195713",
|
|
"https://m.deezer.com/en/track/4195713",
|
|
}
|
|
for _, input := range inputs {
|
|
if result := Parse(input); result == nil {
|
|
t.Fatalf("expected parse for %q", input)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDeezerMobileHostURL(t *testing.T) {
|
|
url := "https://m.deezer.com/track/4195713"
|
|
result := Parse(url)
|
|
if result == nil {
|
|
t.Fatalf("expected parsed url")
|
|
}
|
|
if result.Source != "deezer" || result.MediaType != "track" || result.ID != "4195713" {
|
|
t.Fatalf("unexpected parse result: %+v", result)
|
|
}
|
|
}
|
|
|
|
func TestSoundcloudURL(t *testing.T) {
|
|
inputs := []string{
|
|
"https://soundcloud.com/artist-name/track-name",
|
|
"https://soundcloud.com/artist-name/sets/playlist-name",
|
|
"https://m.soundcloud.com/artist-name/track-name",
|
|
"https://on.soundcloud.com/abcdef",
|
|
}
|
|
for _, input := range inputs {
|
|
result := Parse(input)
|
|
if result == nil {
|
|
t.Fatalf("expected parse for %q", input)
|
|
}
|
|
if result.Source != "soundcloud" || result.Kind != KindSoundcloud {
|
|
t.Fatalf("unexpected parse result: %+v", result)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSoundcloudProfileURLIsNotTrack(t *testing.T) {
|
|
if result := Parse("https://soundcloud.com/artist-name"); result != nil {
|
|
t.Fatalf("expected nil for profile url, got %+v", result)
|
|
}
|
|
}
|
|
|
|
func TestSoundcloudSetsRootWithoutPlaylistSlugInvalid(t *testing.T) {
|
|
if result := Parse("https://soundcloud.com/artist-name/sets"); result != nil {
|
|
t.Fatalf("expected nil for sets root url, got %+v", result)
|
|
}
|
|
}
|