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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

20


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
...
122
123
124
125
126
127
128

129
130
131
132
133






134
135
136
137

138


139



























140
141
142
143
144
145
146
# api: dbus
# title: RadioTray hook
# description: Allows to bookmark stations to RadioTray/NG
# version: 0.5
# 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".' }
# url: http://radiotray.sourceforge.net/
# priority: extra
# id: streamtuner2-radiotray
# extraction-method: xml
# pack: radiotray.py
# fpm-prefix: /usr/share/streamtuner2/channels/
#
# Adds a context menu "Keep in RadioTray.." for bookmarking.
# Until a newer version exposes addRadio(), this plugin
# will fall back to just playUrl().

#


# The patch for radiotray/DbusFacade.py would be:
#   +
#   +    @dbus.service.method('net.sourceforge.radiotray')
#   +    def addRadio(self, title, url, group="root"):
#   +        self.dataProvider.addRadio(title, url, group)
#
# Displays existing radiotray stations in ST2 bookmarks
# category as read from ~/.local/share/radiotray/bookmarks.xml.
#
# This plugin may be packaged up separately.
#

from config import *
from channels import *
from uikit import uikit
................................................................................

    # send to 
    def share(self, *w):
        row = self.parent.row()
        if row:
            group = self.map_group(row.get("genre"))
            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:
                log.ERR("rtng dbus inactive")






                # RadioTray doesn't have an addRadio method yet, so just fall back to play the stream URL
                try:
                    self.radiotray().addRadio(row["title"], row["url"], group)
                except:

                    self.radiotray().playUrl(row["url"])


        pass




























    # 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 == "asis":
            return genre  # if RadioTray itself can map arbitrary genres to its folders
|


|












|
|
|
>

>
>






|
|







 







>




|
>
>
>
>
>
>
|
|
|
|
>

>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
...
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# api: streamtuner2
# title: RadioTray hook
# description: Allows to bookmark stations to RadioTray/NG
# version: 0.6
# 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".' }
# url: http://radiotray.sourceforge.net/
# priority: extra
# id: streamtuner2-radiotray
# extraction-method: xml
# pack: radiotray.py
# fpm-prefix: /usr/share/streamtuner2/channels/
#
# 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.
#
# 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')
#   +    def addRadio(self, title, url, group="root"):
#   +        self.dataProvider.addRadio(title, url, group)
#
# Displays existing radiotray stations in ST2 bookmarks (from
# either old bookmarks.xml or RT-NG bookmarks.json)
#
# This plugin may be packaged up separately.
#

from config import *
from channels import *
from uikit import uikit
................................................................................

    # send to 
    def share(self, *w):
        row = self.parent.row()
        if row:
            group = self.map_group(row.get("genre"))
            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)
                self.parent.status("Updated RT-NG bookmarks.json. Use Preferences>Reload Bookmarks..")
                #except:
                #    log.ERR("radiotray-ng not active")

            # RadioTray doesn't have an addRadio method yet, so just fall back to play the stream URL
            try:
                self.radiotray().addRadio(row["title"], row["url"], group)
            except:
                try:
                    self.radiotray().playUrl(row["url"])
                except:
                    log.ERR("radiotry-old not active")
        pass
        
    # 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
        # find existing group
        for g in j:
            if g["group"] == group or g["group"] == row["genre"]:
                found = g
                break
        # else add new group
        if not found:
            found = {
                "group": row["genre"],
                "image": None,
                "stations": []
            }
            j.append(found)
        # overwrite bookmarks.json
        if found:
            g["stations"].append({
                "image": None,
                "name": row["title"],
                "url": row["url"]
            })
            json.dump(j, open(fn, "w"), indent=4)

    # 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 == "asis":
            return genre  # if RadioTray itself can map arbitrary genres to its folders