summaryrefslogtreecommitdiff
path: root/internal/service/service.go
blob: 49647feb6454c378b559721a3b42fd2669d26474 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package services

// service defines any Music service recognized by song.link
// Since most services have multiple url version (long, short, etc...),
// it is allowd to have multiple ones.
// This allows for seamless song link detection
type service struct {
	name     string
	patterns []string
}

func GetServices() []service {
	return []service{
		*New(
			"Apple Music",
			[]string{"https://music.apple.com/"},
		),
		*New(
			"Spotify",
			[]string{"https://open.spotify.com/track/", "https://open.spotify.com/album/", "https://open.spotify.com/playlist/"},
		),
		*New(
			"Youtube Music",
			[]string{"https://music.youtube.com/"},
		),
		// *New(
		// 	"Amazon Music",
		// 	[]string{"https://music.amazon.com/",},
		// ),
		*New(
			"Tidal",
			[]string{"https://tidal.com/"},
		),
		*New(
			"Deezer",
			[]string{"https://www.deezer.com/"},
		),
		*New(
			"Pandora",
			[]string{"https://www.pandora.com/"},
		),
	}
}

func New(name string, patterns []string) *service {
	return &service{name, patterns}
}

func (s *service) Name() string {
	return s.name
}

func (s *service) Owns(url string) bool {
	// If the url begins the same as any of the patterns, it is owned by the service
	for _, pattern := range s.patterns {
		if len(url) >= len(pattern) && url[:len(pattern)] == pattern {
			return true
		}
	}
	return false
}

// Resolve returns the song.link url for the given service url
func (s *service) Resolve(url string) string {
	return "https://song.link/" + url
}