42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 | # extraction afterwards (instead of a block match).
#
# · Entries may contain more than one streaming url. Each accompanied by a
# bitrate. → Therefore the .best_url() sorting method.
#
# · Later versions might of course use multi-urls again…
#
class radiolist (ChannelPlugin):
# module attributes
listformat = "pls"
has_search = False
categories = ["Europe", "America", "Canada", "Oceania", "Asia"]
catmap = {"Europe":"", "America":"world", "Canada":"world/canada", "Oceania":"world/oceania", "Asia":"world/asia"}
titles = dict( genre="Genre", title="Station", playing="Location", bitrate="Bitrate", listeners=False ) |
|
| 42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 | # extraction afterwards (instead of a block match).
#
# · Entries may contain more than one streaming url. Each accompanied by a
# bitrate. → Therefore the .best_url() sorting method.
#
# · Later versions might of course use multi-urls again…
#
class radiolist (ChannelPlugin, action.heuristic_funcs):
# module attributes
listformat = "pls"
has_search = False
categories = ["Europe", "America", "Canada", "Oceania", "Asia"]
catmap = {"Europe":"", "America":"world", "Canada":"world/canada", "Oceania":"world/oceania", "Asia":"world/asia"}
titles = dict( genre="Genre", title="Station", playing="Location", bitrate="Bitrate", listeners=False ) |
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 | if ut and uu and lg:
url, br = self.best_url(uu)
entries.append(dict(
homepage = ut[0][0],
title = unhtml(ut[0][1]),
url = url,
bitrate = br,
format = self.guess_fmt(url),
listformat = self.guess_pls(url),
playing = lg[0],
genre = lg[1]
))
# done
[log.DATA(e) for e in entries]
return entries
# pick highest rated URL from [(url,bitrate),…] tuples
def best_url(self, urls):
r = dict([(u, to_int(b)) for u,b in urls]) # {url: bitrate, …}
best = sorted(r, key=r.get, reverse=True)
return best[0], r[best[0]]
# see if audio type can be guessed
def guess_fmt(self, url):
ext = re.findall("mp3|ogg|wma|aac|mp4", url)
if ext:
return mime_fmt(ext[0])
else:
return "audio/mpeg"
# guess PLS/M3U from url
def guess_pls(self, url):
ext = re.findall("|".join(action.playlist_fmt_prio), url)
if ext:
return ext[0]
else:
return "srv"
|
|
|
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
< | 89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
| if ut and uu and lg:
url, br = self.best_url(uu)
entries.append(dict(
homepage = ut[0][0],
title = unhtml(ut[0][1]),
url = url,
bitrate = br,
format = self.mime_guess(url, "audio/mpeg"),
listformat = self.list_guess(url),
playing = lg[0],
genre = lg[1]
))
# done
[log.DATA(e) for e in entries]
return entries
# pick highest rated URL from [(url,bitrate),…] tuples
def best_url(self, urls):
r = dict([(u, to_int(b)) for u,b in urls]) # {url: bitrate, …}
best = sorted(r, key=r.get, reverse=True)
return best[0], r[best[0]]
|