mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-06-19 09:13:53 +00:00
Support after/before in current_user_recently_played
This commit is contained in:
parent
349587ca32
commit
ff7c33e97d
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Added
|
||||
|
||||
- Support for `playlist_cover_image`
|
||||
- Support `after` and `before` parameter in `current_user_recently_played`
|
||||
|
||||
## [2.7.1] - 2020-01-20
|
||||
|
||||
|
||||
@ -759,13 +759,21 @@ class Spotify(object):
|
||||
return self._get('me/top/tracks', time_range=time_range, limit=limit,
|
||||
offset=offset)
|
||||
|
||||
def current_user_recently_played(self, limit=50):
|
||||
def current_user_recently_played(self, limit=50, after=None,
|
||||
before=None):
|
||||
''' Get the current user's recently played tracks
|
||||
|
||||
Parameters:
|
||||
- limit - the number of entities to return
|
||||
- after - unix timestamp in milliseconds. Returns all items
|
||||
after (but not including) this cursor position.
|
||||
Cannot be used if before is specified.
|
||||
- before - unix timestamp in milliseconds. Returns all items
|
||||
before (but not including) this cursor position.
|
||||
Cannot be used if after is specified
|
||||
'''
|
||||
return self._get('me/player/recently-played', limit=limit)
|
||||
return self._get('me/player/recently-played', limit=limit, after=after,
|
||||
before=before)
|
||||
|
||||
def current_user_saved_albums(self, limit=20, offset=0):
|
||||
""" Gets a list of the albums saved in the current authorized user's
|
||||
|
||||
@ -25,6 +25,7 @@ import sys
|
||||
import unittest
|
||||
import warnings
|
||||
import requests
|
||||
from pprint import pprint # noqa
|
||||
|
||||
sys.path.insert(0, os.path.abspath(os.pardir))
|
||||
|
||||
@ -88,6 +89,7 @@ class AuthTestSpotipy(unittest.TestCase):
|
||||
'user-read-private '
|
||||
'user-top-read '
|
||||
'user-follow-modify '
|
||||
'user-read-recently-played '
|
||||
'ugc-image-upload'
|
||||
)
|
||||
|
||||
@ -241,6 +243,25 @@ class AuthTestSpotipy(unittest.TestCase):
|
||||
items = response['items']
|
||||
self.assertTrue(len(items) > 0)
|
||||
|
||||
def test_current_user_recently_played(self):
|
||||
# No cursor
|
||||
res = self.spotify.current_user_recently_played()
|
||||
self.assertTrue(len(res['items']) <= 50)
|
||||
played_at = res['items'][0]['played_at']
|
||||
|
||||
# Using `before` gives tracks played before
|
||||
res = self.spotify.current_user_recently_played(
|
||||
before=res['cursors']['after'])
|
||||
self.assertTrue(len(res['items']) <= 50)
|
||||
self.assertTrue(res['items'][0]['played_at'] < played_at)
|
||||
played_at = res['items'][0]['played_at']
|
||||
|
||||
# Using `after` gives tracks played after
|
||||
res = self.spotify.current_user_recently_played(
|
||||
after=res['cursors']['before'])
|
||||
self.assertTrue(len(res['items']) <= 50)
|
||||
self.assertTrue(res['items'][0]['played_at'] > played_at)
|
||||
|
||||
def test_user_playlist_ops(self):
|
||||
sp = self.spotify
|
||||
# create empty playlist
|
||||
|
||||
Loading…
Reference in New Issue
Block a user