From 05ecbf808eba7201dfb43f5b62f8b34792168556 Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Thu, 28 Dec 2023 05:25:55 +0530 Subject: [PATCH] Don't export client --- spt/add.go | 4 ++-- spt/auth.go | 2 +- spt/get.go | 50 +++++++++++++++++++++++++------------------------- spt/play.go | 16 ++++++++-------- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/spt/add.go b/spt/add.go index 64a3039..a927c56 100644 --- a/spt/add.go +++ b/spt/add.go @@ -8,7 +8,7 @@ import ( ) func AddTracksToPlaylist(playlistId spotify.ID, t ...spotify.ID) error { - _, err := Client.AddTracksToPlaylist(ctx, playlistId, t...) + _, err := client.AddTracksToPlaylist(ctx, playlistId, t...) return err } @@ -16,7 +16,7 @@ func QueueTracks(ids ...spotify.ID) error { count := 0 _ctx := ctx for _, id := range ids { - if err := Client.QueueSong(_ctx, id); err != nil { + if err := client.QueueSong(_ctx, id); err != nil { return errors.New(fmt.Sprintf("%s | Tracks Queued: %d", err.Error(), count)) } } diff --git a/spt/auth.go b/spt/auth.go index e1e54d5..681eab6 100644 --- a/spt/auth.go +++ b/spt/auth.go @@ -98,7 +98,7 @@ func InitClient() error { token = payload.Token } - Client = spotify.New(auth.Client(context.Background(), token)) + client = spotify.New(auth.Client(context.Background(), token)) return nil } diff --git a/spt/get.go b/spt/get.go index a9f8323..b2a0e5c 100644 --- a/spt/get.go +++ b/spt/get.go @@ -40,7 +40,7 @@ type Playable interface { var ( ctx = context.Background() - Client *spotify.Client + client *spotify.Client playlistCache map[spotify.ID]*Playlist = make(map[spotify.ID]*Playlist) albumCache map[spotify.ID]*Album = make(map[spotify.ID]*Album) PageContinue = errors.New("CONTINUE") @@ -48,7 +48,7 @@ var ( func GetPlaylist(playlistId spotify.ID) (*Playlist, chan error) { c := make(chan error) - if fp, err := Client.GetPlaylist(ctx, playlistId); err != nil { + if fp, err := client.GetPlaylist(ctx, playlistId); err != nil { go func() { c <- err }() return nil, c } else { @@ -60,7 +60,7 @@ func GetPlaylist(playlistId spotify.ID) (*Playlist, chan error) { addTracks() go func() { for page := 1; ; page++ { - if perr := Client.NextPage(ctx, &fp.Tracks); perr == spotify.ErrNoMorePages { + if perr := client.NextPage(ctx, &fp.Tracks); perr == spotify.ErrNoMorePages { c <- nil break } else if perr != nil { @@ -86,7 +86,7 @@ func GetPlaylist(playlistId spotify.ID) (*Playlist, chan error) { func GetAlbum(albumID spotify.ID) (*Album, chan error) { c := make(chan error) if _, ok := albumCache[albumID]; !ok { - fa, err := Client.GetAlbum(ctx, albumID) + fa, err := client.GetAlbum(ctx, albumID) if err != nil { go func() { c <- err }() return nil, c @@ -98,7 +98,7 @@ func GetAlbum(albumID spotify.ID) (*Album, chan error) { addTracks() go func() { for page := 1; ; page++ { - if perr := Client.NextPage(ctx, &fa.Tracks); perr == spotify.ErrNoMorePages { + if perr := client.NextPage(ctx, &fa.Tracks); perr == spotify.ErrNoMorePages { c <- nil break } else if perr != nil { @@ -125,7 +125,7 @@ func CurrentUserSavedAlbums() (*SavedAlbums, chan error) { c := make(chan error) _a := make(SavedAlbums, 0) albums := &_a - if sp, err := Client.CurrentUsersAlbums(ctx); err != nil { + if sp, err := client.CurrentUsersAlbums(ctx); err != nil { go func() { c <- err }() return nil, c } else { @@ -135,7 +135,7 @@ func CurrentUserSavedAlbums() (*SavedAlbums, chan error) { addAlbums() go func() { for page := 1; ; page++ { - if perr := Client.NextPage(ctx, sp); perr == spotify.ErrNoMorePages { + if perr := client.NextPage(ctx, sp); perr == spotify.ErrNoMorePages { c <- nil break } else if perr != nil { @@ -153,7 +153,7 @@ func CurrentUserPlaylists() (*UserPlaylists, chan error) { c := make(chan error) _p := make(UserPlaylists, 0) playlists := &_p - if spp, err := Client.CurrentUsersPlaylists(ctx); err != nil { + if spp, err := client.CurrentUsersPlaylists(ctx); err != nil { go func() { c <- err }() return nil, c } else { @@ -163,7 +163,7 @@ func CurrentUserPlaylists() (*UserPlaylists, chan error) { addPlaylists() go func() { for page := 1; ; page++ { - if perr := Client.NextPage(ctx, spp); perr == spotify.ErrNoMorePages { + if perr := client.NextPage(ctx, spp); perr == spotify.ErrNoMorePages { c <- nil break } else if perr != nil { @@ -181,7 +181,7 @@ func CurrentUserSavedTracks() (*LikedSongs, chan error) { c := make(chan error) _p := make(LikedSongs, 0) playlists := &_p - if ls, err := Client.CurrentUsersTracks(ctx); err != nil { + if ls, err := client.CurrentUsersTracks(ctx); err != nil { go func() { c <- err }() return nil, c } else { @@ -191,7 +191,7 @@ func CurrentUserSavedTracks() (*LikedSongs, chan error) { addTracks() go func() { for page := 1; ; page++ { - if perr := Client.NextPage(ctx, ls); perr == spotify.ErrNoMorePages { + if perr := client.NextPage(ctx, ls); perr == spotify.ErrNoMorePages { c <- nil break } else if perr != nil { @@ -210,7 +210,7 @@ func CurrentUserFollowedArtists() (*FollowedArtists, chan error) { // TODO: Check if this is the proper implementation _a := make(FollowedArtists, 0) artists := &_a - if ar, err := Client.CurrentUsersFollowedArtists(ctx); err != nil { + if ar, err := client.CurrentUsersFollowedArtists(ctx); err != nil { go func() { c <- err }() return nil, c } else { @@ -225,7 +225,7 @@ func CurrentUserFollowedArtists() (*FollowedArtists, chan error) { if len(ar.Artists) == 0 { c <- nil } - if ar, err = Client.CurrentUsersFollowedArtists(ctx, spotify.After(string(ap))); err != nil { + if ar, err = client.CurrentUsersFollowedArtists(ctx, spotify.After(string(ap))); err != nil { if err == spotify.ErrNoMorePages { c <- nil break @@ -243,15 +243,15 @@ func CurrentUserFollowedArtists() (*FollowedArtists, chan error) { } func RecentlyPlayed() ([]spotify.RecentlyPlayedItem, error) { - return Client.PlayerRecentlyPlayedOpt(ctx, &spotify.RecentlyPlayedOptions{Limit: 50}) + return client.PlayerRecentlyPlayedOpt(ctx, &spotify.RecentlyPlayedOptions{Limit: 50}) } func GetPlayerState() (*spotify.PlayerState, error) { - return Client.PlayerState(ctx) + return client.PlayerState(ctx) } func GetTopTracks() ([]spotify.FullTrack, error) { - c, err := Client.CurrentUsersTopTracks(ctx, spotify.Limit(topTracksLimit)) + c, err := client.CurrentUsersTopTracks(ctx, spotify.Limit(topTracksLimit)) if c != nil { return c.Tracks, err } else { @@ -260,7 +260,7 @@ func GetTopTracks() ([]spotify.FullTrack, error) { } func GetTopArtists() ([]spotify.FullArtist, error) { - c, err := Client.CurrentUsersTopArtists(ctx, spotify.Limit(topTracksLimit)) + c, err := client.CurrentUsersTopArtists(ctx, spotify.Limit(topTracksLimit)) if c != nil { return c.Artists, err } else { @@ -269,15 +269,15 @@ func GetTopArtists() ([]spotify.FullArtist, error) { } func GetArtistTopTracks(artistID spotify.ID) ([]spotify.FullTrack, error) { - c, err := Client.CurrentUser(ctx) + c, err := client.CurrentUser(ctx) if err != nil { return []spotify.FullTrack{}, err } - return Client.GetArtistsTopTracks(ctx, artistID, c.Country) + return client.GetArtistsTopTracks(ctx, artistID, c.Country) } func GetArtistAlbums(artistID spotify.ID) ([]spotify.SimpleAlbum, error) { - c, err := Client.GetArtistAlbums(ctx, artistID, albumtypes) + c, err := client.GetArtistAlbums(ctx, artistID, albumtypes) if err != nil { return []spotify.SimpleAlbum{}, err } @@ -285,7 +285,7 @@ func GetArtistAlbums(artistID spotify.ID) ([]spotify.SimpleAlbum, error) { } func Search(s string) (*spotify.SearchResult, error) { - return Client.Search(ctx, s, + return client.Search(ctx, s, spotify.SearchTypePlaylist| spotify.SearchTypeAlbum| spotify.SearchTypeTrack| @@ -293,7 +293,7 @@ func Search(s string) (*spotify.SearchResult, error) { } func UserDevices() ([]spotify.PlayerDevice, error) { - return Client.PlayerDevices(ctx) + return client.PlayerDevices(ctx) } func TransferPlayback(deviceId spotify.ID) error { @@ -301,10 +301,10 @@ func TransferPlayback(deviceId spotify.ID) error { if err != nil { return errors.New("Unable to get Current Player State!") } - err = Client.PauseOpt(ctx, &spotify.PlayOptions{DeviceID: &s.Device.ID}) - return Client.TransferPlayback(ctx, deviceId, true) + err = client.PauseOpt(ctx, &spotify.PlayOptions{DeviceID: &s.Device.ID}) + return client.TransferPlayback(ctx, deviceId, true) } func GetFullPlaylist(id spotify.ID) (*spotify.FullPlaylist, error) { - return Client.GetPlaylist(ctx, id) + return client.GetPlaylist(ctx, id) } diff --git a/spt/play.go b/spt/play.go index 91a62d9..06d13b4 100644 --- a/spt/play.go +++ b/spt/play.go @@ -8,7 +8,7 @@ import ( ) func play(options *spotify.PlayOptions) error { - return Client.PlayOpt(ctx, options) + return client.PlayOpt(ctx, options) } func PlaySong(uri spotify.URI) error { @@ -38,16 +38,16 @@ func PlayContext(context spotify.URI) error { } func TogglePlayback() error { - p, err := Client.PlayerCurrentlyPlaying(ctx) + p, err := client.PlayerCurrentlyPlaying(ctx) if err != nil { return err } if p.Playing { - if err := Client.Pause(ctx); err != nil { + if err := client.Pause(ctx); err != nil { return err } } else { - if err := Client.Play(ctx); err != nil { + if err := client.Play(ctx); err != nil { return err } } @@ -63,11 +63,11 @@ func UriToID(uri spotify.URI) (spotify.ID, error) { } func Next() error { - return Client.Next(ctx) + return client.Next(ctx) } func Previous() error { - return Client.Previous(ctx) + return client.Previous(ctx) } func Shuffle() error { @@ -77,7 +77,7 @@ func Shuffle() error { return err } - return Client.Shuffle(ctx, !s.ShuffleState) + return client.Shuffle(ctx, !s.ShuffleState) } func Repeat() error { @@ -92,5 +92,5 @@ func Repeat() error { return err } - return Client.Repeat(ctx, next[s.RepeatState]) + return client.Repeat(ctx, next[s.RepeatState]) }