Skip to content
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

Fix radio.de API limitation of 100 rows #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions resources/lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class RadioApi():
USER_AGENT = 'XBMC Addon Radio'

PLAYLIST_PREFIXES = ('m3u', 'pls', 'asx', 'xml')

MAX_ROWS = 100

def __init__(self, language='english', user_agent=USER_AGENT):
self.set_language(language)
Expand Down Expand Up @@ -90,11 +92,27 @@ def get_stations_by_category(self, category_type, category_value):
if not category_type in self.get_category_types():
raise ValueError('Bad category_type')
path = 'menu/broadcastsofcategory'
param = {
'category': '_%s' % category_type,
'value': category_value,
}
stations = self.__api_call(path, param)
start = 0
fetched_all_stations = False
stations = []
while not fetched_all_stations:
param = {
'category': '_%s' % category_type,
'value': category_value,
'start': str(start),
'rows': str(RadioApi.MAX_ROWS),
}
fetched_stations = self.__api_call(path, param)
num_fetched_stations = len(fetched_stations)

if num_fetched_stations == 0:
fetched_all_stations = True
else:
start += num_fetched_stations
stations += fetched_stations

self.log("get_stations_by_category Fetched " + str(len(stations)) + " stations.")

return self.__format_stations(stations)

def search_stations_by_string(self, search_string):
Expand Down