mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-07-27 23:42:28 +02:00
feat: add beatport provider
This commit is contained in:
@@ -47,6 +47,8 @@ func Parse(raw string) *ParsedURL {
|
||||
return parseQobuz(raw, parts)
|
||||
case isYandexHost(host):
|
||||
return parseYandex(raw, parts)
|
||||
case isBeatportHost(host):
|
||||
return parseBeatport(raw, parts)
|
||||
case isTidalHost(host):
|
||||
return parseTidal(raw, parts)
|
||||
case isDeezerHost(host):
|
||||
@@ -58,6 +60,60 @@ func Parse(raw string) *ParsedURL {
|
||||
}
|
||||
}
|
||||
|
||||
func parseBeatport(raw string, parts []string) *ParsedURL {
|
||||
if len(parts) < 2 {
|
||||
return nil
|
||||
}
|
||||
if len(parts[0]) == 2 {
|
||||
parts = parts[1:]
|
||||
}
|
||||
if len(parts) > 0 && parts[0] == "catalog" {
|
||||
parts = parts[1:]
|
||||
}
|
||||
if len(parts) < 2 {
|
||||
return nil
|
||||
}
|
||||
|
||||
mediaType := ""
|
||||
idIndex := 1
|
||||
switch parts[0] {
|
||||
case "track", "tracks":
|
||||
mediaType = "track"
|
||||
if parts[0] == "track" {
|
||||
idIndex = 2
|
||||
}
|
||||
case "release", "releases":
|
||||
mediaType = "album"
|
||||
if parts[0] == "release" {
|
||||
idIndex = 2
|
||||
}
|
||||
case "library":
|
||||
if len(parts) < 3 || (parts[1] != "playlists" && parts[1] != "playlist") {
|
||||
return nil
|
||||
}
|
||||
mediaType = "playlist"
|
||||
idIndex = 2
|
||||
case "playlists":
|
||||
mediaType = "playlist"
|
||||
idIndex = 2
|
||||
case "chart", "playlist":
|
||||
mediaType = "chart"
|
||||
idIndex = 2
|
||||
case "artist":
|
||||
mediaType = "artist"
|
||||
idIndex = 2
|
||||
case "label":
|
||||
mediaType = "label"
|
||||
idIndex = 2
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
if idIndex >= len(parts) || strings.TrimSpace(parts[idIndex]) == "" {
|
||||
return nil
|
||||
}
|
||||
return &ParsedURL{OriginalURL: raw, Source: "beatport", MediaType: mediaType, ID: parts[idIndex], Kind: KindGeneric}
|
||||
}
|
||||
|
||||
func parseQobuz(raw string, parts []string) *ParsedURL {
|
||||
if len(parts) < 2 {
|
||||
return nil
|
||||
@@ -222,6 +278,10 @@ func isYandexHost(host string) bool {
|
||||
return host == "music.yandex.ru" || host == "music.yandex.com" || host == "music.yandex.kz" || host == "music.yandex.by"
|
||||
}
|
||||
|
||||
func isBeatportHost(host string) bool {
|
||||
return host == "beatport.com" || host == "api.beatport.com"
|
||||
}
|
||||
|
||||
func isTidalHost(host string) bool {
|
||||
return host == "tidal.com" || host == "open.tidal.com" || host == "listen.tidal.com"
|
||||
}
|
||||
@@ -236,7 +296,7 @@ func isSoundcloudHost(host string) bool {
|
||||
|
||||
func isSupportedMedia(mediaType string) bool {
|
||||
switch mediaType {
|
||||
case "album", "track", "playlist", "artist", "label", "video":
|
||||
case "album", "track", "playlist", "artist", "label", "video", "chart":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
|
||||
@@ -67,6 +67,31 @@ func TestYandexURLs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBeatportURLs(t *testing.T) {
|
||||
tests := []struct {
|
||||
url string
|
||||
mediaType string
|
||||
id string
|
||||
}{
|
||||
{url: "https://www.beatport.com/track/strobe/1696999", mediaType: "track", id: "1696999"},
|
||||
{url: "https://www.beatport.com/release/random-album/12345", mediaType: "album", id: "12345"},
|
||||
{url: "https://www.beatport.com/library/playlists/67890", mediaType: "playlist", id: "67890"},
|
||||
{url: "https://www.beatport.com/chart/some-chart/111", mediaType: "chart", id: "111"},
|
||||
{url: "https://www.beatport.com/artist/deadmau5/24078", mediaType: "artist", id: "24078"},
|
||||
{url: "https://www.beatport.com/label/mau5trap/1234", mediaType: "label", id: "1234"},
|
||||
{url: "https://api.beatport.com/v4/catalog/tracks/1696999/", mediaType: "track", id: "1696999"},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
result := Parse(tc.url)
|
||||
if result == nil {
|
||||
t.Fatalf("expected parse for %q", tc.url)
|
||||
}
|
||||
if result.Source != "beatport" || 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",
|
||||
|
||||
Reference in New Issue
Block a user