Index: channels/tunein.py ================================================================== --- channels/tunein.py +++ channels/tunein.py @@ -1,15 +1,16 @@ # encoding: UTF-8 # api: streamtuner2 # title: TuneIn # description: Online Radio, Broadcasts, Podcasts per RadioTime API -# version: 0.2 +# version: 0.3 # type: channel # category: radio # url: http://tunein.com/ # config: # { name: radiotime_group, value: music, type: select, select: music|genres, description: Catalogue type as categories. (→ Reload Category Tree) } +# { name: radiotime_maxpages, value: 10, type: int, description: Maximum number of pages. } # priority: default # png: # iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAbpJREFUOI2Nkk9PE1EUxc+ZuTMIaP+KqClxx4dA0jRVgwFM/JPIRv0CunDnxsQ1G4NGvgD7LkiExG5IDHFhDDEmblwRQJG2AVuwMNOZd91QAuUR # e1bvnnfeLzf3PsKioq6Dtf25xsq3Kdf3gkxh9OUis29tWcdm9iPxuvHl62MNQz/a+3uhVl56M647d7sGHOxU8hpFR7Uag9+l+UddAySdWuv0soWR710DXOj93mtDWxQBRTBwq7AcZfte2bK0mQCQ11X0I5lzEW2858BZMXBkZWkGqk8Atk7c # mBhqVCWV2E0MDz9dYLo8ptWbwdrP2aC6nSYhIOck2PiVdDwvfXxox9WqVAcPVtc/jOkm68uf56M/9T4AoAhMq5V06NCc2d+hNAzhwBttPz5q36FxchOT0xT5HwMEvRO1CHITk9MEgHHdfED4z4La9nmQqiY2dNywHY6b++d6h65OhVvVElw3 @@ -82,23 +83,27 @@ }) return r # Fetch OPML, convert outline elements to dicts - def api(self, method, url=None): + def api(self, method): r = [] - opml = ahttp.get(url or self.base + method) - x = ElementTree.fromstring(opml) - # append entries - for outline in x.findall(".//outline"): - outline = dict(outline.items()) - # additional pages - if "key" in outline and outline["key"] == "nextStations": - if len(x) < conf.max_streams: - r = r + self.api(method=None, url=outline["URL"]) - else: - pass - else: - r.append(outline) + # fetch API page + next = self.base + method + max = int(conf.radiotime_maxpages) + while next: + opml = ahttp.get(next) + next = None + x = ElementTree.fromstring(opml) + # append entries + for outline in x.findall(".//outline"): + outline = dict(outline.items()) + # additional pages + if "key" in outline and outline["key"] == "nextStations": + if len(r) < conf.max_streams and max > 0: + next = outline["URL"] + max = max - 1 + else: + r.append(outline) return r