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

⌈⌋ branch:  streamtuner2


Check-in [0763c7e201]

Overview
Comment:Preliminary support for Radiotray-NG
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:0763c7e201928cf5ffcfc30937033bd2c9e29d85
User & Date: mario on 2018-12-16 19:37:09
Other Links: manifest | tags
Context
2018-12-16
20:06
Fix cmd= parameter handling. check-in: 6cea64726f user: mario tags: trunk
19:37
Preliminary support for Radiotray-NG check-in: 0763c7e201 user: mario tags: trunk
2018-10-07
15:21
Add shoutcast_format=pls/m3u/xpsf option check-in: 5d84c96422 user: mario tags: trunk
Changes

Modified channels/radiotray.py from [4465adc486] to [530caa9d50].

1
2
3
4
5
6
7
8
9
10
11
..
31
32
33
34
35
36
37

38
39
40
41
42
43
44
45
..
46
47
48
49
50
51
52

53
54
55
56
57
58
59
60
61
62
63








64
65
66
67
68
69
70
..
73
74
75
76
77
78
79
80
81
82
83
84
85













86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107







108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

125

126
127
128
129

130
131
132
133
134
135
136
137
# api: dbus
# title: RadioTray hook
# description: Allows to bookmark stations to RadioTray
# version: 0.4
# 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
................................................................................
#

from config import *
from channels import *
from uikit import uikit
import re
import dbus

from xdg.BaseDirectory import xdg_data_home
from xml.etree import ElementTree


# not a channel plugin, just a category in bookmarks, and a context menu
class radiotray (object):

    # plugin info
................................................................................
    module = 'radiotray'
    meta = plugin_meta()
    # bookmarks cat
    parent = None
    bm = None
    # radiotray config file / bookmarks
    rt_xml = "%s/%s/%s" % (xdg_data_home, "radiotray", "bookmarks.xml")



    # DBUS connector
    def radiotray(self):
        return dbus.Interface(
            dbus.SessionBus().get_object(
                "net.sourceforge.radiotray",
                "/net/sourceforge/radiotray"
            ),
            "net.sourceforge.radiotray"
        )










    # hook up to main tab
    def __init__(self, parent):

        # keep reference to main window    
        self.parent = parent
................................................................................

        # create category
        self.bm.add_category("radiotray", plugin=self);
        self.bm.category_plugins["radiotray"] = self #.update_streams(cat="radiotray")
        self.bm.reload_if_current(self.module)

        # add context menu
        uikit.add_menu([parent.streammenu, parent.streamactions], "Keep in RadioTray", self.share, insert=4)
        

    # load RadioTray bookmarks
    def update_streams(self, cat):
        r = []













        try:
            for group in ElementTree.parse(self.rt_xml).findall(".//group"):
                for bookmark in group.findall("bookmark"):
                    r.append({
                        "genre": group.attrib["name"],
                        "title": bookmark.attrib["name"],
                        "url": bookmark.attrib["url"],
                        "playing": "",
                    })
        except Exception as e:
            log.DATA("Extracting from radiotray bookmarks.xml failed:", e)
        return r


    # send to 
    def share(self, *w):
        row = self.parent.row()
        if row:
            # RadioTray doesn't have an addRadio method yet, so just fall back to play the stream URL
            try:
                group = self.map_group(row.get("genre"))
                log.PROC("mapping genre '%s' to RT group '%s'" % (row["genre"], group))







                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
        if conf.radiotray_map == "play":
            raise NotImplementedError("just call .playUrl()")
        map = {
            "Jazz": "jazz|fusion|swing",
            "Pop / Rock": "top|pop|rock|metal",
            "Latin": "latin|flamenco|tango|salsa|samba",

            "Classical": "classic|baroque|opera|symphony|piano|violin",

            "Oldies": "20s|50s|60s|70s|oldie",
            "Chill": "chill|easy|listening",
            "Techno / Electronic": "techno|electro|dance|house|beat|dubstep|progressive|trance",
            "Country": "country|bluegrass|western",

            "Community": "community|talk|sports|spoken|educational",
        }
        #for str in (genre,title):
        for cat,rx in map.items():
            if re.search(rx, genre, re.I):
                return cat
        return "root"



