Check-in [846623040b]
Overview
| Comment: | Enhance configurability of language, remove default categories. |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
846623040b2bf39d1f1a5024f96b1f9c |
| User & Date: | mario on 2014-05-30 23:21:12 |
| Other Links: | manifest | tags |
Context
|
2014-05-30
| ||
| 23:21 | Better cleaup of regex-extracted entries. check-in: a2142151c0 user: mario tags: trunk | |
| 23:21 | Enhance configurability of language, remove default categories. check-in: 846623040b user: mario tags: trunk | |
|
2014-05-28
| ||
| 19:53 | English-localized version of SurfMusic.de now supported check-in: 4db7cbeed2 user: mario tags: trunk | |
Changes
Modified channels/surfmusik.py from [d30a39ab13] to [38f14e35ce].
1 2 3 4 | # encoding: UTF-8 # api: streamtuner2 # title: SurfMusik # description: User collection of streams categorized by region and genre. | | | 1 2 3 4 5 6 7 8 9 10 11 12 | # encoding: UTF-8 # api: streamtuner2 # title: SurfMusik # description: User collection of streams categorized by region and genre. # version: 0.5 # type: channel # category: radio # author: gorgonz123 # source: http://forum.ubuntuusers.de/topic/streamtuner2-zwei-internet-radios-anhoeren-au/3/ # recognizes: max_streams # # This plugin comes in German (SurfMusik) and English (SurfMusic) variations. |
| ︙ | ︙ | |||
32 33 34 35 36 37 38 39 40 41 |
# Surfmusik sharing site
class surfmusik (ChannelPlugin):
# description
title = "SurfMusik"
module = "surfmusik"
homepage = "http://www.surfmusik.de/"
lang = "DE" # last configured categories
base = {
| > | | < | < < < < < < < < < < < < < | | > > > > > > > | > | | < | | | | > | | | | 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 |
# Surfmusik sharing site
class surfmusik (ChannelPlugin):
# description
title = "SurfMusik"
module = "surfmusik"
homepage = "http://www.surfmusik.de/"
listformat = "audio/x-scpls"
lang = "DE" # last configured categories
base = {
"DE": ("http://www.surfmusik.de/", "genre/", "land/"),
"EN": ("http://www.surfmusic.de/", "format/", "country/"),
}
categories = []
titles = dict( genre="Genre", title="Station", playing="Location", bitrate=False, listeners=False )
config = [
{
"name": "surfmusik_lang",
"value": "EN",
"type": "select",
"select":"DE=German|EN=English",
"description": "Switching to a new category title language requires reloading the category tree.",
"category": "language",
}
]
# Set channel title
def __init__(self, parent=None):
self.title = ("SurfMusik", "SurfMusic")[conf.get("surfmusik_lang", "EN") == "EN"]
ChannelPlugin.__init__(self, parent)
# just a static list for now
def update_categories(self):
lang = conf.surfmusik_lang
(base_url, path_genre, path_country) = self.base[lang]
cats = {
"DE": ["Genres", "Deutschland", "Europa", "USA", "Kanada", "Amerika", "Afrika", "Asien", "Ozeanien", "MusicTV", "NewsTV", "Poli", "Flug"],
"EN": ["Genres", "Europe", "Germany", "USA", "Canada", "America", "Africa", "Asia", "Oceania", "MusicTV", "NewsTV", "Poli", "Flug"],
}
map = {
"Genres": "genres.htm",
"Europe": "euro.htm", "Europa": "euro.htm",
"Germany": "bundesland.htm", "Deutschland": "bundesland.htm",
"Africa": "africa.htm", "Afrika": "africa.htm",
"America": "amerika.htm", "Amerika": "amerika.htm",
"Asia": "asien.htm", "Asien": "asien.htm",
"Oceania": "ozean.htm", "Ozeanien": "ozean.htm",
"Canada": "canadian-radio-stations.htm", "Kanada": "kanada-online-radio.htm",
"USA": "staaten.htm",
}
rx_links = re.compile(r"""
<a\b [^>]+ \b href="
(?:(?:https?:)?//www.surfmusi[kc].de)? /?
(?:land|country|genre|format)/
([\-+\w\d\s%]+) \.html"
""", re.X)
r = []
# Add main categories, and fetch subentries (genres or country names)
for cat in cats[lang]:
r.append(cat)
if map.get(cat):
subcats = rx_links.findall( http.get(base_url + map[cat]) )
subcats = [x.replace("+", " ").title() for x in subcats]
r.append(sorted(subcats))
self.categories = r
# summarize links from surfmusik
def update_streams(self, cat, force=0):
(base_url, path_genre, path_country) = self.base[conf.surfmusik_lang]
entries = []
i = 0
max = int(conf.max_streams)
is_tv = 0
# placeholder category
if cat in ["Genres"]:
path = None
# separate
elif cat in ["Poli", "Flug"]:
path = ""
# tv
elif cat in ["SurfTV", "MusikTV", "NewsTV"]:
path = ""
is_tv = 1
# genre
elif cat in self.categories[self.categories.index("Genres") + 1]:
path = path_genre
# country
else:
path = path_country
if path is not None:
ucat = cat.replace(" ", "+").lower()
html = http.get(base_url + path + ucat + ".html")
html = re.sub("&#x?\d+;", "", html)
rx_radio = re.compile(r"""
<td\s+class="home1"><a[^>]*\s+href="(.+?)"[^>]*> .*?
<a\s+class="navil"\s+href="([^"]+)"[^>]*>([^<>]+)</a></td>
<td\s+class="ort">(.*?)</td>.*?
<td\s+class="ort">(.*?)</td>.*?
""", re.X|re.I)
rx_video = re.compile(r"""
<a[^>]+href="([^"]+)"[^>]*>(?:<[^>]+>)*Externer
""", re.X|re.I)
# per-country list
for uu in rx_radio.findall(html):
(url, homepage, name, genre, city) = uu
# find mms:// for webtv stations
if is_tv:
m = rx_video.search(http.get(url))
if m:
url = m.group(1)
# just convert /radio/ into /m3u/ link
else:
url = "http://www.surfmusik.de/m3u/" + url[30:-5] + ".m3u"
entries.append({
"title": name,
"homepage": homepage,
"url": url,
"playing": city,
"genre": genre,
"format": ("video/html" if is_tv else "audio/mpeg"),
})
# limit result list
if i > max:
break
|
| ︙ | ︙ |