diff --git a/main.go b/main.go deleted file mode 100644 index be0a72c..0000000 --- a/main.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "gfx.cafe/util/go/fxplus" - "go.uber.org/fx" - - "git.asdf.cafe/abs3nt/gspot/src/components/cache" - "git.asdf.cafe/abs3nt/gspot/src/components/cli" - "git.asdf.cafe/abs3nt/gspot/src/components/commands" - "git.asdf.cafe/abs3nt/gspot/src/components/logger" - "git.asdf.cafe/abs3nt/gspot/src/services" -) - -func main() { - var s fx.Shutdowner - app := fx.New( - fxplus.WithLogger, - fx.Populate(&s), - services.Config, - fx.Provide( - fxplus.Context, - cache.NewCache, - commands.NewCommander, - logger.NewLogger, - ), - fx.Invoke( - cli.Run, - ), - ) - app.Run() -} diff --git a/src/components/cli/cli.go b/src/components/cli/cli.go index 46b81a4..a011c1b 100644 --- a/src/components/cli/cli.go +++ b/src/components/cli/cli.go @@ -40,7 +40,7 @@ func Run(c *commands.Commander, s fx.Shutdowner) { Usage: "Plays a spotify url", ArgsUsage: "url", Action: func(ctx context.Context, cmd *cli.Command) error { - return c.PlayUrl(cmd.Args().First()) + return c.PlayURL(cmd.Args().First()) }, Category: "Playback", }, diff --git a/src/components/commands/next.go b/src/components/commands/next.go index ef37980..a019e97 100644 --- a/src/components/commands/next.go +++ b/src/components/commands/next.go @@ -20,12 +20,12 @@ func (c *Commander) Next(amt int, inqueue bool) error { err := c.Client().Next(c.Context) if err != nil { if isNoActiveError(err) { - deviceId, err := c.activateDevice() + deviceID, err := c.activateDevice() if err != nil { return err } err = c.Client().NextOpt(c.Context, &spotify.PlayOptions{ - DeviceID: &deviceId, + DeviceID: &deviceID, }) if err != nil { return err diff --git a/src/components/commands/play.go b/src/components/commands/play.go index 896b3de..953a672 100644 --- a/src/components/commands/play.go +++ b/src/components/commands/play.go @@ -43,11 +43,11 @@ func (c *Commander) PlayLikedSongs(position int) error { if err != nil { return err } - to_add := []spotify.ID{} + toAdd := []spotify.ID{} for _, song := range songs.Tracks { - to_add = append(to_add, song.ID) + toAdd = append(toAdd, song.ID) } - _, err = c.Client().AddTracksToPlaylist(c.Context, playlist.ID, to_add...) + _, err = c.Client().AddTracksToPlaylist(c.Context, playlist.ID, toAdd...) if err != nil { return err } @@ -78,11 +78,11 @@ func (c *Commander) PlayLikedSongs(position int) error { if err != nil { return err } - to_add := []spotify.ID{} + toAdd := []spotify.ID{} for _, song := range songs.Tracks { - to_add = append(to_add, song.ID) + toAdd = append(toAdd, song.ID) } - _, err = c.Client().AddTracksToPlaylist(c.Context, playlist.ID, to_add...) + _, err = c.Client().AddTracksToPlaylist(c.Context, playlist.ID, toAdd...) if err != nil { return err } @@ -91,20 +91,20 @@ func (c *Commander) PlayLikedSongs(position int) error { return err } -func (c *Commander) PlayUrl(urlString string) error { +func (c *Commander) PlayURL(urlString string) error { url, err := url.Parse(urlString) if err != nil { return err } - track_id := strings.Split(url.Path, "/")[2] - err = c.Client().QueueSong(c.Context, spotify.ID(track_id)) + trackID := strings.Split(url.Path, "/")[2] + err = c.Client().QueueSong(c.Context, spotify.ID(trackID)) if err != nil { if isNoActiveError(err) { deviceID, err := c.activateDevice() if err != nil { return err } - err = c.Client().QueueSongOpt(c.Context, spotify.ID(track_id), &spotify.PlayOptions{ + err = c.Client().QueueSongOpt(c.Context, spotify.ID(trackID), &spotify.PlayOptions{ DeviceID: &deviceID, }) if err != nil { diff --git a/src/components/commands/previous.go b/src/components/commands/previous.go index 68c6457..d91440d 100644 --- a/src/components/commands/previous.go +++ b/src/components/commands/previous.go @@ -8,12 +8,12 @@ func (c *Commander) Previous() error { err := c.Client().Previous(c.Context) if err != nil { if isNoActiveError(err) { - deviceId, err := c.activateDevice() + deviceID, err := c.activateDevice() if err != nil { return err } err = c.Client().PreviousOpt(c.Context, &spotify.PlayOptions{ - DeviceID: &deviceId, + DeviceID: &deviceID, }) if err != nil { return err diff --git a/src/components/commands/radio.go b/src/components/commands/radio.go index 951d27c..006896a 100644 --- a/src/components/commands/radio.go +++ b/src/components/commands/radio.go @@ -16,12 +16,12 @@ import ( ) func (c *Commander) Radio() error { - current_song, err := c.Client().PlayerCurrentlyPlaying(c.Context) + currentSong, err := c.Client().PlayerCurrentlyPlaying(c.Context) if err != nil { return err } - if current_song.Item != nil { - return c.RadioGivenSong(current_song.Item.SimpleTrack, current_song.Progress) + if currentSong.Item != nil { + return c.RadioGivenSong(currentSong.Item.SimpleTrack, currentSong.Progress) } _, err = c.activateDevice() if err != nil { @@ -153,12 +153,13 @@ func (c *Commander) RadioGivenArtist(artist spotify.SimpleArtist) error { seed := spotify.Seeds{ Tracks: []spotify.ID{recomendationIds[id]}, } - additional_recs, err := c.Client().GetRecommendations(c.Context, seed, &spotify.TrackAttributes{}, spotify.Limit(100)) + additionalRecs, err := c.Client(). + GetRecommendations(c.Context, seed, &spotify.TrackAttributes{}, spotify.Limit(100)) if err != nil { return err } additionalRecsIds := []spotify.ID{} - for _, song := range additional_recs.Tracks { + for _, song := range additionalRecs.Tracks { exists, err := c.SongExists(db, song.ID) if err != nil { return err @@ -255,12 +256,13 @@ func (c *Commander) RadioGivenSong(song spotify.SimpleTrack, pos int) error { seed := spotify.Seeds{ Tracks: []spotify.ID{recomendationIds[id]}, } - additional_recs, err := c.Client().GetRecommendations(c.Context, seed, &spotify.TrackAttributes{}, spotify.Limit(100)) + additionalRecs, err := c.Client(). + GetRecommendations(c.Context, seed, &spotify.TrackAttributes{}, spotify.Limit(100)) if err != nil { return err } additionalRecsIds := []spotify.ID{} - for _, song := range additional_recs.Tracks { + for _, song := range additionalRecs.Tracks { exists, err := c.SongExists(db, song.ID) if err != nil { return err @@ -344,9 +346,9 @@ func (c *Commander) CreateRadioPlaylist(name string) (*spotify.FullPlaylist, *sq } func (c *Commander) SongExists(db *sql.DB, song spotify.ID) (bool, error) { - song_id := string(song) + songID := string(song) sqlStmt := `SELECT id FROM radio WHERE id = ?` - err := db.QueryRow(sqlStmt, song_id).Scan(&song_id) + err := db.QueryRow(sqlStmt, songID).Scan(&songID) if err != nil { if err != sql.ErrNoRows { return false, err @@ -366,7 +368,7 @@ func (c *Commander) RefillRadio() error { if !status.Playing { return nil } - to_remove := []spotify.ID{} + toRemove := []spotify.ID{} radioPlaylist, db, err := c.GetRadioPlaylist("") if err != nil { return err @@ -394,13 +396,13 @@ func (c *Commander) RefillRadio() error { if track.Track.Track.ID == status.Item.ID { break } - to_remove = append(to_remove, track.Track.Track.ID) + toRemove = append(toRemove, track.Track.Track.ID) } page++ } - if len(to_remove) > 0 { + if len(toRemove) > 0 { var trackGroups []spotify.ID - for idx, item := range to_remove { + for idx, item := range toRemove { if idx%100 == 0 { _, err = c.Client().RemoveTracksFromPlaylist(c.Context, radioPlaylist.ID, trackGroups...) trackGroups = []spotify.ID{} @@ -416,7 +418,7 @@ func (c *Commander) RefillRadio() error { } } - to_add := 500 - (playlistItems.Total - len(to_remove)) + toAdd := 500 - (playlistItems.Total - len(toRemove)) playlistItems, err = c.Client().GetPlaylistItems(c.Context, radioPlaylist.ID) if err != nil { return fmt.Errorf("playlist items: %w", err) @@ -464,7 +466,7 @@ func (c *Commander) RefillRadio() error { } queue := []spotify.ID{} for idx, rec := range recomendationIds { - if idx > to_add { + if idx > toAdd { break } _, err = db.QueryContext(c.Context, fmt.Sprintf("INSERT INTO radio (id) VALUES('%s')", rec.String())) @@ -473,7 +475,7 @@ func (c *Commander) RefillRadio() error { } queue = append(queue, rec) } - to_add -= len(queue) + toAdd -= len(queue) _, err = c.Client().AddTracksToPlaylist(c.Context, radioPlaylist.ID, queue...) if err != nil { return fmt.Errorf("add tracks: %w", err) @@ -482,30 +484,31 @@ func (c *Commander) RefillRadio() error { if err != nil { return fmt.Errorf("repeat: %w", err) } - for to_add > 0 { + for toAdd > 0 { id := frand.Intn(len(recomendationIds)-2) + 1 seed := spotify.Seeds{ Tracks: []spotify.ID{recomendationIds[id]}, } - additional_recs, err := c.Client().GetRecommendations(c.Context, seed, &spotify.TrackAttributes{}, spotify.Limit(100)) + additionalRecs, err := c.Client(). + GetRecommendations(c.Context, seed, &spotify.TrackAttributes{}, spotify.Limit(100)) if err != nil { return fmt.Errorf("get recs: %w", err) } additionalRecsIds := []spotify.ID{} - for idx, song := range additional_recs.Tracks { + for idx, song := range additionalRecs.Tracks { exists, err := c.SongExists(db, song.ID) if err != nil { return fmt.Errorf("check song existence: %w", err) } if !exists { - if idx > to_add { + if idx > toAdd { break } additionalRecsIds = append(additionalRecsIds, song.ID) queue = append(queue, song.ID) } } - to_add -= len(queue) + toAdd -= len(queue) _, err = c.Client().AddTracksToPlaylist(c.Context, radioPlaylist.ID, additionalRecsIds...) if err != nil { return fmt.Errorf("add tracks to playlist: %w", err) @@ -548,9 +551,9 @@ func (c *Commander) RadioFromAlbum(album spotify.SimpleAlbum) error { return c.RadioGivenList(seedIds[:seedCount], album.Name) } -func (c *Commander) RadioGivenList(song_ids []spotify.ID, name string) error { +func (c *Commander) RadioGivenList(songs []spotify.ID, name string) error { seed := spotify.Seeds{ - Tracks: song_ids, + Tracks: songs, } recomendations, err := c.Client().GetRecommendations(c.Context, seed, &spotify.TrackAttributes{}, spotify.Limit(99)) if err != nil { @@ -568,7 +571,7 @@ func (c *Commander) RadioGivenList(song_ids []spotify.ID, name string) error { if err != nil { return err } - queue := []spotify.ID{song_ids[0]} + queue := []spotify.ID{songs[0]} for _, rec := range recomendationIds { exists, err := c.SongExists(db, rec) if err != nil { @@ -591,13 +594,13 @@ func (c *Commander) RadioGivenList(song_ids []spotify.ID, name string) error { }) if err != nil { if isNoActiveError(err) { - deviceId, err := c.activateDevice() + deviceID, err := c.activateDevice() if err != nil { return err } err = c.Client().PlayOpt(c.Context, &spotify.PlayOptions{ PlaybackContext: &radioPlaylist.URI, - DeviceID: &deviceId, + DeviceID: &deviceID, }) if err != nil { return err @@ -609,12 +612,12 @@ func (c *Commander) RadioGivenList(song_ids []spotify.ID, name string) error { seed := spotify.Seeds{ Tracks: []spotify.ID{recomendationIds[id]}, } - additional_recs, err := c.Client().GetRecommendations(c.Context, seed, &spotify.TrackAttributes{}, spotify.Limit(100)) + additionalRecs, err := c.Client().GetRecommendations(c.Context, seed, &spotify.TrackAttributes{}, spotify.Limit(100)) if err != nil { return err } additionalRecsIds := []spotify.ID{} - for _, song := range additional_recs.Tracks { + for _, song := range additionalRecs.Tracks { exists, err := c.SongExists(db, song.ID) if err != nil { return err diff --git a/src/components/tui/loader.go b/src/components/tui/loader.go index f49641f..539ffc3 100644 --- a/src/components/tui/loader.go +++ b/src/components/tui/loader.go @@ -32,7 +32,7 @@ func (m *mainModel) LoadMoreItems() { for _, item := range items { m.list.InsertItem(len(m.list.Items())+1, item) } - main_updates <- m + mainUpdates <- m return case "artists": artists, err := m.commands.Client().CurrentUsersFollowedArtists( @@ -60,7 +60,7 @@ func (m *mainModel) LoadMoreItems() { for _, item := range items { m.list.InsertItem(len(m.list.Items())+1, item) } - main_updates <- m + mainUpdates <- m return case "album": tracks, err := m.commands.AlbumTracks(m.album.ID, (page + 1)) @@ -80,7 +80,7 @@ func (m *mainModel) LoadMoreItems() { for _, item := range items { m.list.InsertItem(len(m.list.Items())+1, item) } - main_updates <- m + mainUpdates <- m return case "albums": albums, err := m.commands.UserAlbums(page + 1) @@ -99,7 +99,7 @@ func (m *mainModel) LoadMoreItems() { for _, item := range items { m.list.InsertItem(len(m.list.Items())+1, item) } - main_updates <- m + mainUpdates <- m return case "main": playlists, err := m.commands.Playlists(page + 1) @@ -117,7 +117,7 @@ func (m *mainModel) LoadMoreItems() { for _, item := range items { m.list.InsertItem(len(m.list.Items())+1, item) } - main_updates <- m + mainUpdates <- m return case "playlist": playlistItems, err := m.commands.PlaylistTracks(m.playlist.ID, (page + 1)) @@ -139,7 +139,7 @@ func (m *mainModel) LoadMoreItems() { for _, item := range items { m.list.InsertItem(len(m.list.Items())+1, item) } - main_updates <- m + mainUpdates <- m return case "tracks": tracks, err := m.commands.TrackList(page + 1) @@ -159,7 +159,7 @@ func (m *mainModel) LoadMoreItems() { for _, item := range items { m.list.InsertItem(len(m.list.Items())+1, item) } - main_updates <- m + mainUpdates <- m return } } diff --git a/src/components/tui/main.go b/src/components/tui/main.go index 8a56981..b79971d 100644 --- a/src/components/tui/main.go +++ b/src/components/tui/main.go @@ -22,7 +22,7 @@ var ( DocStyle = lipgloss.NewStyle().Margin(0, 2).Border(lipgloss.DoubleBorder(), true, true, true, true) currentlyPlaying *spotify.CurrentlyPlaying playbackContext string - main_updates chan *mainModel + mainUpdates chan *mainModel page = 1 loading = false showingMessage = false @@ -190,32 +190,32 @@ func (m *mainModel) GoBack() (tea.Cmd, error) { return tea.Quit, nil case Albums, Artists, Tracks, Playlist, Devices, Search, Queue: m.mode = Main - new_items, err := MainView(m.commands) + newItems, err := MainView(m.commands) if err != nil { return nil, err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) case Album: m.mode = Albums - new_items, err := AlbumsView(m.commands) + newItems, err := AlbumsView(m.commands) if err != nil { return nil, err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) case Artist: m.mode = Artists - new_items, err := ArtistsView(m.commands) + newItems, err := ArtistsView(m.commands) if err != nil { return nil, err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) case ArtistAlbum: m.mode = Artist - new_items, err := ArtistAlbumsView(m.artist.ID, m.commands) + newItems, err := ArtistAlbumsView(m.artist.ID, m.commands) if err != nil { return nil, err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) case SearchArtists, SearchTracks, SearchAlbums, SearchPlaylists: m.mode = Search items, result, err := SearchView(m.commands, m.search) @@ -226,39 +226,39 @@ func (m *mainModel) GoBack() (tea.Cmd, error) { m.list.SetItems(items) case SearchArtist: m.mode = SearchArtists - new_items, err := SearchArtistsView(m.commands, m.searchResults.Artists) + newItems, err := SearchArtistsView(m.commands, m.searchResults.Artists) if err != nil { return nil, err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) case SearchArtistAlbum: m.mode = SearchArtist - new_items, err := ArtistAlbumsView(m.artist.ID, m.commands) + newItems, err := ArtistAlbumsView(m.artist.ID, m.commands) if err != nil { return nil, err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) case SearchAlbum: m.mode = SearchAlbums - new_items, err := SearchAlbumsView(m.commands, m.searchResults.Albums) + newItems, err := SearchAlbumsView(m.commands, m.searchResults.Albums) if err != nil { return nil, err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) case SearchPlaylist: m.mode = SearchPlaylists - new_items, err := SearchPlaylistsView(m.commands, m.searchResults.Playlists) + newItems, err := SearchPlaylistsView(m.commands, m.searchResults.Playlists) if err != nil { return nil, err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) default: page = 0 } return nil, nil } -type SpotifyUrl struct { +type SpotifyURL struct { ExternalURLs map[string]string } @@ -343,11 +343,11 @@ func (m *mainModel) QueueItem() error { }() if m.mode == Queue { go func() { - new_items, err := QueueView(m.commands) + newItems, err := QueueView(m.commands) if err != nil { return } - m.list.SetItems(new_items) + m.list.SetItems(newItems) }() } return nil @@ -364,11 +364,11 @@ func (m *mainModel) DeleteTrackFromPlaylist() error { if err != nil { m.SendMessage(err.Error(), 5*time.Second) } - new_items, err := PlaylistView(m.commands, m.playlist) + newItems, err := PlaylistView(m.commands, m.playlist) if err != nil { m.SendMessage(err.Error(), 5*time.Second) } - m.list.SetItems(new_items) + m.list.SetItems(newItems) }() return nil } @@ -382,11 +382,11 @@ func (m *mainModel) SelectItem() error { if err != nil { m.SendMessage(err.Error(), 5*time.Second) } - new_items, err := QueueView(m.commands) + newItems, err := QueueView(m.commands) if err != nil { m.SendMessage(err.Error(), 5*time.Second) } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() }() case Search: @@ -394,150 +394,150 @@ func (m *mainModel) SelectItem() error { switch item := m.list.SelectedItem().(mainItem).SpotifyItem.(type) { case *spotify.FullArtistPage: m.mode = SearchArtists - new_items, err := SearchArtistsView(m.commands, item) + newItems, err := SearchArtistsView(m.commands, item) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() case *spotify.SimpleAlbumPage: m.mode = SearchAlbums - new_items, err := SearchAlbumsView(m.commands, item) + newItems, err := SearchAlbumsView(m.commands, item) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() case *spotify.SimplePlaylistPage: m.mode = SearchPlaylists - new_items, err := SearchPlaylistsView(m.commands, item) + newItems, err := SearchPlaylistsView(m.commands, item) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() case *spotify.FullTrackPage: m.mode = SearchTracks - new_items, err := SearchTracksView(item) + newItems, err := SearchTracksView(item) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() } case SearchArtists: page = 1 m.mode = SearchArtist m.artist = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleArtist) - new_items, err := ArtistAlbumsView(m.artist.ID, m.commands) + newItems, err := ArtistAlbumsView(m.artist.ID, m.commands) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() case SearchArtist: page = 1 m.mode = SearchArtistAlbum m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum) - new_items, err := AlbumTracksView(m.album.ID, m.commands) + newItems, err := AlbumTracksView(m.album.ID, m.commands) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() case SearchAlbums: page = 1 m.mode = SearchAlbum m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum) - new_items, err := AlbumTracksView(m.album.ID, m.commands) + newItems, err := AlbumTracksView(m.album.ID, m.commands) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() case SearchPlaylists: page = 1 m.mode = SearchPlaylist playlist := m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimplePlaylist) m.playlist = playlist - new_items, err := PlaylistView(m.commands, playlist) + newItems, err := PlaylistView(m.commands, playlist) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() case Main: page = 1 switch item := m.list.SelectedItem().(mainItem).SpotifyItem.(type) { case spotify.Queue: m.mode = Queue - new_items, err := QueueView(m.commands) + newItems, err := QueueView(m.commands) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() case *spotify.FullArtistCursorPage: m.mode = Artists - new_items, err := ArtistsView(m.commands) + newItems, err := ArtistsView(m.commands) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() case *spotify.SavedAlbumPage: m.mode = Albums - new_items, err := AlbumsView(m.commands) + newItems, err := AlbumsView(m.commands) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() case spotify.SimplePlaylist: m.mode = Playlist m.playlist = item - new_items, err := PlaylistView(m.commands, item) + newItems, err := PlaylistView(m.commands, item) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() case *spotify.SavedTrackPage: m.mode = Tracks - new_items, err := SavedTracksView(m.commands) + newItems, err := SavedTracksView(m.commands) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() } case Albums: page = 1 m.mode = Album m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum) - new_items, err := AlbumTracksView(m.album.ID, m.commands) + newItems, err := AlbumTracksView(m.album.ID, m.commands) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() case Artist: m.mode = ArtistAlbum m.album = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleAlbum) - new_items, err := AlbumTracksView(m.album.ID, m.commands) + newItems, err := AlbumTracksView(m.album.ID, m.commands) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() case Artists: m.mode = Artist m.artist = m.list.SelectedItem().(mainItem).SpotifyItem.(spotify.SimpleArtist) - new_items, err := ArtistAlbumsView(m.artist.ID, m.commands) + newItems, err := ArtistAlbumsView(m.artist.ID, m.commands) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() case Album, ArtistAlbum, SearchArtistAlbum, SearchAlbum: pos := m.list.Cursor() + (m.list.Paginator.Page * m.list.Paginator.TotalPages) @@ -579,17 +579,17 @@ func (m *mainModel) SelectItem() error { } }() m.mode = "main" - new_items, err := MainView(m.commands) + newItems, err := MainView(m.commands) if err != nil { return err } - m.list.SetItems(new_items) + m.list.SetItems(newItems) } return nil } func (m *mainModel) Init() tea.Cmd { - main_updates = make(chan *mainModel) + mainUpdates = make(chan *mainModel) return Tick() } @@ -665,8 +665,8 @@ func (m *mainModel) Typing(msg tea.KeyMsg) (bool, tea.Cmd) { func (m *mainModel) getContext(playing *spotify.CurrentlyPlaying) (string, error) { context := playing.PlaybackContext - uri_split := strings.Split(string(context.URI), ":") - if len(uri_split) < 3 { + uriSplit := strings.Split(string(context.URI), ":") + if len(uriSplit) < 3 { return "", fmt.Errorf("NO URI") } id := strings.Split(string(context.URI), ":")[2] @@ -699,7 +699,7 @@ func (m *mainModel) getContext(playing *spotify.CurrentlyPlaying) (string, error func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // Update list items from LoadMore select { - case update := <-main_updates: + case update := <-mainUpdates: m.list.SetItems(update.list.Items()) default: } @@ -721,11 +721,11 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if m.mode == Queue && len(m.list.Items()) != 0 { if m.list.Items()[0].(mainItem).SpotifyItem.(spotify.FullTrack).Name != playing.Item.Name { go func() { - new_items, err := QueueView(m.commands) + newItems, err := QueueView(m.commands) if err != nil { return } - m.list.SetItems(new_items) + m.list.SetItems(newItems) }() } } @@ -806,11 +806,11 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { // enter device selection if msg.String() == "d" { m.mode = Devices - new_items, err := DeviceView(m.commands) + newItems, err := DeviceView(m.commands) if err != nil { return m, tea.Quit } - m.list.SetItems(new_items) + m.list.SetItems(newItems) m.list.ResetSelected() } // go back diff --git a/src/components/tui/views.go b/src/components/tui/views.go index 3f4bc58..0dbe5f6 100644 --- a/src/components/tui/views.go +++ b/src/components/tui/views.go @@ -171,7 +171,7 @@ func SearchPlaylistsView(commands *commands.Commander, playlists *spotify.Simple for _, playlist := range playlists.Playlists { items = append(items, mainItem{ Name: playlist.Name, - Desc: stripHtmlRegex(playlist.Description), + Desc: stripHTMLRegex(playlist.Description), SpotifyItem: playlist, }) } @@ -269,13 +269,13 @@ func SavedTracksView(commands *commands.Commander) ([]list.Item, error) { func MainView(c *commands.Commander) ([]list.Item, error) { c.Log.Debug("SWITCHING TO MAIN VIEW") wg := errgroup.Group{} - var saved_items *spotify.SavedTrackPage + var savedItems *spotify.SavedTrackPage var playlists *spotify.SimplePlaylistPage var artists *spotify.FullArtistCursorPage var albums *spotify.SavedAlbumPage wg.Go(func() (err error) { - saved_items, err = c.Client().CurrentUsersTracks(c.Context, spotify.Limit(50), spotify.Offset(0)) + savedItems, err = c.Client().CurrentUsersTracks(c.Context, spotify.Limit(50), spotify.Offset(0)) return }) @@ -300,11 +300,11 @@ func MainView(c *commands.Commander) ([]list.Item, error) { } items := []list.Item{} - if saved_items != nil && saved_items.Total != 0 { + if savedItems != nil && savedItems.Total != 0 { items = append(items, mainItem{ Name: "Saved Tracks", - Desc: fmt.Sprintf("%d saved songs", saved_items.Total), - SpotifyItem: saved_items, + Desc: fmt.Sprintf("%d saved songs", savedItems.Total), + SpotifyItem: savedItems, }) } if albums != nil && albums.Total != 0 { @@ -330,7 +330,7 @@ func MainView(c *commands.Commander) ([]list.Item, error) { for _, playlist := range playlists.Playlists { items = append(items, mainItem{ Name: playlist.Name, - Desc: stripHtmlRegex(playlist.Description), + Desc: stripHTMLRegex(playlist.Description), SpotifyItem: playlist, }) } @@ -338,7 +338,7 @@ func MainView(c *commands.Commander) ([]list.Item, error) { return items, nil } -func stripHtmlRegex(s string) string { +func stripHTMLRegex(s string) string { r := regexp.MustCompile(regex) return r.ReplaceAllString(s, "") } diff --git a/src/config/config.go b/src/config/config.go index 67de52a..b7550b9 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -1,7 +1,7 @@ package config type Config struct { - ClientId string `yaml:"client_id"` + ClientID string `yaml:"client_id"` ClientSecret string `yaml:"client_secret"` ClientSecretCmd string `yaml:"client_secret_cmd"` Port string `yaml:"port"` diff --git a/src/services/auth.go b/src/services/auth.go index 06bc728..866bec7 100644 --- a/src/services/auth.go +++ b/src/services/auth.go @@ -33,24 +33,24 @@ func (fn roundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error) } func GetClient(conf *config.Config) (c *spotify.Client, err error) { - if conf.ClientId == "" || (conf.ClientSecret == "" && conf.ClientSecretCmd == "") || conf.Port == "" { + if conf.ClientID == "" || (conf.ClientSecret == "" && conf.ClientSecretCmd == "") || conf.Port == "" { return nil, fmt.Errorf("INVALID CONFIG") } if conf.ClientSecretCmd != "" { args := strings.Fields(conf.ClientSecretCmd) cmd := args[0] - secret_command := exec.Command(cmd) + secretCommand := exec.Command(cmd) if len(args) > 1 { - secret_command.Args = args + secretCommand.Args = args } - secret, err := secret_command.Output() + secret, err := secretCommand.Output() if err != nil { panic(err) } conf.ClientSecret = strings.TrimSpace(string(secret)) } auth = spotifyauth.New( - spotifyauth.WithClientID(conf.ClientId), + spotifyauth.WithClientID(conf.ClientID), spotifyauth.WithClientSecret(conf.ClientSecret), spotifyauth.WithRedirectURL(fmt.Sprintf("http://localhost:%s/callback", conf.Port)), spotifyauth.WithScopes( @@ -93,11 +93,11 @@ func GetClient(conf *config.Config) (c *spotify.Client, err error) { }) authClient := auth.Client(authCtx, tok) client := spotify.New(authClient, spotify.WithRetry(true)) - new_token, err := client.Token() + newToken, err := client.Token() if err != nil { return nil, err } - out, err := json.MarshalIndent(new_token, "", " ") + out, err := json.MarshalIndent(newToken, "", " ") if err != nil { return nil, err }