Check-in [fe19fd3202]
Overview
Comment: | Weighted selection of available stream urls from Dirble API. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
fe19fd3202aae4c8e3d3e307f95a074e |
User & Date: | mario on 2015-05-15 21:52:19 |
Other Links: | manifest | tags |
Context
2015-05-15
| ||
22:48 | Update Dirble comments. check-in: a906512c8d user: mario tags: trunk | |
21:52 | Weighted selection of available stream urls from Dirble API. check-in: fe19fd3202 user: mario tags: trunk | |
17:58 | Add ahttp.fix_url() for dirble `website` addresses. check-in: 96d86cc203 user: mario tags: trunk | |
Changes
Modified channels/dirble.py from [76274f66da] to [55aaf2e944].
︙ | ︙ | |||
78 79 80 81 82 83 84 | self.api("category/{}/stations".format(self.catmap.get(cat, 0)), all=1)# per_page=200 won't work ] # Extract rows def unpack(self, r): | | > > > > > > > > > > > > > > > > > > > > < | > > | 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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | 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 if len(r.get("streams", [])): s = r["streams"][0] # select "best" stream if there are alternatives if len(r["streams"]) > 1: for alt in r["streams"]: # weight format with bitrate cur_q = self.format_q.get( s["content_type"].strip(), "0.9") \ * s.get("bitrate", 32) alt_q = self.format_q.get(alt["content_type"].strip(), "0.9") \ * alt.get("bitrate", 32) # swap out for overall better score if alt_q > cur_q: s = alt #log.DATA_BETTER_STREAM(s, "βFROMβ", r) # fix absent audio type if s["content_type"] == "?": s["content_type"] == "audio/mpeg" else: return {} # rename fields return dict( genre = " ".join(c["slug"] for c in r["categories"]), title = r["name"], playing = "{} {}".format(r.get("country"), r.get("description")), homepage = ahttp.fix_url(r["website"]), url = s["stream"], format = s["content_type"].strip(), bitrate = s["bitrate"], # img = r["image"]["image"]["thumb"]["url"], # CDN HTTPS trip up requests.get state = self.state_map[int(s["status"])] if s["status"] in [0,1,2] else "", deleted = s.get("timedout", False), ) state_map = ["gtk-media-pause", "gtk-media-next", "gtk-media-rewind"] format_q = {"?":0.75, "audio/mpeg":1.0, "audio/aac":1.25, "audio/aacp":1.35, "audio/ogg":1.50} # Patch API url together, send request, decode JSON list def api(self, method, **params): params["token"] = conf.dirble_api_key or self.key try: # HTTP request and JSON decoding take a while |
︙ | ︙ |