-
Notifications
You must be signed in to change notification settings - Fork 2
/
direct_link.go
66 lines (55 loc) · 1.14 KB
/
direct_link.go
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 control
import (
"fmt"
"strings"
"github.com/zmb3/spotify"
)
func handleLink(link string) error {
link = strings.TrimPrefix(link, "https://open.spotify.com/")
split := strings.SplitN(link, "/", 2)
switch split[0] {
case "track":
return playTrackFromID(split[1])
case "artist":
return playArtistFromID(split[1])
case "playlist":
return playPlaylistFromID(split[1])
case "album":
return playAlbumFromID(split[1])
default:
return fmt.Errorf("unrecognized url")
}
}
func playTrackFromID(id string) error {
t, err := client.GetTrack(spotify.ID(id))
if err != nil {
return err
}
return playTrack(t)
}
func playArtistFromID(id string) error {
a, err := client.GetArtist(spotify.ID(id))
if err != nil {
return err
}
return playArtist(a)
}
func playAlbumFromID(id string) error {
a, err := client.GetAlbum(spotify.ID(id))
if err != nil {
return err
}
return playAlbum(&a.SimpleAlbum)
}
func playPlaylistFromID(id string) error {
p, err := client.GetPlaylist(spotify.ID(id))
if err != nil {
return err
}
pl := Playlist{
FullPlaylist: *p,
isFull: true,
isFollowed: false,
}
return playPlaylist(&pl)
}