Showing 3 changed files with 662 additions and 0 deletions
+5
README.md
... ...
@@ -1,3 +1,8 @@
1 1
 # radio-tags
2 2
 
3 3
 php cli tools to retrieve online radio tags
4
+
5
+# Requirements
6
+The playlist.xml from radio-playlist needs to be copied in the working directory
7
+
8
+
+652
shoutcastcli.php
... ...
@@ -0,0 +1,652 @@
1
+<?php
2
+$ERROR_STRING="An Error Occured";
3
+function getSSLPage($url) {
4
+      $ch = curl_init();
5
+      curl_setopt($ch, CURLOPT_HEADER, false);
6
+      curl_setopt($ch, CURLOPT_URL, $url);
7
+      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
8
+      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
9
+      $result = curl_exec($ch);
10
+      curl_close($ch);
11
+      return $result;
12
+}
13
+function clean_string($string)
14
+{
15
+	//~ $search = array("&", "<", ">", '\\','u00e9','u00e0', 'u00e8', 'u20ac', 'U00e9', 'U00e0', 'U00c9', 'U00b0', 'u2019', 'U2019', 'u00ea', 'u00ea', 'u00e2', '    U00e2', 'u00f4', 'U00f4');
16
+	//~ $replace = array("&amp;", "&lt;", "&gt;", '', 'e', 'a', 'e', 'e', 'e', 'a', 'e', '°', "'", "'", 'e', 'e', 'a', 'a', 'o', 'o' );
17
+	//~ $substring = str_replace($search, $replace, $string);
18
+	//~ echo "$string";
19
+	$substring = iconv("UTF-8","ASCII//TRANSLIT", $string);
20
+	$substring = strip_tags($substring);
21
+	$search = array("&", "<", ">", '\\', 'N?', 'n?');
22
+	$replace = array("&amp;", "&lt;", "&gt;", '', 'N°', 'n°');
23
+	$substring = str_replace($search, $replace, $substring);
24
+	return $substring;
25
+}
26
+
27
+function get_shoutcast_tags($string) {
28
+	$headers = array();
29
+	$metadata = array();
30
+	$useragent = 'Winamp 2.81';
31
+	$t = parse_url($string);
32
+	$context = stream_context_create([
33
+	  'ssl' => [
34
+		'verify_peer' => false,
35
+		'allow_self_signed' => true,
36
+	  ],
37
+	]);
38
+    $sock = stream_socket_client('tls://'.$t['host'].':'.$t['port'], $errno, $errstr, 10, STREAM_CLIENT_CONNECT, $context); 
39
+    //$sock = stream_socket_client('127.0.0.1:'.$t['port'], $errno, $errstr, 10, STREAM_CLIENT_CONNECT, $context);
40
+    $path = isset($t['path'])?$t['path']:'/';
41
+    if ($sock){
42
+		$request = 'GET '.$path.' HTTP/1.0'."\r\n".
43
+            'Host: '.$t['host']."\r\n".
44
+            'Connection: Close'."\r\n". 
45
+            'User-Agent: '.$useragent."\r\n".
46
+            'Accept: */*'."\r\n".
47
+            'icy-metadata: 1'."\r\n".
48
+            'icy-prebuffer: 65536'."\r\n\r\n";
49
+		if (fwrite($sock, $request)){
50
+            $theaders = $line = '';
51
+            $count=0;
52
+
53
+            while (!feof($sock)){ 
54
+                //~ $line = fgets($sock, 4096); 
55
+                $line = fgets($sock, 16384); 
56
+                $count += strlen($line);
57
+                //~ echo ". ";
58
+                if('' == trim($line)){
59
+                    break;
60
+                }                
61
+                $theaders .= $line;
62
+            }
63
+			$theaders = explode("\r\n", $theaders);
64
+            foreach ($theaders as $header){
65
+                $t = explode(':', $header); 
66
+                if (isset($t[0]) && trim($t[0]) != ''){
67
+                    $name = preg_replace('/[^a-z][^a-z0-9]*/i','', strtolower(trim($t[0])));
68
+                    array_shift($t);
69
+                    $value = trim(implode(':', $t));
70
+                    if ($value != ''){
71
+                        if (is_numeric($value)){
72
+                            $headers[$name] = (int)$value;
73
+                        }else{
74
+                            $headers[$name] = $value;
75
+                        }
76
+                    }
77
+                }
78
+            }
79
+            if (!isset($headers['icymetaint'])){
80
+                $data = ''; $metainterval = 512;
81
+                while(!feof($sock)){
82
+                    $data .= fgetc($sock);
83
+                    if (strlen($data) >= $metainterval) break;
84
+                }
85
+                $matches = array();
86
+                preg_match_all('/([\x00-\xff]{2})\x0\x0([a-z]+)=/i', $data, $matches, PREG_OFFSET_CAPTURE);
87
+				preg_match_all('/([a-z]+)=([a-z0-9\(\)\[\]., ]+)/i', $data, $matches, PREG_SPLIT_NO_EMPTY);
88
+                $title = $artist = '';
89
+                foreach ($matches[0] as $nr => $values){
90
+                  $offset = $values[1];
91
+                  $length = ord($values[0]{0}) + 
92
+                            (ord($values[0]{1}) * 256)+ 
93
+                            (ord($values[0]{2}) * 256*256)+ 
94
+                            (ord($values[0]{3}) * 256*256*256);
95
+                  $info = substr($data, $offset + 4, $length);
96
+                  $seperator = strpos($info, '=');
97
+                  $metadata[substr($info, 0, $seperator)] = substr($info, $seperator + 1);
98
+                    if (substr($info, 0, $seperator) == 'title') $title = substr($info, $seperator + 1);
99
+                    if (substr($info, 0, $seperator) == 'artist') $artist = substr($info, $seperator + 1);
100
+                }
101
+                $metadata['streamtitle'] = $artist . ' - ' . $title;
102
+            }else{
103
+                $metainterval = $headers['icymetaint'];
104
+                $intervals = 0;
105
+                $metadata = '';
106
+                while(1){
107
+                    $data = '';
108
+                    while(!feof($sock)){
109
+                        $data .= fgetc($sock);
110
+                        if (strlen($data) >= $metainterval) break;
111
+                    }
112
+                    //print_data($data);
113
+                    //$len = join(unpack('c', fgetc($sock))) * 16;
114
+                    $len = @join(@unpack('c', fgetc($sock))) * 16;
115
+                    if ($len > 0){
116
+                        $metadata = str_replace("\0", '', fread($sock, $len));
117
+                        break;
118
+                    }else{
119
+                        $intervals++;
120
+                        if ($intervals > 100) break;
121
+                    }
122
+                }
123
+                //~ echo "metadata : [".$metadata."]\n";
124
+                $metarr = explode(';', $metadata);
125
+                foreach ($metarr as $meta){
126
+					$pos_StreamTitle = strpos($meta, "StreamTitle=", 0 );
127
+					if( 0 === $pos_StreamTitle )
128
+					{
129
+						$t = explode('=', $meta);
130
+						if (isset($t[0]) && trim($t[0]) != ''){
131
+							$name = preg_replace('/[^a-z][^a-z0-9]*/i','', strtolower(trim($t[0])));
132
+							array_shift($t);
133
+							$value = trim(implode('=', $t));
134
+							if (substr($value, 0, 1) == '"' || substr($value, 0, 1) == "'"){
135
+								$value = substr($value, 1);
136
+							}
137
+							if (substr($value, -1) == '"' || substr($value, -1) == "'"){
138
+								$value = substr($value, 0, -1);
139
+							}
140
+							if ($value != ''){		
141
+								$valuearr = explode(' - ', $value);
142
+								return $valuearr;
143
+							}
144
+						}
145
+					}
146
+                }
147
+            }
148
+            fclose($sock);
149
+		}
150
+
151
+	} else {
152
+		$metadata[0]=$ERROR_STRING."2";
153
+		$metadata[1]=$errstr;
154
+		return $metadata;
155
+	}
156
+}
157
+
158
+function get_fipradio_tags() {
159
+	$metadata = array();
160
+	$jsondata=file_get_contents("http://www.fipradio.fr/sites/default/files/import_si/si_titre_antenne/FIP_player_current.json");
161
+	$array_json = json_decode($jsondata,TRUE);
162
+	$fipradio_artist = "An Error Occured";
163
+	$fipradio_title = "An Error Occured";
164
+	$fipradio_url = "";
165
+	if( isset($array_json["current"]["song"]) ) {
166
+		$fipradio_title=$array_json["current"]["song"]["titre"];
167
+		if( isset($array_json["current"]["song"]["interpreteMorceau"]) ) {
168
+			$fipradio_artist=$array_json["current"]["song"]["interpreteMorceau"];
169
+		}
170
+		$fipradio_url=$array_json["current"]["song"]["visuel"]["small"];
171
+	}
172
+	$metadata[0]=$fipradio_artist;
173
+	$metadata[1]=$fipradio_title;
174
+	$metadata[2]=$fipradio_url;
175
+	return $metadata; 
176
+}
177
+
178
+function get_lemouv_tags() {
179
+	$metadata = array();
180
+	//~ $jsondata=file_get_contents("http://www.lemouv.fr/sites/default/files/direct.json");
181
+	$jsondata=file_get_contents("http://www.mouv.fr/sites/default/files/import_si/si_titre_antenne/leMouv_player_current.json");
182
+	$array_json = json_decode($jsondata,TRUE);
183
+	//~ $lemouv_title=$array_json["rf_titre_antenne"]["titre"];
184
+	//~ $lemouv_artist=$array_json["rf_titre_antenne"]["interprete"];
185
+	//~ $lemouv_url=$array_json["rf_titre_antenne"]["image"];
186
+	if( isset($array_json["current"]["song"]["titre"]) ) {
187
+		$lemouv_title=$array_json["current"]["song"]["titre"];
188
+	} else {
189
+		$lemouv_title=$array_json["current"]["emission"]["titre"];
190
+	}
191
+	if( isset($array_json["current"]["song"]["interpreteMorceau"]) ) {
192
+		$lemouv_artist=$array_json["current"]["song"]["interpreteMorceau"];
193
+	} else {
194
+		$lemouv_artist=$lemouv_title;
195
+	}
196
+	if( isset($array_json["current"]["song"]["visuel"]["small"]) ) {
197
+		$lemouv_url=$array_json["current"]["song"]["visuel"]["small"];
198
+		$SEARCHSUB='image=';
199
+		$pos_start = strpos($lemouv_url, $SEARCHSUB, 0 );
200
+		if( false !== $pos_start ) {
201
+			$SEARCHSUB2='&';
202
+			$pos_stop = strpos($lemouv_url, $SEARCHSUB2, $pos_start );
203
+			$lemouv_url = substr($lemouv_url, $pos_start+strlen($SEARCHSUB), $pos_stop - $pos_start - strlen($SEARCHSUB) );
204
+		}
205
+	} else {
206
+		$lemouv_url=$array_json["current"]["emission"]["visuel"]["small"];
207
+	}
208
+	//~ $lemouv_title=$array_json["current"]["emission"]["titre"];
209
+	//~ $lemouv_artist=$array_json["current"]["emission"]["lien"];
210
+	//~ $lemouv_url=$array_json["current"]["emission"]["visuel"]["small"];
211
+	if( 0 == strcmp("null",$lemouv_title) )
212
+	{
213
+		$lemouv_title = "An Error Occured";
214
+	}
215
+	if( 0 == strcmp("null",$lemouv_artist) )
216
+	{
217
+		$lemouv_artist = "An Error Occured";
218
+	}
219
+	if( 0 == strcmp("null",$lemouv_url) )
220
+	{
221
+		$lemouv_url = "";
222
+	}
223
+	$metadata[0]=$lemouv_artist;
224
+	$metadata[1]=$lemouv_title;
225
+	$metadata[2]=$lemouv_url;
226
+	return $metadata; 
227
+}
228
+
229
+function get_classic21_tags() {
230
+	$currDate = time();
231
+	$fake_json_data=file_get_contents("http://np.maradio.be/qp/v3/events?rpId=2&serviceNameSize=200&nameSize=200&artistNameSize=200&descriptionSize=200&callback=radioplayer.playing.receive&_=".$currDate );
232
+	//~ echo "http://np.maradio.be/qp/v3/events?rpId=2&serviceNameSize=200&nameSize=200&artistNameSize=200&descriptionSize=200&callback=radioplayer.playing.receive&_=".$currDate;
233
+	$pos_start = strlen("radioplayer.playing.receive(");
234
+	$pos_end = strlen( $fake_json_data ) - 1;
235
+	$jsondata = substr($fake_json_data, $pos_start, $pos_end - $pos_start );
236
+	$array_json = json_decode($jsondata,TRUE);
237
+	$classic21_artist = "An Error Occured";
238
+	$classic21_title = "An Error Occured";
239
+	$classic21_url = "";
240
+	if( isset($array_json["results"]["now"]["name"]) ) {
241
+		$classic21_title=$array_json["results"]["now"]["name"];
242
+	}
243
+	if( isset($array_json["results"]["now"]["artistName"]) ) {
244
+		$classic21_artist=$array_json["results"]["now"]["artistName"];
245
+	}
246
+	$classic21_url=$array_json["results"]["now"]["imageUrl"];
247
+	$metadata[0]=$classic21_artist;
248
+	$metadata[1]=$classic21_title;
249
+	$metadata[2]=$classic21_url;
250
+	return $metadata; 
251
+}
252
+
253
+function get_radio_nova_tags() {
254
+	$metadata = array();
255
+	$radio_nova_artist = "An Error Occured";
256
+	$radio_nova_title = "An Error Occured";
257
+	$radio_nova_url = "";
258
+	$jsondata=file_get_contents("http://www.novaplanet.com/radionova/ontheair");
259
+	$array_json = json_decode($jsondata,TRUE);
260
+	$htmldata=$array_json['track']['markup'];
261
+
262
+	//title
263
+	$SEARCHSUB='<div class="title">';
264
+	//19 = strlen($SEARCHSUB);
265
+	$pos_start = strpos($htmldata, $SEARCHSUB, 0 );
266
+	if( false !== $pos_start ) {
267
+		$SEARCHSUB='</div>';
268
+		$pos_stop = strpos($htmldata, $SEARCHSUB, $pos_start );
269
+		
270
+		$radio_nova_title = substr($htmldata, $pos_start+19, $pos_stop - $pos_start - 19 );
271
+	}
272
+
273
+	//artist
274
+	$SEARCHSUB='<div class="artist">';
275
+	//20 = strlen($SEARCHSUB);
276
+	$pos_start = strpos($htmldata, $SEARCHSUB, 0 );
277
+	if( false !== $pos_start ) {
278
+		$SEARCHSUB='</div>';
279
+		$pos_stop = strpos($htmldata, $SEARCHSUB, $pos_start );
280
+		
281
+		$radio_nova_artist = substr($htmldata, $pos_start+20, $pos_stop - $pos_start - 20 );
282
+		$pattern = '<a href';
283
+		if (preg_match("/<a href/", $radio_nova_artist)) {
284
+			$SEARCHSUB='>      ';
285
+			$pos_start = strpos($radio_nova_artist, $SEARCHSUB, 0 );
286
+			if( false !== $pos_start ) {
287
+				$SEARCHSUB='    </a>';
288
+				$pos_stop = strpos($radio_nova_artist, $SEARCHSUB, $pos_start );
289
+				$radio_nova_artist = substr($radio_nova_artist, $pos_start+7, $pos_stop - $pos_start - 7 );
290
+			}
291
+		}
292
+	}
293
+	
294
+	//url
295
+	$SEARCHSUB='<img src="';
296
+	//10 = strlen($SEARCHSUB);
297
+	$pos_start = strpos($htmldata, $SEARCHSUB, 0 );
298
+	if( false !== $pos_start ) {
299
+		$SEARCHSUB = '" alt="" title="" width="84"';
300
+		$pos_stop = strpos($htmldata, $SEARCHSUB, $pos_start );
301
+		$radio_nova_url = substr($htmldata, $pos_start+10, $pos_stop - $pos_start - 10 );
302
+	}
303
+	$metadata[0]=$radio_nova_artist;
304
+	$metadata[1]=$radio_nova_title;
305
+	$metadata[2]=$radio_nova_url;
306
+	return $metadata; 
307
+}
308
+
309
+function get_fculture_tags() {
310
+	$metadata = array();
311
+	$epochLocal = time();
312
+	$jsondata=file_get_contents("http://www.franceculture.fr/programmes?xmlHttpRequest=1");
313
+	$array_json = json_decode($jsondata,TRUE);
314
+	$i = 0;
315
+	$fculture_artist="An Error Occured";
316
+	$fculture_title="An Error Occured";
317
+	$metadata[0]=$fculture_artist;
318
+	$metadata[1]=$fculture_title;
319
+	while( isset($array_json[$i]) ) {
320
+		$time_start=$array_json[$i]["start"];
321
+		$time_stop=$array_json[$i]["end"];	
322
+		if( $time_stop >= $epochLocal ) {
323
+			if( isset($array_json[$i]["conceptTitle"])) {
324
+			  $fculture_artist=$array_json[$i]["conceptTitle"];
325
+			}
326
+			if( isset($array_json[$i]["expressionTitle"])) {
327
+			  $fculture_title=$array_json[$i]["expressionTitle"];
328
+			}
329
+			$metadata[0]=$fculture_artist;
330
+			$metadata[1]=$fculture_title;
331
+			return $metadata; 
332
+		}
333
+		$i++;
334
+	}
335
+	return $metadata; 
336
+}
337
+
338
+function get_fmusique_tags() {
339
+	$metadata = array();
340
+	$epochts=time();
341
+	$fmusique_artist="An Error Occured";
342
+	$fmusique_title="An Error Occured";
343
+	$jsondata=file_get_contents("https://www.francemusique.fr/programmes?xmlHttpRequest=1");
344
+	$array_json = json_decode($jsondata,TRUE);
345
+	$epochLocal = $epochts-0*3600;
346
+	$i=0;
347
+	while(isset($array_json[$i]["start"])) {
348
+		//~ if( ( $epochLocal < $array_json[$i]["end"] ) &&
349
+		    //~ ( $epochLocal >= $array_json[$i]["start"]) ) {
350
+			//~ if( isset($array_json[$i]["conceptTitle"]) ) {
351
+				//~ $fmusique_artist=$array_json[$i]["conceptTitle"];
352
+			//~ }
353
+			//~ if( isset($array_json[$i]["expressionTitle"]) ) {
354
+				//~ $fmusique_title=$array_json[$i]["expressionTitle"];
355
+			//~ }
356
+			//~ break;
357
+		//~ }
358
+		if( $epochLocal < $array_json[$i]["start"] ) {
359
+			if( isset($array_json[$i-1]["conceptTitle"]) ) {
360
+				$fmusique_artist=$array_json[$i-1]["conceptTitle"];
361
+			}
362
+			if( isset($array_json[$i-1]["expressionTitle"]) ) {
363
+				$fmusique_title=$array_json[$i-1]["expressionTitle"];
364
+			}
365
+			break;
366
+		}
367
+		$i++;
368
+	}
369
+	$metadata[0]=$fmusique_artist;
370
+	$metadata[1]=$fmusique_title;
371
+	return $metadata; 
372
+}
373
+
374
+function get_finfo_tags() {
375
+	$metadata = array();
376
+	$epochts=time();
377
+	$finfo_artist="An Error Occured";
378
+	$finfo_title="An Error Occured";
379
+	$html=file_get_contents("http://www.francetvinfo.fr/replay-radio/grille-des-emissions");
380
+	$SEARCHSUB ='class="program__grid__subline " ';
381
+	$pos_start = strpos($html, $SEARCHSUB, 0 );
382
+	if( false !== $pos_start ) {
383
+		$SEARCHSUB2='<span class="program__grid__line__right__duration">';
384
+		$pos_stop = strpos($html, $SEARCHSUB2, $pos_start );
385
+		$item_content = substr($html, $pos_start+strlen($SEARCHSUB), $pos_stop - $pos_start - strlen($SEARCHSUB) );
386
+		$SEARCHSUB='class="program__grid__line__right__title"> ';
387
+		$pos_start = strpos($item_content, $SEARCHSUB, 0 );
388
+		if( false !== $pos_start ) {
389
+			$SEARCHSUB2='</a>';
390
+			$pos_stop = strpos($item_content, $SEARCHSUB2, $pos_start );
391
+			$finfo_title = substr($item_content, $pos_start+strlen($SEARCHSUB), $pos_stop - $pos_start - strlen($SEARCHSUB) );
392
+			//~ $finfo_title = substr($item_content, $pos_start+strlen($SEARCHSUB));
393
+			//~ echo "=====\n";
394
+		}
395
+		$finfo_title=trim($finfo_title);
396
+		//~ echo $finfo_title;
397
+	}
398
+	$metadata[0]=$finfo_artist;
399
+	$metadata[1]=$finfo_title;
400
+	return $metadata; 
401
+}
402
+
403
+function get_finter_tags() {
404
+	$metadata = array();
405
+	$epochts=time();
406
+	$epochLocal = $epochts;
407
+	$modSeconds=$epochts % 3600;
408
+	$modHours = $epochts / 3600 % 24;
409
+	$epochts=$epochts - $modHours*3600 - $modSeconds - 7200;
410
+	$finter_artist="An Error Occured";
411
+	$finter_title="An Error Occured";
412
+	$metadata[0]=$finter_artist;
413
+	$metadata[1]=$finter_title;
414
+	$jsondata=file_get_contents("https://www.franceinter.fr/programmes");
415
+	$SEARCH_STRING='class="onair-element-content-title">';
416
+	$pos_start = strpos($jsondata, $SEARCH_STRING );
417
+	$title="";
418
+	$artist="";
419
+	if( false !== $pos_start ) {
420
+		$SEARCH_STRING2="</a>";
421
+		$pos_stop = strpos($jsondata, $SEARCH_STRING2, $pos_start );
422
+		if( false !== $pos_stop ) {
423
+			$artist = substr($jsondata,$pos_start+strlen($SEARCH_STRING), $pos_stop - ($pos_start+strlen($SEARCH_STRING)));
424
+			$SEARCH_STRING=' class="onair-element-content-text">';
425
+			$pos_start = strpos($jsondata, $SEARCH_STRING, $pos_stop );
426
+			if( false !== $pos_start ) {
427
+				$SEARCH_STRING2="</a>";
428
+				$pos_stop = strpos($jsondata, $SEARCH_STRING2, $pos_start );
429
+				$title = substr($jsondata,$pos_start+strlen($SEARCH_STRING), $pos_stop - ($pos_start+strlen($SEARCH_STRING)));
430
+			}
431
+		}
432
+		$metadata[0]=$artist;
433
+		$metadata[1]=$title;
434
+	}
435
+	return $metadata;
436
+}
437
+
438
+function get_lgrrock_url() {
439
+	$SEARCHSUB='<img class="border_gris" src="http://www.lagrosseradio.com/artiste/images/';
440
+	$htmldata = file_get_contents("http://www.lagrosseradio.com/_include/ajax_global.php?type_page=0&top_good=-5");
441
+	$pos_start = strpos($htmldata, $SEARCHSUB, 0 );
442
+	if( false !== $pos_start ) {
443
+		$SEARCHSUB='" width="80" height="80"';
444
+		$pos_stop = strpos($htmldata, $SEARCHSUB, $pos_start );
445
+		//30 = strlen('<img class="border_gris" src="');
446
+		$url = substr($htmldata, $pos_start+30, $pos_stop - $pos_start - 30 );
447
+		return $url;
448
+	}
449
+	return "";
450
+}
451
+
452
+function get_lgrmetal_url() {
453
+	$SEARCHSUB='<img class="border_gris" src="http://www.lagrosseradio.com/artiste/images/';
454
+	$htmldata = file_get_contents("http://www.lagrosseradio.com/_include/ajax_global.php?type_page=0&top_good=-5");
455
+	$pos_start = strpos($htmldata, $SEARCHSUB, 0 );
456
+	if( false !== $pos_start ) {
457
+		$SEARCHSUB='<img class="border_gris" src="http://www.lagrosseradio.com/artiste/images/art_pochettes/';
458
+		$pos_start2 = strpos($htmldata, $SEARCHSUB, $pos_start+strlen($SEARCHSUB) );
459
+		if( false !== $pos_start2 ) {
460
+			$SEARCHSUB='" width="80" height="80"';
461
+			$pos_stop = strpos($htmldata, $SEARCHSUB, $pos_start2 );
462
+			//30 = strlen('<img class="border_gris" src="');
463
+			$url = substr($htmldata, $pos_start2+30, $pos_stop - $pos_start2 - 30 );
464
+			return $url;
465
+		}
466
+	}
467
+	return "";
468
+}
469
+
470
+function get_lgrreggae_url() {
471
+	$SEARCHSUB='<img class="border_gris" src="http://www.lagrosseradio.com/artiste/images/';
472
+	$htmldata = file_get_contents("http://www.lagrosseradio.com/_include/ajax_global.php?type_page=0&top_good=-5");
473
+	$pos_start = strpos($htmldata, $SEARCHSUB, 0 );
474
+	if( false !== $pos_start ) {
475
+		$pos_start2 = strpos($htmldata, $SEARCHSUB, $pos_start+strlen($SEARCHSUB) );
476
+		if( false !== $pos_start2 ) {
477
+			$pos_start3 = strpos($htmldata, $SEARCHSUB, $pos_start2+strlen($SEARCHSUB) );
478
+			if( false !== $pos_start3 ) {
479
+				$SEARCHSUB='" width="80" height="80"';
480
+				$pos_stop = strpos($htmldata, $SEARCHSUB, $pos_start3 );
481
+				//30 = strlen('<img class="border_gris" src="');
482
+				$url = substr($htmldata, $pos_start3+30, $pos_stop - $pos_start3 - 30 );
483
+				return $url;
484
+			}
485
+		}
486
+	}
487
+	return "";
488
+}
489
+
490
+function print_data($data){
491
+    $data = str_split($data);
492
+    $c = 0;
493
+    $string = '';
494
+    echo "<pre>\n000000 ";
495
+    foreach ($data as $char){
496
+        $string .= addcslashes($char, "\n\r\0\t");
497
+        $hex = dechex(join(unpack('C', $char)));
498
+        if ($c % 4 == 0) echo ' ';
499
+        if ($c % (4*4) == 0 && $c != 0){
500
+          foreach (str_split($string) as $s){
501
+            //echo " $string\n";
502
+            if (ord($s) < 32 || ord($s) > 126){
503
+              echo '\\'.ord($s);
504
+            }else{
505
+              echo $s;
506
+            }
507
+          }
508
+          echo "\n";
509
+          $string = '';
510
+          echo str_pad($c, 6, '0', STR_PAD_LEFT).'  ';
511
+        }
512
+        if (strlen($hex) < 1) $hex = '00';
513
+        if (strlen($hex) < 2) $hex = '0'.$hex;
514
+          echo $hex.' ';
515
+        $c++;
516
+    }
517
+    echo "  $string\n</pre>";
518
+}
519
+
520
+function get_rfi_tags() {
521
+	$jsondata=file_get_contents("http://www.rfi.fr/current-program-grid-info/monde/?xmlHttpRequest=1");
522
+	$array_json = json_decode($jsondata,TRUE);
523
+	$rfimonde_artist = "An Error Occured";
524
+	$rfimonde_title = "An Error Occured";
525
+	$rfimonde_url = "";
526
+	if( isset($array_json["currentProgramTitle"]) ) {
527
+		$rfimonde_title=$array_json["currentProgramTitle"];
528
+	}
529
+	//~ if( isset($array_json["results"]["now"]["artistName"]) ) {
530
+		//~ $rfimonde_artist=$array_json["results"]["now"]["artistName"];
531
+	//~ }
532
+	//~ $rfimonde_url=$array_json["results"]["now"]["imageUrl"];
533
+	$metadata[0]=$rfimonde_artist;
534
+	$metadata[1]=$rfimonde_title;
535
+	$metadata[2]=$rfimonde_url;
536
+	return $metadata; 
537
+}
538
+
539
+$DEBUG=0;
540
+if( $DEBUG != 0 )
541
+{
542
+	$STREAMURL="http://67.212.163.150:80/;stream.nsv";
543
+	echo "[DEBUG] stream : $STREAMURL<br>\n";
544
+	clean_string('http://str45.streamakaci.com:8014/;895614762790501stream.nsv');
545
+	$tags = array();
546
+	$tags = get_shoutcast_tags($STREAMURL);
547
+}
548
+
549
+
550
+//~ echo "Load done\n";
551
+//~ exit(0);
552
+//$xsl_contents = file_get_contents( "https://files.kawi.fr:8000/status.xsl" );
553
+$xsl_contents = getSSLPage("https://files.kawi.fr:8000/status.xsl" );
554
+$xsl_contents_utf8 = mb_convert_encoding($xsl_contents, 'HTML-ENTITIES', "UTF-8");
555
+$doc = new DOMDocument();
556
+$doc->loadHTML($xsl_contents_utf8);
557
+//~ $doc->loadHTML($xsl_contents);
558
+		
559
+$file_contents_playlist=file_get_contents( "playlist.xml" );
560
+$xml = simplexml_load_string($file_contents_playlist);
561
+$json = json_encode($xml);
562
+$array = json_decode($json,TRUE);
563
+$CPTMAX=0;
564
+foreach ( $array as $channel_list )
565
+{
566
+	echo "<?xml version='1.0' encoding='UTF-8'?>\n";
567
+	echo "<channel_list>\n";
568
+	foreach ( $channel_list as $channel )
569
+	{
570
+		$track_artist=$ERROR_STRING;
571
+		$track_title=$ERROR_STRING;
572
+		$track_url="";
573
+		$track=array();
574
+
575
+		//JS:var mountpoints = div.getElementsByTagName("h3");
576
+		if( 1 == $channel['icy'] ) {
577
+			$i = 0;
578
+			foreach ($doc->getElementsByTagName('h3') as $node) {
579
+				$mountpoint_raw=$node->textContent;
580
+				$mountpoint_name = substr($mountpoint_raw, 13, strlen($mountpoint_raw) - 13);
581
+				if( 0 == strcmp( $channel['shortname'], $mountpoint_name ) ) {
582
+					$j = 0;
583
+					foreach ( $doc->getElementsByTagName('table') as $table ) {
584
+						if( $j == 2*$i+1 ) {
585
+							$streamdata_raw=$table->textContent;
586
+							$SEARCHSUB="Current Song:";
587
+							$pos_start = strpos($streamdata_raw, $SEARCHSUB, 0 );
588
+							if( false !== $pos_start ) {
589
+								$streamdata_title_raw = substr($streamdata_raw, $pos_start+strlen($SEARCHSUB));
590
+								$SEARCHSUB=" - ";
591
+								$pos_start = strpos($streamdata_title_raw, $SEARCHSUB, 0 );
592
+							}
593
+							if(  false !== $pos_start ) {
594
+								$track_artist=substr($streamdata_title_raw,0,$pos_start);
595
+								$track_title=substr($streamdata_title_raw,$pos_start+strlen($SEARCHSUB));
596
+							} else {
597
+								$track_title=$streamdata_title_raw;
598
+							}
599
+						}
600
+						$j++;
601
+					}
602
+				}	
603
+				$i++;			
604
+			}
605
+		} else {
606
+			//JSON or OTHERS tags
607
+			$track_artist=$ERROR_STRING;
608
+			$track_title=$ERROR_STRING;
609
+			$track_url="";
610
+			if( 0 == strcmp($channel['shortname'],"fipradio") ) {
611
+				$track=get_fipradio_tags();
612
+			} else if( 0 == strcmp($channel['shortname'],"lemouv") ) {
613
+				$track=get_lemouv_tags();
614
+			} else if( 0 == strcmp($channel['shortname'],"classic21") ) {
615
+				$track=get_classic21_tags();
616
+			} else if( 0 == strcmp($channel['shortname'],"radio_nova") ) {
617
+				$track=get_radio_nova_tags();
618
+			} else if( 0 == strcmp($channel['shortname'],"finfo") ) {
619
+				$track=get_finfo_tags();
620
+			} else if( 0 == strcmp($channel['shortname'],"finter") ) {
621
+				$track=get_finter_tags();
622
+			} else if( 0 == strcmp($channel['shortname'],"fculture") ) {
623
+				$track=get_fculture_tags();
624
+			} else if( 0 == strcmp($channel['shortname'],"fmusique") ) {
625
+				$track=get_fmusique_tags();
626
+			} else if( 0 == strcmp($channel['shortname'],"rfi") ) {
627
+				$track=get_rfi_tags();
628
+			}
629
+			
630
+			if( isset( $track[0] ) ) {
631
+				$track_artist=trim($track[0]);
632
+			}
633
+			if( isset( $track[1] ) ) {
634
+				$track_title=trim($track[1]);
635
+			}
636
+			if( isset( $track[2] ) ) {
637
+				$track_url=trim($track[2]);
638
+			}
639
+		}
640
+		$track_artist=clean_string($track_artist);
641
+		$track_title=clean_string($track_title);
642
+		echo "<channel>\n";
643
+		echo "\t<title>".$channel['title']."</title>\n";
644
+		echo "\t<shortname>".$channel['shortname']."</shortname>\n";
645
+		echo "\t<track_artist>".$track_artist."</track_artist>\n";
646
+		echo "\t<track_title>".$track_title."</track_title>\n";
647
+		echo "\t<track_url>".$track_url."</track_url>\n";
648
+		echo "</channel>\n";
649
+	}
650
+	echo "</channel_list>\n";
651
+}
652
+?>
+5
tags.sh
... ...
@@ -0,0 +1,5 @@
1
+#!/bin/bash
2
+cd /var/www/html/radio
3
+php /var/www/html/radio/shoutcastcli.php > /var/www/html/radio/tags.xml.new
4
+cp /var/www/html/radio/tags.xml.new /var/www/html/radio/tags.xml
5
+