Internet radio browser GUI for music/video streams from various directory services.

⌈⌋ branch:  streamtuner2


Check-in [b5f2654777]

Overview
Comment:Support for RT-NG direct bookmarks.json saving.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:b5f2654777f66c9ede49d0e48a0141656e69e173
User & Date: mario on 2018-12-17 16:49:08
Other Links: manifest | tags
Context
2018-12-17
16:50
Add debug/logging to plugin dependency checks. check-in: 4b3498e020 user: mario tags: trunk
16:49
Support for RT-NG direct bookmarks.json saving. check-in: b5f2654777 user: mario tags: trunk
2018-12-16
20:06
Fix cmd= parameter handling. check-in: 6cea64726f user: mario tags: trunk
Changes

Modified channels/radiotray.py from [530caa9d50] to [5e56c67925].

     1         -# api: dbus
            1  +# api: streamtuner2
     2      2   # title: RadioTray hook
     3      3   # description: Allows to bookmark stations to RadioTray/NG
     4         -# version: 0.5
            4  +# version: 0.6
     5      5   # type: feature
     6      6   # category: bookmarks
     7      7   # depends: deb:python-dbus, deb:streamtuner2, deb:python-xdg
     8      8   # config:
     9      9   #   { name: radiotray_map, type: select, value: "group", select: 'root|group|asis|play', description: 'Map genres to default RadioTray groups, or just "root".' }
    10     10   # url: http://radiotray.sourceforge.net/
    11     11   # priority: extra
    12     12   # id: streamtuner2-radiotray
    13     13   # extraction-method: xml
    14     14   # pack: radiotray.py
    15     15   # fpm-prefix: /usr/share/streamtuner2/channels/
    16     16   #
    17         -# Adds a context menu "Keep in RadioTray.." for bookmarking.
    18         -# Until a newer version exposes addRadio(), this plugin
    19         -# will fall back to just playUrl().
           17  +# Adds a context menu "Add in RadioTray.." for bookmarking.
           18  +# Should work with old Radiotray and Radiotray-NG. It will
           19  +# now probe for RTNG first and prefers to edit its bookmark
           20  +# list.
    20     21   #
           22  +# With the old Radiotry this plugin will fall back to just
           23  +# playUrl() until the addRadio remote call is added.
    21     24   # The patch for radiotray/DbusFacade.py would be:
    22     25   #   +
    23     26   #   +    @dbus.service.method('net.sourceforge.radiotray')
    24     27   #   +    def addRadio(self, title, url, group="root"):
    25     28   #   +        self.dataProvider.addRadio(title, url, group)
    26     29   #
    27         -# Displays existing radiotray stations in ST2 bookmarks
    28         -# category as read from ~/.local/share/radiotray/bookmarks.xml.
           30  +# Displays existing radiotray stations in ST2 bookmarks (from
           31  +# either old bookmarks.xml or RT-NG bookmarks.json)
    29     32   #
    30     33   # This plugin may be packaged up separately.
    31     34   #
    32     35   
    33     36   from config import *
    34     37   from channels import *
    35     38   from uikit import uikit
................................................................................
   122    125   
   123    126       # send to 
   124    127       def share(self, *w):
   125    128           row = self.parent.row()
   126    129           if row:
   127    130               group = self.map_group(row.get("genre"))
   128    131               log.PROC("mapping genre '%s' to RT group '%s'" % (row["genre"], group))
          132  +
   129    133               # Radiotray-NG
   130    134               try:
   131    135                   self.radiotray_ng().add_radio(row["title"], row["url"], group)
   132    136               except:
   133         -                log.ERR("rtng dbus inactive")
   134         -                # RadioTray doesn't have an addRadio method yet, so just fall back to play the stream URL
          137  +                #try:
          138  +                cfg = self.radiotray_ng().get_config()
          139  +                self.save_rtng_json(cfg, row, group)
          140  +                self.parent.status("Updated RT-NG bookmarks.json. Use Preferences>Reload Bookmarks..")
          141  +                #except:
          142  +                #    log.ERR("radiotray-ng not active")
          143  +
          144  +            # RadioTray doesn't have an addRadio method yet, so just fall back to play the stream URL
          145  +            try:
          146  +                self.radiotray().addRadio(row["title"], row["url"], group)
          147  +            except:
   135    148                   try:
   136         -                    self.radiotray().addRadio(row["title"], row["url"], group)
   137         -                except:
   138    149                       self.radiotray().playUrl(row["url"])
          150  +                except:
          151  +                    log.ERR("radiotry-old not active")
   139    152           pass
          153  +        
          154  +    # manually add to RTNG bookmarks.json
          155  +    def save_rtng_json(self, cfg, row, group):
          156  +        fn = json.loads(cfg)["bookmarks"]
          157  +        j = json.load(open(fn, "r"))
          158  +        found = None
          159  +        # find existing group
          160  +        for g in j:
          161  +            if g["group"] == group or g["group"] == row["genre"]:
          162  +                found = g
          163  +                break
          164  +        # else add new group
          165  +        if not found:
          166  +            found = {
          167  +                "group": row["genre"],
          168  +                "image": None,
          169  +                "stations": []
          170  +            }
          171  +            j.append(found)
          172  +        # overwrite bookmarks.json
          173  +        if found:
          174  +            g["stations"].append({
          175  +                "image": None,
          176  +                "name": row["title"],
          177  +                "url": row["url"]
          178  +            })
          179  +            json.dump(j, open(fn, "w"), indent=4)
   140    180   
   141    181       # match genre to RT groups
   142    182       def map_group(self, genre):
   143    183           if not genre or not len(genre) or conf.radiotray_map == "root":
   144    184               return "root"
   145    185           if conf.radiotray_map == "asis":
   146    186               return genre  # if RadioTray itself can map arbitrary genres to its folders