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

⌈⌋ ⎇ branch:  streamtuner2


Check-in [00f1bd3fd7]

Overview
Comment:basic.ch is no more
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | py3
Files: files | file ages | folders
SHA1: 00f1bd3fd7d8eb95ccf285a31d0c4e9f591c5872
User & Date: mario on 2014-04-11 02:28:04
Other Links: branch diff | manifest | tags
Context
2014-04-11
02:53
Add icons check-in: 9525b6b42e user: mario tags: py3
02:28
basic.ch is no more check-in: 00f1bd3fd7 user: mario tags: py3
02:27
no more TV listings on Shoutcast check-in: c8dcfb540d user: mario tags: py3
Changes

Deleted channels/basicch.py version [c507665eb7].

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
181
182
183
184
185
186
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

# api: streamtuner2
# title: basic.ch channel
#
#
#
# Porting ST1 plugin senseless, old parsing method wasn't working any longer. Static
# realaudio archive is not available anymore.
#
# Needs manual initialisation of categories first.
#


import re
import ahttp as http
from config import conf
from channels import *
from xml.sax.saxutils import unescape














# basic.ch broadcast archive
class basicch (ChannelPlugin):

    # description
    title = "basic.ch"
    module = "basicch"
    homepage = "http://www.basic.ch/"
    version = 0.3
    base = "http://basic.ch/"

    # keeps category titles->urls    
    catmap = {}
    categories = []   #"METAMIX", "reload category tree!", ["menu > channel > reload cat..."]]
    #titles = dict(listeners=False, bitrate=False)
 
    
    # read previous channel/stream data, if there is any
    def cache(self):
        ChannelPlugin.cache(self)
        # catmap
        cache = conf.load("cache/catmap_" + self.module)
        if (cache):
            self.catmap = cache
        pass
    

    # refresh category list
    def update_categories(self):

        html = http.get(self.base + "shows.cfm")

        rx_current = re.compile(r"""
            <a\shref="shows.cfm[?]showid=(\d+)">([^<>]+)</a>
            \s*<span\sclass="smalltxt">([^<>]+)</span><br
        """, re.S|re.X)


        #-- archived shows
        for uu in rx_current.findall(html):
            (id, title, genre) = uu
            self.catmap[title] = {
                "sub_url": self.base + "shows.cfm?showid=" + id,
                "title": title,
                "genre": genre,
                "id": id,
            }

        #-- populate category treee
        self.categories = [
            "METAMIX",
            "shows", [ title for title in self.catmap.keys() ]
        ]
        
        #-- keep catmap as cache-file, it's essential for redisplaying        
        self.save()
        return

    # saves .streams and .catmap
    def save(self):
        ChannelPlugin.save(self)
        conf.save("cache/catmap_" + self.module, self.catmap)


    # download links from dmoz listing
    def update_streams(self, cat, force=0):

        rx_metamix = re.compile("""
            <a\shref="(http://[^<">]+)">(METAMIX[^<]+)</a>
            \s+<span\sclass="smalltxt">([^<>]+)</span><br
        """, re.S|re.X)

        rx_playlist = re.compile("""
            <filename>(http://[^<">]+)</filename>\s*
            <artist>([^<>]+)</artist>\s*
            <title>([^<>]+)</title>
        """, re.S|re.X)

        entries = []
 
        #-- update categories first
        if not len(self.catmap):
            self.update_categories()
    
        #-- frontpage mixes
        if cat == "METAMIX":
            for uu in rx_metamix.findall(http.get(self.base)):
                (url, title, genre) = uu
                entries.append({
                    "genre": genre,
                    "title": title,
                    "url": url,
                    "format": "audio/mp3",
                    "homepage": self.homepage,
                })

        #-- pseudo entry        
        elif cat=="shows":
            entries = [{"title":"shows","homepage":self.homepage+"shows.cfm"}]
            
        #-- fetch playlist.xml
        else:
        
            # category name "Xsound & Ymusic" becomes "Xsoundandymusic"
            id = cat.replace("&", "and").replace(" ", "")
            id = id.lower().capitalize()
            
            catinfo = self.catmap.get(cat, {"id":"", "genre":""})
            
            # extract
            html = http.get(self.base + "playlist/" + id + ".xml")
            for uu in rx_playlist.findall(html):    # you know, we could parse this as proper xml
                (url, artist, title) = uu           # but hey, lazyness works too
                entries.append({
                    "url": url,
                    "title": artist,
                    "playing": title,
                    "genre": catinfo["genre"],
                    "format": "audio/mp3",
                    "homepage": self.base + "shows.cfm?showid=" + catinfo["id"],
                })

        # done    
        return entries
        










