-
-
Notifications
You must be signed in to change notification settings - Fork 108
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
Add support for streaming #336
Conversation
I see that the travis-ci tests are failing with the following error: I don't think this is something I can fix myself, right? Thanks in advance. |
Yeah, the CI fails for PRs, see #171. Do they pass for you locally? |
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.
Thanks very much for the PR! I'll review it in more detail later.
I tested both implementations by retrieving my recent tracks since January 1st of this year.
Please could you share some example code for this?
stream=True (which I made the default)
I think I'd like to be on the cautious side and start off with stream=False
as the default, so as not to have any surprising API changes (for example, user.get_loved_tracks(limit=20)
returns a 20-item list now, and a generator with this PR).
Then we can release it with a minor bump, and announce it will become the default in the next major release, where we can flip the default to stream=True
. That way nothing will break for people pinning by major version.
We have a major, breaking release coming up soon anyway, as Python 3.5 will be EOL in September and dropped, so it won't be too long to wait.
What do you think?
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
import time
from datetime import datetime
import pylast
start = time.time()
print(start)
# You have to have your own unique two values for API_KEY and API_SECRET
# Obtain yours from https://www.last.fm/api/account/create for Last.fm
API_KEY = "******************************"
API_SECRET = "***************************"
# In order to perform a write operation you need to authenticate yourself
username = "*************"
password_hash = pylast.md5("**********")
network = pylast.LastFMNetwork(api_key=API_KEY, api_secret=API_SECRET,
username=username, password_hash=password_hash)
tracks = network.get_user(username=username).get_recent_tracks(
time_from=int(datetime(year=2020, month=1, day=1).timestamp()),
cacheable=False, stream=False # or stream=True
)
for track in tracks:
pass
end = time.time()
print(end)
print(end-start) I took some shortcuts with this example since I only made some scratches in PyCharm. I ran both examples locally watched the memory usage of the python process via system monitor/taskmanager on Windows.
Couldn't agree more, I didn't really think about it other than my own use case. Compatibility-wise it's a much better choice to make the change more gradually. I'll make the change and update the pull request. To finish this comment, I would like to say thank you to you and the other contributers, since this wrapper made it really easy for me to implement my personal use case. |
I made the changes as requested. Is there anything else I should do? |
Please could you resolve the conflicts and I'll take another look? Thanks! |
src/pylast/__init__.py
Outdated
return _get_artist_tracks() if stream else list(_get_artist_tracks()) | ||
|
||
def get_friends(self, limit=50, cacheable=False, stream=False): | ||
def get_friends(self, limit=50, cacheable=False): |
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.
This lost its stream=False
in the merge
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.
Thx, fixing it now.
src/pylast/__init__.py
Outdated
""" | ||
Returns this user's loved track as a sequence of LovedTrack objects in | ||
reverse order of their timestamp, all the way back to the first track. | ||
|
||
If limit==None, it will try to pull all the available data. | ||
If stream=True, it will yield tracks as soon as a page has been retrieved. | ||
If stream=False, it will yield tracks as soon as a page has been retrieved. |
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.
Should this still say If stream=True, ...
?
We can also remove the stream=False
from test calls, it has no effect.
I made a copy of your branch and resolved conflicts and changed the things I just commented above: https://github.com/pylast/pylast/tree/streaming (sorry for accidentally pushing to your branch, I undid the commit) And all the tests passed except for one:
https://github.com/pylast/pylast/runs/1623179772?check_suite_focus=true |
I'll look into it right away |
I originally replaced |
That fails with another
Let's leave it with the original in this PR as there's enough going on here, and please could you open a separate PR to change it? Thanks! |
Sorry, should've read that, don't know why I didn't. Reverted it to the original |
I tested locally and all tests pass. Let's merge and I'll get a release out in the next week or so. Thank you! |
Changes proposed in this pull request:
I tested both implementations by retrieving my recent tracks since January 1st of this year. With stream=False the memory usage was 150mb and rising while with stream=True (which I made the default) the memory usage stayed between 28 and 35mb.