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

⌈⌋ ⎇ branch:  streamtuner2


Check-in [c734771f92]

Overview
Comment:New channel plugin for Radionomy.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c734771f92c05b4d4d25ed15686576b5fae61948
User & Date: mario on 2015-05-02 05:45:00
Other Links: manifest | tags
Context
2015-05-02
19:52
Move strip_tags(), entity_decode(), and nl() out of class into normal functions. check-in: d275a3e6e7 user: mario tags: trunk
05:45
New channel plugin for Radionomy. check-in: c734771f92 user: mario tags: trunk
05:44
Fix `audioformat` property name. check-in: 3f1b3bd882 user: mario tags: trunk
Changes

Added channels/radionomy.py version [3d7226d120].





















































































































































































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
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
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
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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
# encoding: UTF-8
# api: streamtuner2
# title: Radionomy
# description: Modern radio directory and streaming provider
# color: #ffcc77
# url: http://radionomy.com/
# version: 0.5
# type: channel
# category: radio
# config: -
#    { name: radionomy_pages,  type: int,  value: 3,  category: limit,  description: Number of pages per category to scan. }
#    { name: radionomy_update,  type: boolean,  value: 1,  description: Also fetch OnAir updates about currently playing songs. }
# png:
#   iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAACXBIWXMAAAsTAAALEwEAmpwYAAABIElEQVQ4y62Uv0rEQBCHv/yRQziJ1bYWV/gCaxrhGrtrg1f5GMc+xOKLeIetVjZXHRrwAewstxMWFDViM5EQcrk9yTRJZn+/j51h
#   JhESypZnwAKYAWP6wwN3wLUz+gkgEsglsOR/MXdGryK5yaMk34ECWAPVFmMCTIFb4FByeSrl1JDMGf0VcIt7ZcsMeBPYIpaeABSBEABEW8jnLG00dt0WK1ueSikvwDnw4YzeNCS1Z5w2klULkgAb4Bh4AC7kKOrypDsq+JHnBDgBRtuE
#   aWBLrpzRr32COBD0vEsQCvocCsQ+oKTj/Ehm5rtnyv9AXt6nrYGrgKyxBl1Re3ykbHkDzPdcEZQtDxorshxsaQf7jcTSjxWQC8wHmL1oc/HyC1/TWBfFRR9xAAAAAElFTkSuQmCC
# priority: extra
#
# Over 6500 radio stations of mixed genres and from different
# countries.
#
# Radionomy is a commercial radio hosting service. All listed
# stations are actually hosted by itself. Public and free access.
# And stream hosting is free as well, by adding advertisements,
# and given a daily listener quota.
#
# With "RMO" it furthermore provides access to a reusable song
# collection, and jingles etc.


from config import *
from channels import *
import ahttp
import re
import json
from pq import pq


