Skip to content

Commit 8dc8bac

Browse files
Merge pull request #31 from Keeper-of-the-Keys/sc-pagination
Add support for pagination in the SoundCloud API.
2 parents d7a1ced + 44e499b commit 8dc8bac

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/gpodder/plugins/soundcloud.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,26 @@ def get_tracks(self, feed, channel):
126126

127127
json_url = ('https://api.soundcloud.com/users/%(user)s/%(feed)s.'
128128
'json?consumer_key=%'
129-
'(consumer_key)s&limit=200'
129+
'(consumer_key)s&limit=200&linked_partitioning=1'
130130
% {"user": self.get_user_id(),
131131
"feed": feed,
132132
"consumer_key": CONSUMER_KEY})
133133

134134
logger.debug('get_tracks url: %s', json_url)
135135

136136
json_tracks = json.loads(util.urlopen(json_url).read().decode('utf-8'))
137-
tracks = [track for track in json_tracks if track['streamable'] or track['downloadable']]
137+
tracks = [track for track in json_tracks['collection'] if track['streamable'] or track['downloadable']]
138+
139+
try:
140+
while(json_tracks['next_href'] != ''):
141+
next_url = json_tracks['next_href']
142+
logger.debug('get page: %s', next_url)
143+
json_tracks = json.loads(util.urlopen(next_url).read().decode('utf-8'))
144+
tracks += [track for track in json_tracks['collection'] if track['streamable'] or track['downloadable']]
145+
except:
146+
logger.debug('No pagination/end of pagination for this feed.')
147+
148+
logger.debug('Starting to add %d tracks, this may take a while.', len(tracks))
138149

139150
self.cache['episodes'] = { episode.guid:
140151
{ "filesize": episode.file_size,

0 commit comments

Comments
 (0)