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

⌈⌋ branch:  streamtuner2


Diff

Differences From Artifact [20027a66d7]:

To Artifact [59a1f308de]:


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
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







+
+
-
+

-
-
-
-
-
+
+
+
+
+

-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+





            # loop
            entries = []
            next = 0
            max = int(conf.max_streams)
            count = max
            rx_stream = None
            rx_next = re.compile("""onclick="showMoreGenre""")

            try:
            while (next < max):
               while (next < max):

               # page
               url = "http://www.shoutcast.com/genre-ajax/" + ucat
	       referer = url.replace("/genre-ajax", "/radio")
	       params = { "strIndex":"0", "count":str(count), "ajax":"true", "mode":"listeners", "order":"desc" }
               html = http.ajax(url, params, referer)   #,feedback=self.parent.status)
                  # page
                  url = "http://www.shoutcast.com/genre-ajax/" + ucat
                  referer = url.replace("/genre-ajax", "/radio")
                  params = { "strIndex":"0", "count":str(count), "ajax":"true", "mode":"listeners", "order":"desc" }
                  html = http.ajax(url, params, referer)   #,feedback=self.parent.status)

               __print__(html)
                  __print__(html)

               # regular expressions
               if not conf.get("pyquery") or not pq:
               
                   # new extraction regex
                   if not rx_stream:
                       rx_stream = re.compile(
                           """
                           <a\s+class="?playbutton\d?[^>]+id="(\d+)".+?
                           <a\s+class="[\w\s]*title[\w\s]*"[^>]+href="(http://[^">]+)"[^>]*>([^<>]+)</a>.+?
                           (?:Recently\s*played|Coming\s*soon|Now\s*playing):\s*([^<]*).+?
                           ners">(\d*)<.+?
                           bitrate">(\d*)<.+?
                           type">([MP3AAC]*)
                           """,
                           re.S|re.I|re.X
                       )
                  # regular expressions
                  if not conf.get("pyquery") or not pq:
                  
                      # new extraction regex
                      if not rx_stream:
                          rx_stream = re.compile(
                              """
                              <a\s+class="?playbutton\d?[^>]+id="(\d+)".+?
                              <a\s+class="[\w\s]*title[\w\s]*"[^>]+href="(http://[^">]+)"[^>]*>([^<>]+)</a>.+?
                              (?:Recently\s*played|Coming\s*soon|Now\s*playing):\s*([^<]*).+?
                              ners">(\d*)<.+?
                              bitrate">(\d*)<.+?
                              type">([MP3AAC]*)
                              """,
                              re.S|re.I|re.X
                          )

                   # extract entries
                   self.parent.status("parsing document...")
                   __print__("loop-rx")
                   for m in rx_stream.findall(html):
                       (id, homepage, title, playing, ls, bit, fmt) = m
                       __print__(uu)
                       entries += [{
                           "title": self.entity_decode(title),
                           "url": "http://yp.shoutcast.com/sbin/tunein-station.pls?id=" + id,
                           "homepage": http.fix_url(homepage),
                           "playing": self.entity_decode(playing),
                           "genre": cat, #self.strip_tags(uu[4]),
                           "listeners": int(ls),
                           "max": 0, #int(uu[6]),
                           "bitrate": int(bit),
                           "format": self.mime_fmt(fmt),
                       }]
                      # extract entries
                      self.parent.status("parsing document...")
                      __print__("loop-rx")
                      for m in rx_stream.findall(html):
                          (id, homepage, title, playing, ls, bit, fmt) = m
                          __print__(uu)
                          entries += [{
                              "title": self.entity_decode(title),
                              "url": "http://yp.shoutcast.com/sbin/tunein-station.pls?id=" + id,
                              "homepage": http.fix_url(homepage),
                              "playing": self.entity_decode(playing),
                              "genre": cat, #self.strip_tags(uu[4]),
                              "listeners": int(ls),
                              "max": 0, #int(uu[6]),
                              "bitrate": int(bit),
                              "format": self.mime_fmt(fmt),
                          }]

               # PyQuery parsing
               else:
                   # iterate over DOM
                   for div in (pq(e) for e in pq(html).find("div.dirlist")):
                  # PyQuery parsing
                  else:
                      # iterate over DOM
                      for div in (pq(e) for e in pq(html).find("div.dirlist")):

                       entries.append({
                            "title": div.find("a.playbutton,a.playbutton1").attr("title"),
                            "url": div.find("a.playbutton,a.playbutton1").attr("href"),
                            "homepage": http.fix_url(div.find("a.div_website").attr("href")),
                            "playing": div.find("div.playingtext").attr("title"),
#                            "title": div.find("a.clickabletitleGenre, div.stationcol a").attr("title"),
#                            "url": div.find("a.playbutton, a.playbutton1, a.playimage").attr("href"),
#                            "homepage": http.fix_url(div.find("a.playbutton.clickabletitle, a[target=_blank], a.clickabletitleGenre, a.clickabletitle, div.stationcol a, a").attr("href")),
#                            "playing": div.find("div.playingtextGenre, div.playingtext").attr("title"),
                            "listeners": int(div.find("div.dirlistners").text()),
                            "bitrate": int(div.find("div.dirbitrate").text()),
                            "format": self.mime_fmt(div.find("div.dirtype").text()),
                            "max": 0,
                            "genre": cat,
                           # "title2": e.find("a.playbutton").attr("name"),
                       })
                          entries.append({
                               "title": div.find("a.playbutton,a.playbutton1").attr("title"),
                               "url": div.find("a.playbutton,a.playbutton1").attr("href"),
                               "homepage": http.fix_url(div.find("a.div_website").attr("href")),
                               "playing": div.find("div.playingtext").attr("title"),
   #                            "title": div.find("a.clickabletitleGenre, div.stationcol a").attr("title"),
   #                            "url": div.find("a.playbutton, a.playbutton1, a.playimage").attr("href"),
   #                            "homepage": http.fix_url(div.find("a.playbutton.clickabletitle, a[target=_blank], a.clickabletitleGenre, a.clickabletitle, div.stationcol a, a").attr("href")),
   #                            "playing": div.find("div.playingtextGenre, div.playingtext").attr("title"),
                               "listeners": int(div.find("div.dirlistners").text()),
                               "bitrate": int(div.find("div.dirbitrate").text()),
                               "format": self.mime_fmt(div.find("div.dirtype").text()),
                               "max": 0,
                               "genre": cat,
                              # "title2": e.find("a.playbutton").attr("name"),
                          })


               # display partial results (not strictly needed anymore, because we fetch just one page)
               self.parent.status()
               self.update_streams_partially_done(entries)
               
               # more pages to load?
               if (re.search(rx_next, html)):
                  next += count
               else:
                  next = 99999
                  # display partial results (not strictly needed anymore, because we fetch just one page)
                  self.parent.status()
                  self.update_streams_partially_done(entries)
                  
                  # more pages to load?
                  if (re.search(rx_next, html)):
                     next += count
                  else:
                     next = 99999
                     
            except:
               return entries
            
            #fin
            __print__(entries)
            return entries