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

⌈⌋ ⎇ branch:  streamtuner2


Check-in [6c2dc3f04e]

Overview
Comment:Fixed internet_radio basic regex extraction.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6c2dc3f04e2e0ea252aaba22cb421edbdb8ca53a
User & Date: mario on 2015-03-24 02:02:43
Other Links: manifest | tags
Context
2015-03-24
21:09
Updated key. check-in: 0db0cbed82 user: mario tags: trunk
02:02
Fixed internet_radio basic regex extraction. check-in: 6c2dc3f04e user: mario tags: trunk
01:30
Minor updates to help pages. check-in: 04c9f4d564 user: mario tags: trunk
Changes

Modified channels/internet_radio.py from [b9fa0242be] to [583351e59d].

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







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



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











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







-
+







            except Exception as e:
                __print__(dbg.ERR, e)
                continue
            
        # fin
        return entries

    # Advertised 
    """
    <tr valign="top" class="stream">
    <td class="listing1" width="120" align="center">
    <a onClick="return popitup('/player/?mount=http://uk2.internet-radio.com:31076/listen.pls&amp;title=Box Uk Radio Danceradiouk&amp;website=http://danceradiouk.com ')"
       href="/player/?mount=http://uk2.internet-radio.com:31076/listen.pls&amp;title=Box Uk Radio Danceradiouk&amp;website=http://danceradiouk.com ">
       <img style="margin-right: 6px;" src="/images/blank.gif" class="sprite sprite-flash" alt="Flash Player"></a>
       <a onClick="_gaq.push(['_trackEvent', 'TuneIn', 'Play - M3U', 'http://uk2.internet-radio.com:31076/listen.pls']);"
       href="http://servers.internet-radio.com/tools/playlistgenerator/?u=http://uk2.internet-radio.com:31076/listen.pls&amp;t=.m3u">
       <img style="margin-right: 6px;" src="/images/blank.gif" class="sprite sprite-wmp" alt="Windows Media Player"></a>
       <a onClick="_gaq.push(['_trackEvent', 'TuneIn', 'Play - PLS', 'http://uk2.internet-radio.com:31076/listen.pls']);"
       href="http://servers.internet-radio.com/tools/playlistgenerator/?u=http://uk2.internet-radio.com:31076/listen.pls&amp;t=.pls">
       <img style="margin-right: 6px;" src="/images/blank.gif" class="sprite sprite-winamp" alt="Winamp">
       <img style="margin-right: 6px;" src="/images/blank.gif" class="sprite sprite-itunes" alt="iTunes"></a>
       <a onClick="_gaq.push(['_trackEvent', 'TuneIn', 'Play - RAM', 'http://uk2.internet-radio.com:31076/listen.pls']);"
       href="http://servers.internet-radio.com/tools/playlistgenerator/?u=http://uk2.internet-radio.com:31076/listen.pls&amp;t=.ram">
       <img src="/images/blank.gif" class="sprite sprite-realplayer" alt="Realplayer"></a><br>
       <div style="margin-top: 10px;"><a href="/stations/80s/">80s</a> <a href="/stations/90s/">90s</a> 00s <a href="/stations/rock/">Rock</a> <a href="/stations/disco/">Disco</a> <a href="/stations/pop/">Pop</a> </div></td>
    <td class="listing2" ><img src="/images/icons/award_star_silver_1.png" alt="Featured" width="16" height="16">
       <a href="/station/danceradioukchatbox/" style="font-weight:bold;">Box Uk Radio Danceradiouk</a>
    <br>Bow Wow Wow - I Want Candy
    <br><a onClick="_gaq.push(['_trackEvent','Link', 'Station Link', 'http://danceradiouk.com ']);"
       class="url" href="http://danceradiouk.com " title="Box Uk Radio Danceradiouk" target="_blank">http://danceradiouk.com </a>
    </td><td class="listing1" align="right" width="100">
    128 Kbps<br>22 Listeners<br>
    <img src="/images/blank.gif" class="sprite sprite-de" alt="Germany"><img src="/images/blank.gif" class="sprite sprite-cy" alt="Cyprus">
    <img src="/images/blank.gif" class="sprite sprite-se" alt="Sweden"><img src="/images/blank.gif" class="sprite sprite-gb" alt="United Kingdom">
    <img src="/images/blank.gif" class="sprite sprite-rw" alt="Rwanda"><img src="/images/blank.gif" class="sprite sprite-mx" alt="Mexico">
    <img src="/images/blank.gif" class="sprite sprite-ru" alt="Russian Federation"><img src="/images/blank.gif" class="sprite sprite-si" alt="Slovenia">
    <img src="/images/blank.gif" class="sprite sprite-ca" alt="Canada"><img src="/images/blank.gif" class="sprite sprite-tt" alt="Trinidad and Tobago">
    <img src="/images/blank.gif" class="sprite sprite-ch" alt="Switzerland"><img src="/images/blank.gif" class="sprite sprite-hu" alt="Hungary">
    <img src="/images/blank.gif" class="sprite sprite-lt" alt="Lithuania">
    </td></tr>
    """
    # Normal
    """
    <tr valign="top" class="stream">
    <td class="listing1" width="120" align="center">
    <img style="margin-right: 6px;" src="/images/icons/blank.png" alt="Blank">
    <a onClick="_gaq.push(['_trackEvent', 'TuneIn', 'Play - M3U', 'http://80.86.106.136:80/listen.pls']);"
       href="http://servers.internet-radio.com/tools/playlistgenerator/?u=http://80.86.106.136:80/listen.pls&amp;t=.m3u">
       <img style="margin-right: 6px;" src="/images/blank.gif" class="sprite sprite-wmp" alt="Windows Media Player"></a>
       <a onClick="_gaq.push(['_trackEvent', 'TuneIn', 'Play - PLS', 'http://80.86.106.136:80/listen.pls']);"
       href="http://servers.internet-radio.com/tools/playlistgenerator/?u=http://80.86.106.136:80/listen.pls&amp;t=.pls">
       <img style="margin-right: 6px;" src="/images/blank.gif" class="sprite sprite-winamp" alt="Winamp">
       <img style="margin-right: 6px;" src="/images/blank.gif" class="sprite sprite-itunes" alt="iTunes"></a>
       <a onClick="_gaq.push(['_trackEvent', 'TuneIn', 'Play - RAM', 'http://80.86.106.136:80/listen.pls']);"
       href="http://servers.internet-radio.com/tools/playlistgenerator/?u=http://80.86.106.136:80/listen.pls&amp;t=.ram">
       <img src="/images/blank.gif" class="sprite sprite-realplayer" alt="Realplayer"></a>
       <br><div style="margin-top: 10px;">Top 40 </div></td>
    <td class="listing2" ><img src="/images/icons/award_star_bronze_1.png" alt="Recommended" width="16" height="16">
       <a href="/station/kissfmromania/" style="font-weight:bold;">KissFM Romania - www.kissfm.ro</a>
    ---ALTERNATIVELY--- <span style="color: #c00;"><b> TDI Radio MP3 48kbps</b></span>
    <br><a onClick="_gaq.push(['_trackEvent','Link', 'Station Link', 'http://www.kissfm.ro']);"
       class="url" href="http://www.kissfm.ro" title="KissFM Romania - www.kissfm.ro" target="_blank">http://www.kissfm.ro</a>
    </td><td class="listing1" align="right" width="100">
    32 Kbps<br>5716 Listeners<br>
    </td></tr>
    """
    # Variation
    """
    <tr><td width="74"> <div id="jquery_jplayer_19" class="jp-jplayer"></div>
	<div id="jp_container_19" class="jp-audio-stream" role="application" aria-label="media player">
    <td class="listing1" width="120" align="center">
		<div class="jp-type-single">
    <img style="margin-right: 6px;" src="/images/icons/blank.png" alt="Blank">
      <a onClick="_gaq.push(['_trackEvent', 'TuneIn', 'Play - M3U', 'http://colostreaming.com:8092/listen.pls']);"
       href="http://servers.internet-radio.com/tools/playlistgenerator/?u=http://colostreaming.com:8092/listen.pls&amp;t=.m3u">
      <img style="margin-right: 6px;" src="/images/blank.gif" class="sprite sprite-wmp" alt="Windows Media Player"></a>
      <a onClick="_gaq.push(['_trackEvent', 'TuneIn', 'Play - PLS', 'http://colostreaming.com:8092/listen.pls']);" 
      href="http://servers.internet-radio.com/tools/playlistgenerator/?u=http://colostreaming.com:8092/listen.pls&amp;t=.pls">
			<div class="jp-gui jp-interface">
				<div class="jp-controls">
					<i onClick="ga('send', 'event', 'tunein', 'playjp', 'http://softrockradio.purestream.net:8032/listen.pls');" style="font-size: 60px;" class="jp-play text-danger mdi-av-play-circle-outline"></i>
					<i style="font-size: 60px;" class="jp-pause text-danger mdi-av-pause-circle-outline"></i>
			</div>	</div>
			<div class="jp-no-solution text-center">
				<small><a href="http://get.adobe.com/flashplayer/" target="_blank">Flash Required</a></small>
      <img style="margin-right: 6px;" src="/images/blank.gif" class="sprite sprite-winamp" alt="Winamp"><img style="margin-right: 6px;" src="/images/blank.gif" class="sprite sprite-itunes" alt="iTunes"></a>
      <a onClick="_gaq.push(['_trackEvent', 'TuneIn', 'Play - RAM', 'http://colostreaming.com:8092/listen.pls']);" href="http://servers.internet-radio.com/tools/playlistgenerator/?u=http://colostreaming.com:8092/listen.pls&amp;t=.ram"><img src="/images/blank.gif" class="sprite sprite-realplayer" alt="Realplayer"></a>
    <br><div style="margin-top: 10px;">Poprock <a href="/stations/dance/">Dance</a> 50s Various </div></td>
	</div></div>
    <td class="listing2" ><img src="/images/icons/award_star_bronze_1.png" alt="Recommended" width="16" height="16">
      <span style="color: #c00;"><b> Jack and Jill Radio Pop Rock Dance 50s Big Band Classical Country Folk Jazz Blue</b></span>
    <br>Vince Gill - When Love Finds You - (Album)When Love Finds You - 1994 Countr
    <br><a onClick="_gaq.push(['_trackEvent','Link', 'Station Link', 'http://www.jackandjillradio.com']);"
     class="url" href="http://www.jackandjillradio.com" title="Jack and Jill Radio Pop Rock Dance 50s Big Band Classical Country Folk Jazz Blues Its All Here!" target="_blank">http://www.jackandjillradio.com</a>
    </td><td class="listing1" align="right" width="100">
    24 Kbps<br></td>
        <div id="volume19" class="text-center" style="visibility: hidden;">
                    <span class="jp-current-time"></span>
                    <div class="jp-volume-bar progress" style="margin:0;">
                            <div class="jp-volume-bar-value progress-bar active progress-bar-striped progress-bar-danger"></div>
        </div>	</div>
	</div>	</td>	<td>
				<h4 class="text-danger" style="display: inline;">SoftRockRadio.net - Classic Soft Rock  (Soft Rock Radio)</h4>
				<br>
				<b>Kenny Loggins - Heart To Heart</b><br>
				<a onClick="ga('send', 'event', 'externallink', 'listing', 'http://www.softrockradio.net');" class="small text-success" href="http://www.softrockradio.net" target="_blank">http://www.softrockradio.net</a>
				<br>Genres: <a onClick="ga('send', 'event', 'genreclick', 'stationlisting', '70s');" href="/stations/70s/">70s</a> 80s <a onClick="ga('send', 'event', 'genreclick', 'stationlisting', 'classic rock');" href="/stations/classic rock/">classic rock</a><!--
				<br><samp>19 http://softrockradio.purestream.net:8032/listen.pls shoutcast1 audio/mpeg</samp>
				<div id="jplayer_inspector_19"></div>-->
			</td>
			<td width="120" class="text-right hidden-xs">
				<p>
              			139 Listeners<br>
				 128 Kbps<br>
				</p>
				<a style="margin:1px" class="btn btn-default btn-xs" onClick="ga('send', 'event', 'tunein', 'playpls', 'http://softrockradio.purestream.net:8032/listen.pls');" href="/servers/tools/playlistgenerator/?u=http://softrockradio.purestream.net:8032/listen.pls&amp;t=.pls">PLS</a>
				<a style="margin:1px" class="btn btn-default btn-xs" onClick="ga('send', 'event', 'tunein', 'playm3u', 'http://softrockradio.purestream.net:8032/listen.pls');" href="/servers/tools/playlistgenerator/?u=http://softrockradio.purestream.net:8032/listen.pls&amp;t=.m3u">M3U</a>
				<a style="margin:1px" class="btn btn-default btn-xs" onClick="ga('send', 'event', 'tunein', 'playram', 'http://softrockradio.purestream.net:8032/listen.pls');" href="/servers/tools/playlistgenerator/?u=http://softrockradio.purestream.net:8032/listen.pls&amp;t=.ram">RAM</a>
				<a style="margin:1px" class="btn btn-default btn-xs" onClick="window.open('/player/?mount=http://softrockradio.purestream.net:8032/listen.pls&amp;title=SoftRockRadio.net - Classic Soft Rock  (Soft Rock Radio)&amp;website=http://www.softrockradio.net','_blank','width=360,height=470'); ga('send', 'event', 'tunein', 'playpopup', 'http://softrockradio.purestream.net:8032/listen.pls');" href="#">FLA</a>
    </td></tr>
    """

    # Regex extraction
    def with_regex(self, html):
        __print__(dbg.PROC, "internet-radio, regex")
        r = []
        html = "\n".join(html)
        
        # Break up into <tr> blocks before extracting bits
        rx_tr = re.compile("""<tr[^>]*>(.+?)</tr>""", re.S)
        rx_data = re.compile(r"""
               \?u=(https?://[^'">]+/listen\.pls)       
               playjp',\s*'(https?://[^'">]+)
               .*?
               <div[^>]+10px[^>]+>(.+?)</div>           
               .*?
               listing2
               .*?
               (?:href="/station/[^>]+> | <b>) ([^<>]+) </[ab]>
               (?:\s*</span>\s*)*
               (?:<br>\s*([^<>]+)\s*<br>)?                
               .*?
               (?:<a[^>]+class="url"[^>]+href="([^<">]+)")?  
               .*?   <h4.*?>([^<>]+)</
               .*?   <b>([^<>]+)</b>
         (?:   .*?   href="(.*?)"        )?
               .+
               listing1
               .*?
               (?:(\d+)\s+Kbps \s*<br>\s*)?                  
               (?:(\d+)\s+Listeners)?
         (?:   .*?   Genres:((?:</?a[^>]+>|\w+|\s+)+)    )?
               .*?   (\d+)\s*Listeners
               .*?   (\d+)\s*Kbps
               (?:\s*<br>\s*)?
               \s*</td>             
        """, re.S|re.X)

        for div in rx_tr.findall(html):
            if div.find('id="pagination"') < 0:
                #__print__(dbg.DATA, len(div))
                uu = rx_data.search(div)
                if uu:
                    (url, genres, title, playing, homepage, bitrate, listeners) = uu.groups()
                    (url, title, playing, homepage, genres, listeners, bitrate) = uu.groups()
                    
                    # transform data
                    r.append({
                        "url": url,
                        "genre": self.strip_tags(genres or ""),
                        "homepage": http.fix_url(homepage or ""),
                        "title": (title or "").strip().replace("\n", " "),