Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add 'play --playlist' support. Issue #27 #41

Merged
merged 27 commits into from
Aug 1, 2021

Conversation

Threpio
Copy link
Contributor

@Threpio Threpio commented Jul 20, 2021

Fixes issue #27

Upgraded root spotify module from v0.5.0 => v0.6.0.
Added --playlist flag to the play function that takes a playlist name and plays it.

Tests have been updated to reflect upgrade from spotify v0.5.0 -> v0.6.0
New tests required for additional features.

Copy link
Owner

@brianstrauch brianstrauch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, although I think we should change the Play() function to better support playing albums... see my comment below. (And then you could easily sneak the --album flag into this PR!)

internal/mock_api.go Outdated Show resolved Hide resolved
internal/p/p.go Outdated

return cmd
}

func p(api internal.APIInterface, query, deviceID string) (string, error) {
func p(api internal.APIInterface, query, contextQuery, deviceID string) (string, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the logic here needs to be fixed to use contextQuery

internal/p/p_test.go Outdated Show resolved Hide resolved

return cmd
}

func Play(api internal.APIInterface, query, deviceID string) (string, error) {
func Play(api internal.APIInterface, query, contextQuery , deviceID string) (string, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should pass query and queryType here, where queryType is "track", "album", or "playlist". Then we can switch on queryType to determine if we should do internal.Search() or a linear search through all of the user's playlists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An internal.Search() currently returns a *spotify.track not a *spotify.album/playlist

  • So we need to modify that to allow for a return on an album.
  • If we do it for albums then the logic I have currently done for finding playlists can be overhauled aswel

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we should just get rid of internal.Search(), and instead call the API directly and return the PagingObject. Playing albums should have the same logic as playing tracks, just a different queryType. I like your current logic for playlists though. We should keep that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for finding a playlist by name already exists for spotify playlist show, so we might be able to steal that code and use it here

internal/play/play_test.go Outdated Show resolved Hide resolved
internal/play/play_test.go Outdated Show resolved Hide resolved
Threpio and others added 4 commits July 20, 2021 17:57
Co-authored-by: Brian Strauch <bstrauch24@gmail.com>
Co-authored-by: Brian Strauch <bstrauch24@gmail.com>
Co-authored-by: Brian Strauch <bstrauch24@gmail.com>
@Threpio
Copy link
Contributor Author

Threpio commented Jul 21, 2021

@brianstrauch - PR for commands that would show how we can use the Spotify library.
I will split the commands up to do searchPlaylists, searchAlbums and searchTracks

The tests pass but I am not sure they are done correctly

Copy link
Owner

@brianstrauch brianstrauch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome! I was just thinking about how much I needed these changes earlier today 😄

Only two changes left to make before we merge:

  1. We should be passing flag values directly into the p() and Play() functions, so we can unit test all of the logic with the mock API.
  2. Logic is duplicated between the p() and Play() functions, let's only write it once, in Play(). p() can call Play()

internal/p/p.go Show resolved Hide resolved
internal/p/p.go Outdated Show resolved Hide resolved
internal/p/p_test.go Outdated Show resolved Hide resolved
internal/p/p_test.go Outdated Show resolved Hide resolved
internal/p/p_test.go Outdated Show resolved Hide resolved
internal/play/play.go Show resolved Hide resolved
internal/play/play_test.go Outdated Show resolved Hide resolved
internal/play/play_test.go Outdated Show resolved Hide resolved
internal/play/play_test.go Outdated Show resolved Hide resolved
internal/errors.go Outdated Show resolved Hide resolved
Threpio and others added 9 commits July 21, 2021 17:58
Co-authored-by: Brian Strauch <bstrauch24@gmail.com>
Co-authored-by: Brian Strauch <bstrauch24@gmail.com>
Co-authored-by: Brian Strauch <bstrauch24@gmail.com>
Co-authored-by: Brian Strauch <bstrauch24@gmail.com>
Co-authored-by: Brian Strauch <bstrauch24@gmail.com>
Co-authored-by: Brian Strauch <bstrauch24@gmail.com>
Co-authored-by: Brian Strauch <bstrauch24@gmail.com>
Co-authored-by: Brian Strauch <bstrauch24@gmail.com>
Co-authored-by: Brian Strauch <bstrauch24@gmail.com>
Copy link
Owner

@brianstrauch brianstrauch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: I'm merging brianstrauch/spotify#9 tonight and releasing v0.7.0... just to keep things moving. Just a few fixes left on this PR.

internal/p/p_test.go Outdated Show resolved Hide resolved
internal/errors.go Outdated Show resolved Hide resolved
@brianstrauch
Copy link
Owner

Hey @Threpio, how's this coming along?

@Threpio
Copy link
Contributor Author

Threpio commented Jul 26, 2021

Was away for the weekend - apologies.

Will have another update by this evening (CET)

@Threpio
Copy link
Contributor Author

Threpio commented Jul 26, 2021

I won't be able to complete this for a week or so because of prior commitments - If you want to run with it then fire away!

@Threpio Threpio marked this pull request as ready for review July 30, 2021 13:12
@Threpio
Copy link
Contributor Author

Threpio commented Jul 30, 2021

Done a couple of tests locally and it seems that all the new functionality is done correctly - Still intermittently getting the previous song shown when selecting a playlist...

EDIT:
I would like for this to be a squash commit considering I mucked the git up a whole load.

@brianstrauch
Copy link
Owner

@Threpio Thanks, I'll take a look later today! ... and no worries, squash is the default for this repo 😄

Copy link
Owner

@brianstrauch brianstrauch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, I'll make a few touch-ups and try to fix the issue you mentioned above! Thanks again for the PR!

@brianstrauch brianstrauch merged commit a48566e into brianstrauch:master Aug 1, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants