Showing 2 changed files with 150 additions and 100 deletions
+146 -97
shoutcastcli.php
... ...
@@ -12,10 +12,6 @@ function getSSLPage($url) {
12 12
 }
13 13
 function clean_string($string)
14 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 15
 	$substring = iconv("UTF-8","ASCII//TRANSLIT", $string);
20 16
 	$substring = strip_tags($substring);
21 17
 	$search = array("&", "<", ">", '\\', 'N?', 'n?');
... ...
@@ -35,9 +31,10 @@ function get_shoutcast_tags($string) {
35 31
 		'allow_self_signed' => true,
36 32
 	  ],
37 33
 	]);
38
-    $sock = stream_socket_client('tls://'.$t['host'].':'.$t['port'], $errno, $errstr, 10, STREAM_CLIENT_CONNECT, $context); 
34
+    //$sock = stream_socket_client('tls://'.$t['host'].':'.$t['port'], $errno, $errstr, 10, STREAM_CLIENT_CONNECT, $context); 
35
+    $sock = stream_socket_client('tcp://'.$t['host'].':'.$t['port'], $errno, $errstr, 10, STREAM_CLIENT_CONNECT, $context); 
39 36
     //$sock = stream_socket_client('127.0.0.1:'.$t['port'], $errno, $errstr, 10, STREAM_CLIENT_CONNECT, $context);
40
-    $path = isset($t['path'])?$t['path']:'/';
37
+  $path = isset($t['path'])?$t['path']:'/';
41 38
     if ($sock){
42 39
 		$request = 'GET '.$path.' HTTP/1.0'."\r\n".
43 40
             'Host: '.$t['host']."\r\n".
... ...
@@ -60,7 +57,7 @@ function get_shoutcast_tags($string) {
60 57
                 }                
61 58
                 $theaders .= $line;
62 59
             }
63
-			$theaders = explode("\r\n", $theaders);
60
+			      $theaders = explode("\r\n", $theaders);
64 61
             foreach ($theaders as $header){
65 62
                 $t = explode(':', $header); 
66 63
                 if (isset($t[0]) && trim($t[0]) != ''){
... ...
@@ -76,6 +73,8 @@ function get_shoutcast_tags($string) {
76 73
                     }
77 74
                 }
78 75
             }
76
+            var_dump($theaders);
77
+            exit(0);
79 78
             if (!isset($headers['icymetaint'])){
80 79
                 $data = ''; $metainterval = 512;
81 80
                 while(!feof($sock)){
... ...
@@ -182,38 +181,14 @@ function get_fipradio_tags() {
182 181
 }
183 182
 
184 183
 function get_lemouv_tags() {
185
-	$metadata = array();
186
-	//~ $jsondata=file_get_contents("http://www.lemouv.fr/sites/default/files/direct.json");
187
-	$jsondata=file_get_contents("http://www.mouv.fr/sites/default/files/import_si/si_titre_antenne/leMouv_player_current.json");
188
-	$array_json = json_decode($jsondata,TRUE);
189
-	//~ $lemouv_title=$array_json["rf_titre_antenne"]["titre"];
190
-	//~ $lemouv_artist=$array_json["rf_titre_antenne"]["interprete"];
191
-	//~ $lemouv_url=$array_json["rf_titre_antenne"]["image"];
192
-	if( isset($array_json["current"]["song"]["titre"]) ) {
193
-		$lemouv_title=$array_json["current"]["song"]["titre"];
194
-	} else {
195
-		$lemouv_title=$array_json["current"]["emission"]["titre"];
196
-	}
197
-	if( isset($array_json["current"]["song"]["interpreteMorceau"]) ) {
198
-		$lemouv_artist=$array_json["current"]["song"]["interpreteMorceau"];
199
-	} else {
200
-		$lemouv_artist=$lemouv_title;
201
-	}
202
-	if( isset($array_json["current"]["song"]["visuel"]["small"]) ) {
203
-		$lemouv_url=$array_json["current"]["song"]["visuel"]["small"];
204
-		$SEARCHSUB='image=';
205
-		$pos_start = strpos($lemouv_url, $SEARCHSUB, 0 );
206
-		if( false !== $pos_start ) {
207
-			$SEARCHSUB2='&';
208
-			$pos_stop = strpos($lemouv_url, $SEARCHSUB2, $pos_start );
209
-			$lemouv_url = substr($lemouv_url, $pos_start+strlen($SEARCHSUB), $pos_stop - $pos_start - strlen($SEARCHSUB) );
210
-		}
211
-	} else {
212
-		$lemouv_url=$array_json["current"]["emission"]["visuel"]["small"];
213
-	}
214
-	//~ $lemouv_title=$array_json["current"]["emission"]["titre"];
215
-	//~ $lemouv_artist=$array_json["current"]["emission"]["lien"];
216
-	//~ $lemouv_url=$array_json["current"]["emission"]["visuel"]["small"];
184
+  $metadata = array();
185
+  $mouvfront = file_get_contents("https://www.mouv.fr/");
186
+  $re = '/<script>window\.REDUX_STATE = (.+?)<\/script>/';
187
+  preg_match($re, $mouvfront, $matches);
188
+  $array_json = json_decode($matches[1],TRUE);
189
+  $lemouv_artist=$array_json["now"]["current"]["playing_item"]["title"];
190
+  $lemouv_title=$array_json["now"]["current"]["playing_item"]["subtitle"];
191
+  $lemouv_url=$array_json["now"]["current"]["playing_item"]["cover"];
217 192
 	if( 0 == strcmp("null",$lemouv_title) )
218 193
 	{
219 194
 		$lemouv_title = "An Error Occured";
... ...
@@ -232,10 +207,95 @@ function get_lemouv_tags() {
232 207
 	return $metadata; 
233 208
 }
234 209
 
210
+function get_europe1_tags() {
211
+  $metadata = array();
212
+  $front = file_get_contents("https://www.europe1.fr/");
213
+  //Url
214
+  $re = '/<div class="visuel_cnt"><img alt="" src="(.+?)" class="img-responsive" \/><\/div>/';
215
+  preg_match($re, $front, $matches);
216
+  $metadata[2]=$matches[1];
217
+
218
+  //Artist
219
+  $re = '/<div class="horaire">(.+?)<\/div>/';
220
+  preg_match($re, $front, $matches);
221
+  $metadata[0]=$matches[1];
222
+
223
+  //Title
224
+  $re = '/<div class="animateur">(.+?)<\/div>/';
225
+  preg_match($re, $front, $matches);
226
+  $metadata[1]=$matches[1];
227
+  //Force HTTPS
228
+  $metadata[2] = str_replace("http:", "https:", $metadata[2]);
229
+  return $metadata;
230
+}
231
+
232
+function get_partyvibe_tags() {
233
+  $metadata = array();
234
+  $front = file_get_contents("http://94.130.238.52:8000/played.html");
235
+  $re = '/(.+)<td>(.+?)<td style="padding: 0 10px;">/';
236
+  preg_match($re, $front, $matches);
237
+  $re = '/(.+?) - (.+)/';
238
+  preg_match($re, $matches[2], $matchesmeta);
239
+  $metadata[0]=$matchesmeta[1];
240
+  $metadata[1]=$matchesmeta[2];
241
+  $metadata[2]="";
242
+  return $metadata;
243
+}
244
+
245
+function get_radio_classique_tags() {
246
+  $metadata = array();
247
+  $front = file_get_contents("https://d3gf3bsqck8svl.cloudfront.net/direct-metadata/current.json");
248
+  $array_json = json_decode($front,TRUE);
249
+  $metadata[0]=$array_json["auteur"];
250
+  $metadata[1]=$array_json["titre"];
251
+  $metadata[2]="";
252
+  return $metadata;
253
+}
254
+
255
+function get_bbcws_tags() {
256
+  $metadata = array();
257
+  $front = file_get_contents("https://www.bbc.co.uk/radio/player/bbc_world_service");
258
+  
259
+  $re = '/>(.+?)  <\/a>  <\/h2> <p/';
260
+  preg_match($re, $front, $matches);
261
+  $pos_start = strrpos($matches[1],'>  ');
262
+  $metadata[1]=substr($matches[1], $pos_start+3);
263
+  
264
+  $re = '/>  (.+?) <\/a>  <\/h2> <h2 id="title">/';
265
+  preg_match($re, $front, $matches);
266
+  $pos_start = strrpos($matches[1],'>  ');
267
+  $metadata[0]=substr($matches[1], $pos_start+3);
268
+
269
+  $metadata[2]="";
270
+  return $metadata;
271
+}
272
+
273
+function get_soma_tags($name) {
274
+  $urlbase = "https://somafm.com/$name/";
275
+  $front = file_get_contents($urlbase);
276
+  $re = '/<span class="red">Now Playing: <\/span>(.+)/';
277
+  preg_match($re, $front, $matches);
278
+  $re = '/(.+?) - (.+)/';
279
+  preg_match($re, $matches[1], $explode);
280
+  $metadata[0]=$explode[1];
281
+  $metadata[1]=$explode[2];
282
+  $metadata[2]="";
283
+  return $metadata;
284
+}
285
+
286
+function tag_output($title,$tagshortname,$tagartist,$tagtitle,$tagimageurl){
287
+		echo "<channel>\n";
288
+		echo "\t<title>".$title."</title>\n";
289
+		echo "\t<shortname>".$tagshortname."</shortname>\n";
290
+		echo "\t<track_artist>".$tagartist."</track_artist>\n";
291
+		echo "\t<track_title>".$tagtitle."</track_title>\n";
292
+		echo "\t<track_url>".$tagimageurl."</track_url>\n";
293
+		echo "</channel>\n";
294
+}
295
+
235 296
 function get_classic21_tags() {
236 297
 	$currDate = time();
237
-	$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 );
238
-	//~ echo "http://np.maradio.be/qp/v3/events?rpId=2&serviceNameSize=200&nameSize=200&artistNameSize=200&descriptionSize=200&callback=radioplayer.playing.receive&_=".$currDate;
298
+  $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 );
239 299
 	$pos_start = strlen("radioplayer.playing.receive(");
240 300
 	$pos_end = strlen( $fake_json_data ) - 1;
241 301
 	$jsondata = substr($fake_json_data, $pos_start, $pos_end - $pos_start );
... ...
@@ -245,14 +305,20 @@ function get_classic21_tags() {
245 305
 	$classic21_url = "";
246 306
 	if( isset($array_json["results"]["now"]["name"]) ) {
247 307
 		$classic21_title=$array_json["results"]["now"]["name"];
248
-	}
308
+  } else {
309
+		$classic21_title=$array_json["results"]["now"]["programmeName"];
310
+  }
249 311
 	if( isset($array_json["results"]["now"]["artistName"]) ) {
250 312
 		$classic21_artist=$array_json["results"]["now"]["artistName"];
251
-	}
252
-	$classic21_url=$array_json["results"]["now"]["imageUrl"];
313
+  } else {
314
+		$classic21_title=$array_json["results"]["now"]["serviceName"];
315
+  }
316
+  $classic21_url=$array_json["results"]["now"]["imageUrl"];
253 317
 	$metadata[0]=$classic21_artist;
254 318
 	$metadata[1]=$classic21_title;
255 319
 	$metadata[2]=$classic21_url;
320
+  //Force HTTPS
321
+  $metadata[2] = str_replace("http:", "https:", $metadata[2]);
256 322
 	return $metadata; 
257 323
 }
258 324
 
... ...
@@ -261,54 +327,12 @@ function get_radio_nova_tags() {
261 327
 	$radio_nova_artist = "An Error Occured";
262 328
 	$radio_nova_title = "An Error Occured";
263 329
 	$radio_nova_url = "";
264
-	$jsondata=file_get_contents("http://www.novaplanet.com/radionova/ontheair");
265
-	$array_json = json_decode($jsondata,TRUE);
266
-	$htmldata=$array_json['track']['markup'];
267
-
268
-	//title
269
-	$SEARCHSUB='<div class="title">';
270
-	//19 = strlen($SEARCHSUB);
271
-	$pos_start = strpos($htmldata, $SEARCHSUB, 0 );
272
-	if( false !== $pos_start ) {
273
-		$SEARCHSUB='</div>';
274
-		$pos_stop = strpos($htmldata, $SEARCHSUB, $pos_start );
275
-		
276
-		$radio_nova_title = substr($htmldata, $pos_start+19, $pos_stop - $pos_start - 19 );
277
-	}
278
-
279
-	//artist
280
-	$SEARCHSUB='<div class="artist">';
281
-	//20 = strlen($SEARCHSUB);
282
-	$pos_start = strpos($htmldata, $SEARCHSUB, 0 );
283
-	if( false !== $pos_start ) {
284
-		$SEARCHSUB='</div>';
285
-		$pos_stop = strpos($htmldata, $SEARCHSUB, $pos_start );
286
-		
287
-		$radio_nova_artist = substr($htmldata, $pos_start+20, $pos_stop - $pos_start - 20 );
288
-		$pattern = '<a href';
289
-		if (preg_match("/<a href/", $radio_nova_artist)) {
290
-			$SEARCHSUB='>      ';
291
-			$pos_start = strpos($radio_nova_artist, $SEARCHSUB, 0 );
292
-			if( false !== $pos_start ) {
293
-				$SEARCHSUB='    </a>';
294
-				$pos_stop = strpos($radio_nova_artist, $SEARCHSUB, $pos_start );
295
-				$radio_nova_artist = substr($radio_nova_artist, $pos_start+7, $pos_stop - $pos_start - 7 );
296
-			}
297
-		}
298
-	}
299
-	
300
-	//url
301
-	$SEARCHSUB='<img src="';
302
-	//10 = strlen($SEARCHSUB);
303
-	$pos_start = strpos($htmldata, $SEARCHSUB, 0 );
304
-	if( false !== $pos_start ) {
305
-		$SEARCHSUB = '" alt="" title="" width="84"';
306
-		$pos_stop = strpos($htmldata, $SEARCHSUB, $pos_start );
307
-		$radio_nova_url = substr($htmldata, $pos_start+10, $pos_stop - $pos_start - 10 );
308
-	}
309
-	$metadata[0]=$radio_nova_artist;
310
-	$metadata[1]=$radio_nova_title;
311
-	$metadata[2]=$radio_nova_url;
330
+	//$jsondata=file_get_contents("http://www.novaplanet.com/radionova/ontheair");
331
+  $jsondata=file_get_contents("http://www.nova.fr/radio/19577/player");
332
+  $array_json = json_decode($jsondata,TRUE);
333
+  $metadata[0]=$array_json['currentTrack']['artist'];
334
+  $metadata[1]=$array_json['currentTrack']['title'];
335
+  $metadata[2]="https://www.nova.fr".$array_json['currentTrack']['image'];
312 336
 	return $metadata; 
313 337
 }
314 338
 
... ...
@@ -545,11 +569,13 @@ function get_rfi_tags() {
545 569
 $DEBUG=0;
546 570
 if( $DEBUG != 0 )
547 571
 {
548
-	$STREAMURL="http://67.212.163.150:80/;stream.nsv";
572
+	$STREAMURL="http://ice1.somafm.com:80/covers-128-mp3";
549 573
 	echo "[DEBUG] stream : $STREAMURL<br>\n";
550 574
 	clean_string('http://str45.streamakaci.com:8014/;895614762790501stream.nsv');
551 575
 	$tags = array();
552
-	$tags = get_shoutcast_tags($STREAMURL);
576
+  $tags = get_shoutcast_tags($STREAMURL);
577
+  var_dump($tags);
578
+  exit(0);  
553 579
 }
554 580
 
555 581
 
... ...
@@ -633,6 +659,26 @@ foreach ( $array as $channel_list )
633 659
 				$track=get_fmusique_tags();
634 660
 			} else if( 0 == strcmp($channel['shortname'],"rfi") ) {
635 661
 				$track=get_rfi_tags();
662
+			} else if( 0 == strcmp($channel['shortname'],"europe1") ) {
663
+				$track=get_europe1_tags();
664
+			} else if( 0 == strcmp($channel['shortname'],"radio_classique") ) {
665
+				$track=get_radio_classique_tags();
666
+			} else if( 0 == strcmp($channel['shortname'],"covers") ) {
667
+        $track = get_soma_tags($channel['shortname']);
668
+			} else if( 0 == strcmp($channel['shortname'],"groovesalad") ) {
669
+        $track = get_soma_tags($channel['shortname']);
670
+			} else if( 0 == strcmp($channel['shortname'],"suburbsofgoa") ) {
671
+        $track = get_soma_tags($channel['shortname']);
672
+			} else if( 0 == strcmp($channel['shortname'],"folkfwd") ) {
673
+        $track = get_soma_tags($channel['shortname']);
674
+			} else if( 0 == strcmp($channel['shortname'],"bagel") ) {
675
+        $track = get_soma_tags($channel['shortname']);
676
+			} else if( 0 == strcmp($channel['shortname'],"metal") ) {
677
+        $track = get_soma_tags($channel['shortname']);
678
+			} else if( 0 == strcmp($channel['shortname'],"partyvibe") ) {
679
+        $track = get_partyvibe_tags();
680
+			} else if( 0 == strcmp($channel['shortname'],"bbcws") ) {
681
+        $track = get_bbcws_tags();
636 682
 			}
637 683
 			
638 684
 			if( isset( $track[0] ) ) {
... ...
@@ -646,15 +692,18 @@ foreach ( $array as $channel_list )
646 692
 			}
647 693
 		}
