Index: channels/radiobrowser.py ================================================================== --- channels/radiobrowser.py +++ channels/radiobrowser.py @@ -1,10 +1,10 @@ # encoding: UTF-8 # api: streamtuner2 # title: RadioBrowser # description: Community collection of stations; votes, clicks, homepage links. -# version: 0.4 +# version: 0.5 # type: channel # url: http://www.radio-browser.info/ # category: radio # priority: optional # config: @@ -81,10 +81,11 @@ # hook menu def init2(self, parent): if parent: uikit.add_menu([parent.streammenu, parent.streamactions], "Share in Radio-Browser", self.submit, insert=5) + parent.hooks["play"].append(self.click) # votes, and tags, no countries or languages def update_categories(self): params = {"order":"name", "reverse":"false", "hidebroken":"true"} self.categories = list(self.pricat) + [grp["name"] for grp in filter( @@ -159,10 +160,22 @@ try: return json.loads(j, strict=False) # some entries contain invalid character encodings except: return [] + + # callback for general stream play event + def click(self, row, channel): + if not channel == self: + return + # fetch uuid, then register click + uuid = self.api("stations/byurl", {"url": row.get("url")}) + if uuid: + if isinstance(uuid, list): # just vote on the first entry + uuid = uuid[0] + log.PROC_CLICK_COUNT(self.api("url/{}".format(uuid["stationuuid"]))) + # Add radio station to RBI def submit(self, *w): cn = self.parent.channel() row = cn.row()