# radionomy
class radionomy (ChannelPlugin):

    # control attributes
    has_search = False
    listformat = "srv"
    audioformat = "audio/mpeg"
    titles = dict(listeners=False, bitrate=False)
    categories = []
    
    base = "http://www.radionomy.com"

    playing = {}  # OnAir/Update dict


    # categories
    def update_categories(self):

        # get main categories
        main = []
        html = ahttp.get(self.base + "/en/style/")
        for a in pq(html)("#browseMainGenre li a"):
            main += [a.text]
            self.catmap[a.text] = a.attrib["href"]
        cats = [main[0], [main[1]]]

        # append sub categories
        for cat in main[2:]:
            cats.append(cat)
            subs = []
            html = ahttp.get("http://www.radionomy.com" + self.catmap[cat])
            for a in pq(html)("#browseSubGenre li a"):
                subs += [a.text]
                self.catmap[a.text] = a.attrib["href"]
            cats.append(subs)

        self.categories = cats


    # stations
    def update_streams(self, cat, search=None):
        r = []
        # category or search
        if cat:
            req = self.base + self.catmap[cat]

        # assemble page input
        html = ahttp.get(req)
        self.onair_update(req)
        for i in range(0, int(conf.radionomy_pages) - 1):
            add = ahttp.get(req, { "scrollOffset": i }, post=1, ajax=1)
            if add.find("browseRadio") < 0:
                break
            html += add
            self.onair_update(req)
        
        # extractzz
        for data in self.data_play_stream(html):
            data = json.loads(data)
            # combine
            r.append(dict(
                genre = cat,
                title = data["title"],
                url = data["mp3"],
                playing = self.playing.get(data["radioUID"], data["song"]),
                favourite = int(data.get("isFavorite", 0)),
                homepage = "http://www.radionomy.com/en/radio/{}/index".format(data["url"]),
                img = re.sub("\.s\d+\.", ".s32.", data["logo"]),
                uid = data["radioUID"],
            ))
        return r


    # Extracts the data- attribute JSON blob
    @use_rx
    def data_play_stream(self, html, use_rx):
        if use_rx:
            return [self.entity_decode(j) for j in re.findall('data-play-stream="({.*?})"', html)]
        else:
            # fix up for PyQuery, else ignores appended content
            html = re.sub("</html>|</body>", "", html) + "</body></html>"
            return [div.attrib["data-play-stream"] for div in pq(html)(".browseRadioWrap .radioPlayBtn")]


    # Retrieve en/OnAir/Update for per-UID song titles
    def onair_update(self, req):
        if conf.radionomy_update:
            try:
                d = json.loads(
                  ahttp.get("https://www.radionomy.com/en/OnAir/Update", post=1, referer=req)
                )
                if d:
                    self.playing.update(
                      {row["RadioUID"]: "{Title} - {Artist}".format(**row) for row in d}
                    )
            except Exception as e:
                log.ERR("Radionomy title update:", e)

                


"""
<div id="tile-4f60d666-c9af-4e86-9ed1-7d4d488df430" class="browseRadioWrap">
	<a href="/en/radio/w1rs-blues--rock-s-radio/index" rel="internal"><img class="radioCover" src="https://i.radionomy.com/document/radios/4/4f60/4f60d666-c9af-4e86-9ed1-7d4d488df430.s67.jpg" alt="W1RS blues &amp; Rock&#39;s Radio" width="67" height="67"></a>
	<div class="radioInfo">
		<p class="radioName">W1RS blues &amp; Rock&#39;s Radio</p>
		<p class="nowPlaying" style="display: none;">
			<span class="artist">
				
			</span>
			<span class="separator">-</span>
			<span class="title">
				
			</span>
		</p>

		<div class="radioRating">
			<img src="/images/icons/icon-radioRatings-one.png" width="82" height="13" alt="Ratings">
			<a href="#" onclick="AddFavorite(&#39;4f60d666-c9af-4e86-9ed1-7d4d488df430&#39;, event); return false;" class="fav-icon addToFav">
				<img src="/images/icons/icon-radioActionsUnfav.png" width="13" height="13">
			</a>
		</div>
	</div>

	<div class="radioPlay">
		<div class="radioPlayBtn" data-play-stream="{
		&quot;mp3&quot;:
		&quot;http://listen.radionomy.com/w1rs-blues--rock-s-radio&quot;,
		&quot;title&quot;: &quot;W1RS blues &amp; Rock&#39;s
		Radio&quot;, &quot;isFavorite&quot;: false, &quot;url&quot;:
		&quot;w1rs-blues--rock-s-radio&quot;, &quot;logo&quot;:
		&quot;https://i.radionomy.com/document/radios/4/4f60/4f60d666-c9af-4e86-9ed1-7d4d488df430.s400.jpg&quot;,
		&quot;song&quot;: &quot; - &quot;, &quot;radioUID&quot;:
		&quot;4f60d666-c9af-4e86-9ed1-7d4d488df430&quot; }"></div>
		<!-- StopBtn -->
	</div>
</div>
"""