Index: contrib/radionet.py ================================================================== --- contrib/radionet.py +++ contrib/radionet.py @@ -1,11 +1,11 @@ # encoding: UTF-8 # api: streamtuner2 # title: radio.net # description: Europe's biggest radio platform # url: http://radio.net/ -# version: 1.0 +# version: 1.1 # type: channel # category: radio # png: # iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAt0lEQVR42mNgYGD4r+Ar/F/BDwkD+SBxojBMs1mLPBArgGlFqEEENYMNQNLsukIDYkirAvGu # ABsA1OC6XOP/5f8nwIaYAg0k2gBFsAsgTgcZkvnfDugFEeK9AFKsCPMG0CU6eZJgQ4R1eP8H7LLEivWyFJANQcQCLPBAmkGG4MJohmA6C6QA5gI5OxEUDNII @@ -24,10 +24,11 @@ import time import json import re +import traceback from config import * from channels import * import ahttp import action @@ -96,35 +97,49 @@ self.status(p / 5.5) if html.find('?p={}"'.format(p)) >= 0: html += ahttp.get(self.genre_url.format(urlcat) + "?p={}".format(p)) self.set_key(html) r = [] - + + # fetch JSON + ls_json = re.findall("__CONTEXT_PROVIDER__\s*=\s*(\{.+\});", html) + if ls_json: + try: + return self.from_json(ls_json) + except: + log.error("JSON extraction failed", traceback.format_exc()) + # prefetch images from embedded json (genres and location would also be sourceable from "playables":[…]) imgs = dict(re.findall('\],"id":"(\w+)","logo100x100":"(htt[^"]+)",', html)) #log.DATA(imgs) # top 100 of the most horrible html serializations """ - -
-
-
-
-
- -
-
-
-
KISS FM UK
-
London, United Kingdom / Hits, Pop, R'n'B
-
-
- {"city":"Hanover","country":"Germany","genres":["Pop","80s","Top 40 & Charts"],"id":"ndr2","logo100x100":"https://d3kle7qwymxpcy.cloudfront.net/images/broadcasts/02/33/2262/1/c100.png","logo300x300":"https://d3kle7qwymxpcy.cloudfront.net/images/broadcasts/02/33/2262/1/c300.png","logo630x630":"","name":"NDR 2","type":"STATION"}') +
RDS - Radio + Dimensione Suono
Rome, Italy / Hits, Pop, Top 40 & Charts
+ +
102.7 KIIS FM
Los Angeles, USA / Top 40 & Charts, + Hits
""" rx = re.compile(""" - .*? + ]*\\bhref="(?:https?:)?(?://(?:[\w-]+)\.radio\.net)?/s/([^"]+)/?"> .*? ]+> (\w[^<]+)
\s* ]+> (\w[^/]+) \s+ / \s+ (\w.+?)
""", re.X|re.S ) # extract text fields @@ -141,10 +156,30 @@ url = "urn:radionet:"+href, homepage = "http://www.radio.net/s/{}".format(href), img = imgs.get(href, "https://www.radio.net/favicon.ico"), )); return r + + # process json + def from_json(self, ls_json): + ls = [] + for js in ls_json: + ls += json.loads(js)["data"]["stations"]["playables"] + r = [] + for row in ls: + href = row["id"] + r.append(dict( + name = href, + title = row["name"], + genre = ",".join(row["genres"]), + url = "urn:radionet:"+href, + playing = row.get("city", row.get("country", "-")), + homepage = "http://www.radio.net/s/{}".format(href), + img = row["logo100x100"], + )) + print(row) + return r # api search is gone, now requires to fetch streamUrl from per-radio homepage def resolve_urn(self, row): if row.get("url", "-").find("urn:radionet:") != 0: return