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
|
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
|
-
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
|
# encoding: UTF-8
# api: streamtuner2
# title: Xiph.org
# description: ICEcast radios. Scans per JSON API, slow XML, or raw directory.
# type: channel
# url: http://dir.xiph.org/
# version: 0.6
# version: 0.7
# category: radio
# config:
# { name: xiph_source, value: web, type: select, select: "cache=JSON cache srv|xml=Clunky XML blob|buffy=Buffy YP.XML|web=Forbidden fruits", description: "Source for station list extraction." }
# { name: xiph_source, value: buffy, type: select, select: "cache=JSON cache srv|xml=Clunky XML blob|buffy=Buffy YP.XML|web=Forbidden fruits", description: "Source for station list extraction." }
# priority: standard
# png:
# iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAg5JREFUOI2lk1tIE2AUx3+7CG1tlmlG1rSEHrKgEUF7yO40taQiRj10I4qKkOaT4hIUItuTkC8hpJAQtJCICrFpzEKw
# h61eQorGNBOTzbEt16ZrnR5Wq3mZD/3heziX//983znngyyov+eSbHEA5WKBhs4BKVy9gsqajqwiCwo0dA5IQX5u2s4moliMPPV1nCeDzxgNBFDHE2wsKMPzsGVefobjcnO7RMfeMuL341ZBrNEGRmPqqjdvsbbf
# w7irO4Oj+rdywNNNucmERsLUVndR8uYRU13PCew6hpgP8W02xMpIsik++qk5oweW6y3yob8WnXacZDKJWh1Cp4OtRUHsh19TUlUGViv09RGqKAenU5QnLKm+rK88LjgcUnxmr/h8iNO5XYJBRAQZ/qiVeptGWjty
# 5cClDWLwugQRIRiU5UdPCoD6S89jhV6pks9WG6fuwtBtF5v72vC1v+B86SsM+jD56hjnyiM0lRrAbofeXjQJLdE/78jbXSU5166I6f5VeeDdKdq6GtlSd0QkVU+8XsQhlt9W6izbZ5aMKWgtp2WT/yUHd0xSYU7i
# dsPQ+1WMKIsJD08wEV2HGLeRyNMjawqRxhuKBfdgz1m7fI/4mVX+ZGxmgniOoJv+QZHGAMC7p60ZnHkC8HfzZmLTBCd9af9ccnqMc9HTdmFe4kLkJbH/4h0xVtcu+SP/C78AL6btab6woPcAAAAASUVORK5CYII=
# extraction-method: xml, regex, json
#
# Xiph.org maintains the Ogg streaming standard and Vorbis,
# Opus, FLAC audio, and Theora video compression formats.
# The ICEcast server is an open alternative to SHOUTcast.
#
# It also provides a directory listing of known internet
# radio stations; only a handful of them using Ogg though.
# The category list is hardwired in this plugin. And there
# are three station fetching modes now:
#
# → "JSON cache" retrieves a refurbished JSON station list,
# both sliceable genres and searchable.
#
# → "Clunky XML" fetches the olden YP.XML, which is really
# slow, then slices out genres. No search.
#
# → While the secret "buffy" mode keeps the XML blob in memory.
#
# → "Forbidden Fruits" extracts from dir.xiph.org HTML pages,
# with homepages and listener/max infos available. Also
# enables live server searching.
# → "Forbidden Fruits" extracts from dir.xiph.org HTML pages.
# Albeit that doesn't contain homepages or bitrates anymore,
#
# → "JSON cache" retrieves a refurbished JSON station list,
# both sliceable genres and searchable. This will probably
# break now that the BETA interface also killed the JSON
# experimental API.
#
# The previous bitrate filter is now a separate plugin, but
# available for all channels.
from config import *
from uikit import uikit
|
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
-
+
-
+
-
+
+
-
+
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
+
+
+
+
+
+
|
# Build request URL
by_format = {t.lower(): t for t in self.categories[-1]}
if search:
url = "http://dir.xiph.org/search?search={}".format(search)
cat = "search"
elif by_format.get(cat):
url = "http://dir.xiph.org/by_format/{}".format(by_format[cat])
url = "http://dir.xiph.org/codecs/{}".format(by_format[cat].title())
elif cat:
url = "http://dir.xiph.org/by_genre/{}".format(cat.title())
url = "http://dir.xiph.org/genres/{}".format(cat.title())
# Collect all result pages
html = ahttp.get(url)
for i in range(1,5):
if html.find('page={}">{}</a></li>'.format(i, i+1)) < 0:
m = re.search('href="[?]cursor=(\w+)">Next</a>', html)
if not m:
break
self.status(i/5.1)
html += ahttp.get(url, {"search": cat.title(), "page": i})
html += ahttp.get(url, {"cursor": m.group(1)})
try:
html = html.encode("raw_unicode_escape").decode("utf-8")
except:
pass
# Find streams
r = []
rows = re.findall("""<tr\s+class="row\d*">(.+?)</tr>""", html, re.S)
rows = re.findall("""<div\s+class="card\s.*?">(.+?)</div>(?=\s+<div\s+class="card\s)""", html, re.S)
for html in rows:
ls = self.rx_all(
dict(
homepage = """ class="name"> <a\s+href="(.*?)" """,
title = """ class="name"> <a[^>]*> (.*?)</a> """,
listeners = """ "listeners">\[(\d+) """,
playing = """ "stream-description">(.*?)< """,
tags = """ (?s) Tags: (.*?) </div> """,
url = """ href="(/listen/\d+/listen.xspf)" """,
bits = """ class="format"\s+title="([^"]+)" """,
fmt = """ /by_format/([^"]+) """,
#homepage = """ class="name"> <a\s+href="(.*?)" """,
title = """ <h5\s+class="card-title"> ([^>]*) </h5> """,
listeners = """ (\d+) \s+ Listeners \s+ — """,
playing = """ class="card-subtitle[^>]*"> On\s+Air:\s+ ([^<]*) </h6> """,
description = """ class="card-text"> ([^>]*) </p> """,
tags = """ ((?:<a\s+href="/genres/[^>]+> [^<]+ </a>\s+)+) — """,
url = """ <a\s+href="([^">]+)"\s+class="btn[^>]+">Play</a> """,
#bits = """ class="format"\s+title="([^"]+)" """,
fmt = """ <a\s+href="/codecs/(\w+) """,
),
html
)
log.DATA(ls)
if not len(ls["url"]) or not len(ls["title"]):
log.ERR("emptY")
continue
r.append(dict(
genre = unhtml(ls["tags"]),
title = unhtml(ls["title"]),
homepage = ahttp.fix_url(ls["homepage"]),
title = unhtml(ls["title"]) if len(ls["title"]) else unhtml(ls["description"]),
homepage = "", #ahttp.fix_url(ls["homepage"]),
playing = unhtml(ls["playing"]),
url = "http://dir.xiph.org{}".format(ls["url"]),
listformat = "xspf",
listeners = int(ls["listeners"]),
bitrate = bitrate(ls["bits"]),
url = "{}".format(ls["url"]),
listformat = "srv",
listeners = to_int(ls["listeners"]),
bitrate = 0, #bitrate(ls["bits"]),
format = mime_fmt(guess_format(ls["fmt"])),
tags = unhtml(ls["tags"])
))
#log.DATA(r)
return r
# Regex dict
def rx_all(self, fields, src, flags=re.X):
row = {}
for k, v in fields.items():
m = re.search(v, src, flags)
|
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
|
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
|
-
+
|
"ska",
[
"punkrock",
"oi"
],
"darkwave",
"/FORMAT",
["Ogg_Vorbis", "Ogg_Theora", "Opus", "NSV", "WebM"],
["AAC", "AAC+", "MP3", "Opus", "Vorbis", "Theora", "NSV", "WebM"],
]
# Helper functions for XML extraction mode
# Shortcut to get text content from XML subnode by name
|