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 TestYandexURLs(t *testing.T) { tests := []struct { url string mediaType string id string }{ {url: "https://music.yandex.ru/track/9442712", mediaType: "track", id: "9442712"}, {url: "https://music.yandex.ru/album/1000856", mediaType: "album", id: "1000856"}, {url: "https://music.yandex.ru/album/1000856/track/9442712", mediaType: "track", id: "9442712:1000856"}, {url: "https://music.yandex.ru/artist/1433871", mediaType: "artist", id: "1433871"}, {url: "https://music.yandex.ru/users/yandexmusic/playlists/1635", mediaType: "playlist", id: "yandexmusic:1635"}, {url: "https://music.yandex.ru/playlists/4ae45ac1-0972-734f-8537-769490399170", mediaType: "playlist", id: "4ae45ac1-0972-734f-8537-769490399170"}, } for _, tc := range tests { result := Parse(tc.url) if result == nil { t.Fatalf("expected parse for %q", tc.url) } if result.Source != "yandex" || result.MediaType != tc.mediaType || result.ID != tc.id { t.Fatalf("unexpected parse result for %q: %+v", tc.url, 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) } }