# basic.ch broadcast archive
class basicch_old_static: #(ChannelPlugin):

    # description
    title = "basic.ch"
    module = "basicch"
    homepage = "http://www.basic.ch/"
    version = 0.2
    base = "http://basic.ch/"

    # keeps category titles->urls    
    catmap = {}
 
    
    # read previous channel/stream data, if there is any
    def cache(self):
        ChannelPlugin.cache(self)
        # catmap
        cache = conf.load("cache/catmap_" + self.module)
        if (cache):
            self.catmap = cache
        pass
    

    # refresh category list
    def update_categories(self):

        html = http.get(self.base + "downtest.cfm")

        rx_current = re.compile("""
            href="javascript:openWindow.'([\w.?=\d]+)'[^>]+>
            <b>(\w+[^<>]+)</.+?
            <b>(\w+[^<>]+)</.+?
            <a\s+href="(http://[^">]+)"
        """, re.S|re.X)

        rx_archive = re.compile("""
            href="javascript:openWindow.'([\w.?=\d]+)'[^>]+>.+?
            color="000000">(\w+[^<>]+)</.+?
            color="000000">(\w+[^<>]+)</
        """, re.S|re.X)

        archive = []
        previous = []
        current = []
        
        #-- current listings with latest broadcast and archive link
        for uu in rx_current.findall(html):
            self.catmap[uu[1]] = {
                "sub_url": self.base + uu[0],
                "title": uu[1],
                "genre": uu[2],
                "url": uu[3],
            }
            archive.append(uu[1])

        #-- old listings only have archive link
        for uu in rx_archive.findall(html):
            self.catmap[uu[1]] = {
                "sub_url": self.base + uu[0],
                "genre": uu[2],
            }
            previous.append(uu[1])
        
        #-- populate category treee
        self.categories = [
            "current",
            "archive", archive,
            "previous", previous,
        ]
        
        #-- inject streams
        self.streams["current"] = [
             {
                "title": e["title"],
                "url": e["url"],
                "genre": e["genre"],
                "format": "audio/mp3",
                "listeners": 0,
                "max": 100,
                "bitrate": 0,
                "homepage": e["sub_url"],
             }
             for title,e in self.catmap.iteritems() if e.get("url")
        ]

        #-- keep catmap as cache-file, it's essential for redisplaying        
        self.save()
        return

    # saves .streams and .catmap
    def save(self):
        ChannelPlugin.save(self)
        conf.save("cache/catmap_" + self.module, self.catmap)


    # download links from dmoz listing
    def update_streams(self, cat, force=0):
    
        if not self.catmap:
            self.update_categories()
        elif cat=="current":
            self.update_categories()
            return self.streams["current"]
            
        if not self.catmap.get(cat):
            return []
    
        e = self.catmap[cat]
        html = http.get( e["sub_url"] )
        
        rx_archives = re.compile("""
            >(\d\d\.\d\d\.\d\d)</font>.+?
            href="(http://[^">]+|/ram/\w+.ram)"[^>]*>([^<>]+)</a>
            .+?   (>(\w+[^<]*)</)?
        """, re.X|re.S)
        
        entries = []
        
        for uu in rx_archives.findall(html):
            url = uu[1]
            ram = url.find("http://") < 0
            if ram:
                url = self.base + url[1:]
            entries.append({
                "title": uu[0],
                "url": url,
                "playing": uu[2],
                "genre": e["genre"],
                "format": ( "audio/x-pn-realaudio"  if  ram  else  "audio/"+uu[3].lower() ),
                "listeners": 0,
                "max": 1,
                "homepage": e["sub_url"],
            })
            
        return entries
        


<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<