Check-in [57af601fa7]
Overview
Comment: | Bring back dirble channel. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
57af601fa7d9c5db23399e4dfa19cb62 |
User & Date: | mario on 2015-04-30 20:29:58 |
Other Links: | manifest | tags |
Context
2015-04-30
| ||
20:30 | Fix typos in myoggradio help page. check-in: 8e6178d3e3 user: mario tags: trunk | |
20:29 | Bring back dirble channel. check-in: 57af601fa7 user: mario tags: trunk | |
06:24 | Update HTML manual with current page set. check-in: 40900d9702 user: mario tags: trunk | |
Changes
Added channels/dirble.py version [0aabd4d53a].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | # encoding: UTF-8 # api: streamtuner2 # title: Dirble # description: Song history tracker for Internet radio stations. # 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. } # png: # iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAA3NCSVQICAjb4U/gAAACP0lE # QVQokVVSO0+UURA9M/d+jyWbBVcQFSQhPqJSYBRFA5pVoFGURApjYYWtvYUNP8FKOwsttDFq # jMTEWEiDD0wETNSIxJC46yqEsCz7ve4di28hOO2cMzNnzqH+azcBACAiAgQg1EsAQESwCYBA # pwCxNowjI1v7YGLH0Y5iSQFhJEprYjZxtG13+/lCb2dOWxBBABiTrJSLkx8+z/xa0yRutml4 # sC9X+qqJyFqTzTcPDfTup2p5NSTFSintOFmvZ7iv687Dl8/ezufaGgcHT2enKjpdbxMbRcnr # x09uT36JfJ9FWLtnCoWxkRM3Ris/F//Mlpce3LtvSsW6BhAxs5VgtVqtxUaJQCqPnr4ItXfr # Uve5fVM/PpbZzXgNniYCEaUs1spxdKIdBUvEsr4282nu29nuowdbmov2ytXRxukJBhGwwRCI # 1F9pRbSjlytheTnY3t6iHCcMo9BYxtai1AymjSlRbII4YUcRAQQiMKWO0Vbahk2An3H9jJvU # IhEQCKD/TiJiZsXEzMxMYSy78rnOVvf34lISJ8R1pwGqpyCJkvUgCiyziFjJ5Fv7Tx5r07WJ # udJajRVDAI30TUQilG1qPry3I/Y9BThubmigb+R4x8L0m1fz5Ti3h0QE0ClcQCA+dflCz0VD # 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. # import json from config import * from channels import * import ahttp # class dirble (ChannelPlugin): # control flags has_search = False listformat = "srv" titles = dict(listeners=False, playing="Location") base = "http://api.dirble.com/v2/{}" # Retrieve cat list and map def update_categories(self): cats = [] for row in self.api("categories/tree"): print row cats += [row["title"]] self.catmap[row["title"]] = row["id"] if row.get("children"): cats += [[c["title"] for c in row["children"]]] for c in row["children"]: self.catmap[c["title"]] = c["id"] self.categories = cats # Fetch entries def update_streams(self, cat, search=None): return [ self.unpack(r) for r in self.api("category/{}/stations".format(self.catmap.get(cat, 0)), all=1)# per_page=200 won't work ] # Extract rows def unpack(self, r): # find stream (might select on `bitrate` or `format` if available) if len(r.get("streams", [])): s = r["streams"][0] else: return {} # rename fields return dict( genre = " ".join(c["slug"] for c in r["categories"]), title = r["name"], playing = "{country} {description}".format(**r), 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", deleted = s["timedout"], ) # Patch API url together, send request, decode JSON list def api(self, method, **params): params["token"] = conf.dirble_api_key try: 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: del r[int(conf.max_streams):] except Exception as e: log.ERR("Dirble API retrieval failure:", e) r = [] return r |