Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Commit

Permalink
exposed updated_after for playlist/song listing [closes #533]
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-weber committed Jun 15, 2017
1 parent 522487f commit 4c17e05
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
16 changes: 10 additions & 6 deletions gmusicapi/clients/mobileclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ def login(self, email, password, android_id, locale='en_US'):

return True

# TODO expose max/page-results, updated_after, etc for list operations
# TODO expose max/page-results, etc for list operations

def get_all_songs(self, incremental=False, include_deleted=None):
def get_all_songs(self, incremental=False, include_deleted=None, updated_after=None):
"""Returns a list of dictionaries that each represent a song.
:param incremental: if True, return a generator that yields lists
Expand All @@ -161,6 +161,8 @@ def get_all_songs(self, incremental=False, include_deleted=None):
presenting a loading bar to a user.
:param include_deleted: ignored. Will be removed in a future release.
:param updated_after: a datetime.datetime; defaults to unix epoch.
If provided, deleted songs may be returned.
Here is an example song dictionary::
Expand Down Expand Up @@ -209,7 +211,7 @@ def get_all_songs(self, incremental=False, include_deleted=None):
"""

tracks = self._get_all_items(mobileclient.ListTracks, incremental)
tracks = self._get_all_items(mobileclient.ListTracks, incremental, updated_after=updated_after)

return tracks

Expand Down Expand Up @@ -387,14 +389,16 @@ def get_stream_url(self, song_id, device_id=None, quality='hi'):

return self._make_call(mobileclient.GetStreamUrl, song_id, device_id, quality)

def get_all_playlists(self, incremental=False, include_deleted=None):
def get_all_playlists(self, incremental=False, include_deleted=None, updated_after=None):
"""Returns a list of dictionaries that each represent a playlist.
:param incremental: if True, return a generator that yields lists
of at most 1000 playlists
as they are retrieved from the server. This can be useful for
presenting a loading bar to a user.
:param include_deleted: ignored. Will be removed in a future release.
:param updated_after: a datetime.datetime; defaults to unix epoch
If provided, deleted playlists may be returned.
Here is an example playlist dictionary::
Expand All @@ -416,7 +420,7 @@ def get_all_playlists(self, incremental=False, include_deleted=None):
}
"""

playlists = self._get_all_items(mobileclient.ListPlaylists, incremental)
playlists = self._get_all_items(mobileclient.ListPlaylists, incremental, updated_after=updated_after)

return playlists

Expand Down Expand Up @@ -1962,7 +1966,7 @@ def _get_all_items_incremental(self, call, **kwargs):
if 'userPreferences' in item:
if item['userPreferences'].get('subscribed', False):
items.append(item)
elif not item.get('deleted', False):
elif ('updated_after' in kwargs) or (not item.get('deleted', False)):
items.append(item)

# Conditional prevents generator from yielding empty
Expand Down
20 changes: 19 additions & 1 deletion gmusicapi/test/server_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from builtins import * # noqa

from collections import namedtuple
import datetime
from hashlib import md5
import itertools
import os
Expand All @@ -20,7 +21,7 @@
from decorator import decorator
from proboscis.asserts import (
assert_true, assert_equal, assert_is_not_none,
assert_raises, Check
assert_raises, assert_not_equal, Check,
)
from proboscis import test, before_class, after_class, SkipTest
import requests
Expand Down Expand Up @@ -761,6 +762,14 @@ def mc_change_uploaded_song_title_fails(self):
def mc_list_songs_inc_equal(self):
self.assert_list_inc_equivalence(self.mc.get_all_songs)

@song_test
def mc_list_songs_updated_after(self):
songs_last_minute = self.mc.get_all_songs(updated_after=datetime.datetime.now() - datetime.timedelta(minutes=1))
assert_not_equal(len(songs_last_minute), 0)

all_songs = self.mc.get_all_songs()
assert_not_equal(len(songs_last_minute), len(all_songs))

@podcast_test
def mc_list_podcast_series_inc_equal(self):
self.assert_list_inc_equivalence(self.mc.get_all_podcast_series)
Expand Down Expand Up @@ -832,6 +841,15 @@ def assert_public_equal(plid, public):
self.mc.edit_playlist(self.playlist_ids[0], public=True)
assert_public_equal(self.playlist_ids[0], True)

@playlist_test
def mc_list_playlists_updated_after(self):
pls_last_minute = self.mc.get_all_playlists(updated_after=datetime.datetime.now() - datetime.timedelta(minutes=1))
assert_not_equal(len(pls_last_minute), 0)
print(pls_last_minute)

all_pls = self.mc.get_all_playlists()
assert_not_equal(len(pls_last_minute), len(all_pls))

@retry(tries=3)
def _mc_assert_ple_position(self, entry, pos):
"""
Expand Down

0 comments on commit 4c17e05

Please sign in to comment.