648 694
 		$track_artist=clean_string($track_artist);
649
-		$track_title=clean_string($track_title);
695
+    $track_title=clean_string($track_title);
696
+    /*
650 697
 		echo "<channel>\n";
651 698
 		echo "\t<title>".$channel['title']."</title>\n";
652 699
 		echo "\t<shortname>".$channel['shortname']."</shortname>\n";
653 700
 		echo "\t<track_artist>".$track_artist."</track_artist>\n";
654 701
 		echo "\t<track_title>".$track_title."</track_title>\n";
655 702
 		echo "\t<track_url>".$track_url."</track_url>\n";
656
-		echo "</channel>\n";
657
-	}
703
+    echo "</channel>\n";
704
+     */
705
+    tag_output($channel['title'],$channel['shortname'],$track_artist,$track_title,$track_url);
706
+  }
658 707
 	echo "</channel_list>\n";
659 708
 }
660 709
 ?>
+4 -3
tags.sh
... ...
@@ -1,5 +1,6 @@
1 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
2
+RUNDIR=/var/www/html/radio
3
+cd $RUNDIR
4
+php $RUNDIR/shoutcastcli.php > $RUNDIR/tags.xml.new
5
+cp $RUNDIR/tags.xml.new $RUNDIR/tags.xml
5 6