|
|







 







>
|







 







>











>
>
>
>
>
>
>
>







 







|





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










|







<
<
|
|
>
>
>
>
>
>
>
|
|
|












<

>

>


<

>








1
2
3
4
5
6
7
8
9
10
11
..
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
..
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
..
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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
147
148
149
150

151
152
153
154
155
156

157
158
159
160
161
162
163
164
165
166
# 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
................................................................................
#

from config import *
from channels import *
from uikit import uikit
import re
import dbus
import json
from xdg.BaseDirectory import xdg_data_home, xdg_config_home
from xml.etree import ElementTree


# not a channel plugin, just a category in bookmarks, and a context menu
class radiotray (object):

    # plugin info
................................................................................
    module = 'radiotray'
    meta = plugin_meta()
    # bookmarks cat
    parent = None
    bm = None
    # radiotray config file / bookmarks
    rt_xml = "%s/%s/%s" % (xdg_data_home, "radiotray", "bookmarks.xml")
    rtng_json = "%s/%s/%s" % (xdg_config_home, "radiotray-ng", "bookmarks.json")


    # DBUS connector
    def radiotray(self):
        return dbus.Interface(
            dbus.SessionBus().get_object(
                "net.sourceforge.radiotray",
                "/net/sourceforge/radiotray"
            ),
            "net.sourceforge.radiotray"
        )
    def radiotray_ng(self):
        return dbus.Interface(
            dbus.SessionBus().get_object(
                "com.github.radiotray_ng",
                "/com/github/radiotray_ng"
            ),
            "com.github.radiotray_ng"
        )


    # hook up to main tab
    def __init__(self, parent):

        # keep reference to main window    
        self.parent = parent
................................................................................

        # create category
        self.bm.add_category("radiotray", plugin=self);
        self.bm.category_plugins["radiotray"] = self #.update_streams(cat="radiotray")
        self.bm.reload_if_current(self.module)

        # add context menu
        uikit.add_menu([parent.streammenu, parent.streamactions], "Add in RadioTray/NG", self.share, insert=4)
        

    # load RadioTray bookmarks
    def update_streams(self, cat):
        r = []
        # RT-NG
        try:
            for group in json.load(open(self.rtng_json, "r")):
                genre = group["group"]
                for ls in group["stations"]:
                    r.append({
                        "genre": genre,
                        "title": ls["name"],
                        "url": ls["url"]
                    })
        except Exception as e:
            log.ERR("Extracting from radiotray-ng bookmarks.json failed:", e)
        # RT XML
        try:
            for group in ElementTree.parse(self.rt_xml).findall(".//group"):
                for bookmark in group.findall("bookmark"):
                    r.append({
                        "genre": group.attrib["name"],
                        "title": bookmark.attrib["name"],
                        "url": bookmark.attrib["url"],
                        "playing": "",
                    })
        except Exception as e:
            log.ERR("Extracting from radiotray bookmarks.xml failed:", e)
        return r


    # 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
        if conf.radiotray_map == "play":
            raise NotImplementedError("just call .playUrl()")
        map = {
            "Jazz": "jazz|fusion|swing",

            "Latin": "latin|flamenco|tango|salsa|samba",
            "Classic Rock": "classic rock",
            "Classical": "classic|baroque|opera|symphony|piano|violin",
            "Pop / Rock": "top|pop|rock|metal",
            "Oldies": "20s|50s|60s|70s|oldie",
            "Chill": "chill|easy|listening",

            "Country": "country|bluegrass|western",
            "Techno / Electronic": "techno|electro|dance|house|beat|dubstep|progressive|trance",
            "Community": "community|talk|sports|spoken|educational",
        }
        #for str in (genre,title):
        for cat,rx in map.items():
            if re.search(rx, genre, re.I):
                return cat
        return "root"