-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spotify: Play owned/starred playlists by name/by frontend #11887
Conversation
To fix the requirements problem in the build you need to checkout your branch in a virtualenv, pip -e install it and rerun the gen_requirements script. You can't just edit the txt file directly since that isn't what tox does. |
@andrey-git Could you review my PR please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work!
I'm no oficial reviewer, but here is some feedback.
REQUIREMENTS = ['https://github.com/happyleavesaoc/spotipy/' | ||
'archive/%s.zip#spotipy==2.4.4' % COMMIT] | ||
REQUIREMENTS = ['https://github.com/plamere/spotipy/' | ||
'archive/master.zip#spotipy==2.4.4'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked and spotipy is available in pypi in version 2.4.4
No need for tor this hack...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is needed, because the current PyPi 2.4.4 package does not include this PR: spotipy-dev/spotipy#182
The pypi package is from January 2017.
At least I wanted to upgrade from @happyleavesaoc repo to the original master repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just download the code from pypi and GitHub
This package is 💩... same version and different content :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, definitely track the spotipy
release instead of my fork. w.r.t. pypi version, issue has been open for awhile: spotipy-dev/spotipy#211
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe contacting @plamere directly through email ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have the power to merge :)
But the guidelines are well defined: only pypi packages in requirements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That means I cannot improve a component which is using a GitHub repo since years? Don't touch that component otherwise you are forced to persuade the pypi owner to update the package or maintain your own package for us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reasoning is that the master.zip can change and break stuff, while pypi packages will perdure in time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great - Then I will revert to @happyleavesaoc commit .zip 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
def save(self): | ||
"""Save playlists.""" | ||
with open(self.hass.config.path(PERSISTENCE), 'wt') as file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Over complicated and "file" is a dangerous variable name, I suggest:
with open(self.hass.config.path(PERSISTENCE), 'wt') as p_file:
json.dump(self.playlist,p_file)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you suggest how you would simplify it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
look at the code in my comment ...
path = self.hass.config.path(PERSISTENCE) | ||
if not os.path.isfile(path): | ||
return {} | ||
with open(path) as file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Over complicated and "file" is a dangerous variable name, I suggest:
with open(path) as p_file:
return json.load(p_file)
if playlist is not None: | ||
self.playlists[playlist['id']] = playlist | ||
self.save() | ||
self.playlists = self.load() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this need to reload a playlist that was just saved ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be removed, but I just wanted to avoid any differences between json and class data. Which approach would you choose? Just load once at init?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't save() enough ?
from your code there is no difference...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then I need to call load() on init, because the idea was to save it locally to avoid all playlists will be discovered at each restart of HASS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be a semantic issue... are you updating the persistent file or the playlist variable ? maybe splitting update into two different methods ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not like that?
https://gist.github.com/tringler/a48e8932e7e2692ce1546364df4cded8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to indent lines 20:21 and 25:26, but that looks good
def save(self): | ||
"""Save playlists.""" | ||
with open(self.hass.config.path(PERSISTENCE), 'wt') as p_file: | ||
json.dump(self.playlist, yp_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined name 'yp_file'
|
||
def save(self): | ||
"""Save playlists.""" | ||
with open(self.hass.config.path(PERSISTENCE), 'wt') as p_file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local variable 'p_file' is assigned to but never used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the approach is wrong. We should not fetch playlists on every update. That's too intense. I also don't think that we should store the playlists on disk.
They should be fetched on demand when the user passes a playlist to play_media
Also please get rid of the view. I think that if we want such a view, we should make it part of the media player component (but in a separate PR)
@balloob If I fetch the playlists at init of the component I need to restart HASS everytime I update the playlists in Spotify. If I fetch it on demand at play_media action I cannot show it on the frontend as a list. If I not store it on disk, I need to use the state machine which is also not wanted. Where I should store the data else? Which approach should I choose? I agree that the view should be moved to the media_player component. |
We should not store playlists at all. The HTTP view that the media player will register can just get the live data upon request and then pass it on to the client. That way it is only queried when the user needs it (because they opened the media player more info dialog). When the user passes a playlist to Neither use case requires us to store playlists. |
@balloob Allright. I think it's the best if I close that PR. |
Description:
This PR allows you to play owned/starred playlists by name (or uid/uri) or by frontend without the playlist uid.
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io# home-assistant/home-assistant.io#4447
Example entry for
configuration.yaml
(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
tox
run successfully. Your PR cannot be merged unless tests passREQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.If the code does not interact with devices:
tox
run successfully. Your PR cannot be merged unless tests pass