summaryrefslogtreecommitdiff
path: root/internal/service/service.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/service/service.go')
-rw-r--r--internal/service/service.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/internal/service/service.go b/internal/service/service.go
new file mode 100644
index 0000000..49647fe
--- /dev/null
+++ b/internal/service/service.go
@@ -0,0 +1,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
+}