Index: channels/dirble.py ================================================================== --- channels/dirble.py +++ channels/dirble.py @@ -5,11 +5,11 @@ # url: http://dirble.com/ # version: 2.0 # type: channel # category: radio # config: -# { name: dirble_api_key, value: "a0bdd7b8efc2f5d1ebdf1728b65a07ece4c73de5", type: text, description: Required API access key. } +# { name: dirble_api_key, value: "", type: text, description: Alternative API access key. } # png: # iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAA3NCSVQICAjb4U/gAAACP0lE # QVQokVVSO0+UURA9M/d+jyWbBVcQFSQhPqJSYBRFA5pVoFGURApjYYWtvYUNP8FKOwsttDFq # jMTEWEiDD0wETNSIxJC46yqEsCz7ve4di28hOO2cMzNnzqH+azcBACAiAgQg1EsAQESwCYBA # pwCxNowjI1v7YGLH0Y5iSQFhJEprYjZxtG13+/lCb2dOWxBBABiTrJSLkx8+z/xa0yRutml4 @@ -22,35 +22,41 @@ # RKwUE5mgOvtu8u7z9wsVsyPPrBxfayqMjVtrMrmmI4f27swqkVS+GGMqy39nvy+W1uGxKL+h # u+uAt1KkwvVxAGJsEEWxEWzGm4iV8l1HM9K0BmEkrP8BlhoAUfmOxecAAAAASUVORK5CYII= # priority: optional # documentation: http://dirble.com/developer/api # -# Hmm ok, the new v2 API isn't so bad after all. -# It actually contains streaming urls, and even -# station homepages now. -# -# · No idea what status: or timedout: signify. -# · Stream alternatives aren't yet sorted. -# · Leave favicons to regular behaviour, -# station banners are seemingly inaccessible. -# +# +# Server responses take a few seconds, and JSON +# decoding is surprisingly slow. import json from config import * from channels import * import ahttp -# +# Dirble +# +# Hmm ok, the new v2 API isn't so bad after all. +# It actually contains streaming urls, and even +# station homepages now. +# +# · No idea what status: or timedout: mean, +# just mapped to `deleted` and `status` +# · Stream alternatives aren't yet sorted. +# · Leave favicons to regular behaviour, +# station banners are not accessible per CDN. +# class dirble (ChannelPlugin): # control flags has_search = False listformat = "srv" titles = dict(listeners=False, playing="Location") base = "http://api.dirble.com/v2/{}" + key = "a0bdd7b8efc2f5d1ebdf1728b65a07ece4c73de5" # Retrieve cat list and map def update_categories(self): cats = [] @@ -91,27 +97,31 @@ homepage = r["website"], url = s["stream"], format = s["content_type"], bitrate = s["bitrate"], # img = r["image"]["image"]["thumb"]["url"], # CDN HTTPS trip up requests.get - status = "" if s["status"] else "gtk-stop", + state = self.state_map[int(s["status"])] if s["status"] in [0,1,2] else "", deleted = s["timedout"], ) + + state_map = ["gtk-media-pause", "gtk-media-next", "gtk-media-rewind"] # Patch API url together, send request, decode JSON list def api(self, method, **params): - params["token"] = conf.dirble_api_key + params["token"] = conf.dirble_api_key or self.key try: + # HTTP request and JSON decoding take a while r = ahttp.get(self.base.format(method), params) r = json.loads(r) if isinstance(r, dict) and "error" in r: log.ERR(r["error"]) raise Exception - if len(r) > conf.max_streams: + # cut down stream list + if len(r) > int(conf.max_streams): del r[int(conf.max_streams):] except Exception as e: log.ERR("Dirble API retrieval failure:", e) r = [] return r