Index: channels/radiotray.py ================================================================== --- channels/radiotray.py +++ channels/radiotray.py @@ -1,14 +1,15 @@ +# encoding: utf-8 # api: streamtuner2 # title: RadioTray hook # description: Allows to bookmark stations to RadioTray/NG -# version: 0.7 +# version: 0.8 # type: feature # category: bookmarks # depends: deb:python-dbus, deb:streamtuner2, deb:python-xdg # config: -# { name: radiotray_map, type: select, value: "group", select: 'root|group|asis|play', description: 'Map genres to default RadioTray groups, or just "root".' } +# { name: radiotray_map, type: select, value: "group", select: 'root|group|category|asis|channel|play', description: 'Map genres to default RadioTray groups, or just "root".' } # url: http://radiotray.sourceforge.net/ # priority: extra # id: streamtuner2-radiotray # extraction-method: xml # pack: radiotray.py @@ -17,10 +18,18 @@ # Adds a context menu "Add in RadioTray.." for bookmarking. # Should work with old Radiotray and Radiotray-NG. It will # now probe for RTNG first and prefers to edit its bookmark # list. # +# The mapping options: +# · "root" is just meant for the old Radiotray format. +# · "group" tries to fit genres onto existing submenus. +# · "category" maps just the channel category. +# · "channel" instead creates `Shoutcast - Rock` entries. +# · "asis" will transfer the literal station genre. +# · "play" is unused. +# # With the old Radiotry this plugin will fall back to just # playUrl() until the addRadio remote call is added. # The patch for radiotray/DbusFacade.py would be: # + # + @dbus.service.method('net.sourceforge.radiotray') @@ -125,21 +134,20 @@ # send to def share(self, *w): row = self.parent.row() if row: - group = self.map_group(row.get("genre")) + group = self.map_group(row.get("genre", self.parent.channel().current)) log.PROC("mapping genre '%s' to RT group '%s'" % (row["genre"], group)) # Radiotray-NG try: self.radiotray_ng().add_radio(row["title"], row["url"], group) except: try: cfg = self.radiotray_ng().get_config() self.save_rtng_json(cfg, row, group) - #time.sleep(0.350) self.radiotray_ng().reload_bookmarks() self.parent.status("Exported to Radiotray. You may need to use Preferences > Reload Bookmarks.") except Exception as e: log.ERR("radiotray-ng not active", e) @@ -156,19 +164,20 @@ # manually add to RTNG bookmarks.json def save_rtng_json(self, cfg, row, group): fn = json.loads(cfg)["bookmarks"] j = json.load(open(fn, "r")) found = None + group = {"root": "streamtuner2", "": "streamtuner2"}.get(group, group) # find existing group for g in j: - if g["group"] == group or g["group"] == row["genre"]: + if g["group"] == group: found = g break # else add new group if not found: found = { - "group": row["genre"], + "group": group, "image": None, "stations": [] } j.append(found) # overwrite bookmarks.json @@ -182,14 +191,19 @@ # match genre to RT groups def map_group(self, genre): if not genre or not len(genre) or conf.radiotray_map == "root": return "root" + if conf.radiotray_map == "channel": + return "%s - %s" % (self.parent.current_channel, self.parent.channel().current) if conf.radiotray_map == "asis": return genre # if RadioTray itself can map arbitrary genres to its folders if conf.radiotray_map == "play": raise NotImplementedError("just call .playUrl()") + if conf.radiotray_map == "category": + genre = self.parent.channel().current + # else "group" - find first fit for station genre map = { "Jazz": "jazz|fusion|swing", "Latin": "latin|flamenco|tango|salsa|samba", "Classic Rock": "classic rock", "Classical": "classic|baroque|opera|symphony|piano|violin",