-
Notifications
You must be signed in to change notification settings - Fork 38
Description
Hi all, it is not an issue of the library, but I do not know where to find documentation to solve the issue.
Most of small local radios use redirect url, for instance:
1- Radio Kankan (it is a cityname of Guinea West Africa):
http://stream.zeno.fm//ab9q4v3mb
The console gives:
Request access to: Radio KANKAN
Request access to: stream.zeno.fm:80/ab9q4v3mb
Try to reconnect...
-->HTTP/1.1 302
-->location: http://stream.zenolive.com/ab9q4v3mb?zs=3rXgc_2kRwuG_ScHzZfXSQ
new url fields = stream.zenolive.com + /ab9q4v3mb?zs=3rXgc_2kRwuG_ScHzZfXSQ
-->Access-Control-Allow-Origin: *
-->Location: http://node-29.zeno.fm/ab9q4v3mb?zs=3rXgc_2kRwuG_ScHzZfXSQ&rj-tok=AAABf7urGXYASuMmCX_O1AEP9A&rj-ttl=5
new url fields = node-29.zeno.fm + /ab9q4v3mb?zs=3rXgc_2kRwuG_ScHzZfXSQ&rj-tok=AAABf7urGXYASuMmCX_O1AEP9A&rj-ttl=5
@@>content-type: audio/mpeg
icy-name: -
There are several redirection, however after all the content-type: audio/mpeg appears and the station works fine
2- Kassara Barikama (Bamako Mali):
http://stream.zeno.fm/u5u4gvaxh4duv
The console gives:
Request access to: Kassara Barikama
Request access to: stream.zeno.fm:80/u5u4gvaxh4duv
Try to reconnect...
-->HTTP/1.1 302
-->location: http://stream.zenolive.com/u5u4gvaxh4duv?zs=xEwnpDv8SV2bzd5D7yTBqw
new url fields = stream.zenolive.com + u5u4gvaxh4duv?zs=xEwnpDv8SV2bzd5D7yTBqw
-->Access-Control-Allow-Origin: *
-->Location: http://node-35.zeno.fm/u5u4gvaxh4duv?zs=xEwnpDv8SV2bzd5D7yTBqw&rj-tok=AAABf7uvXJcAUn8ykeWJtSNSQQ&rj-ttl=5
new url fields = node-35.zeno.fm + /u5u4gvaxh4duv?zs=xEwnpDv8SV2bzd5D7yTBqw&rj-tok=AAABf7uvXJcAUn8ykeWJtSNSQQ&rj-ttl=5
-->location: http://stream.zeno.fm/y8sgkhhra3quv?zs=xEwnpDv8SV2bzd5D7yTBqw
new url fields = stream.zeno.fm + /y8sgkhhra3quv?zs=xEwnpDv8SV2bzd5D7yTBqw
@@>Content-length: 90
Cache-Control: no-cache
Connection: close
Content-Type: text/html
400 Bad request
Try to reconnect...
Try to reconnect...
This station - and many others - return a bad content-type. But both stations works fine with a PC and modzilla. So something is missing in the request to access to the url because there is reason it does not work on the ESP8266 webradio example
Here is the code:
// si perte du signal
if( !client.connected() ) {
Serial.println("Try to reconnect...");
headerSearch = true;
bufferNumber = 0;
if( client.connect(urlStation, portStation.toInt()) ) {
client.print(String("GET ") + pathStation + " HTTP/1.1\r\n" +
"Host: " + urlStation + "\r\n" +
"Connection: close\r\n\r\n");
} // end of client.connect test
} // end of !client.connected() test
// si tout va bien :)
if( client.available() && !pause ) {
// look foward url rediction type 302
if( headerSearch ) {
headerSearch = false;
String header = client.readStringUntil('\n'); // read the header until \n
Serial.print("-->"); Serial.println(header);
while((header.indexOf("HTTP/1.0 302") >= 0)||(header.indexOf("HTTP/1.1 302") >= 0)) { // it may have several
while((header.indexOf("Location:") < 0) && (header.indexOf("location:") < 0)) { // new url to reach
header = client.readStringUntil('\n');
Serial.print("-->"); Serial.println(header);
}
// get fields separated by "/"
// Example=> Location: http://node-28.zeno.fm/20mdfd30wqzuv?rj-ttl=5&rj-tok=AAABfhD5HCcAg9QOMJ5yH8jRjA
String newPortStation = "80";
String newUrlStation = "";
String newPathStation = "/";
if( header[14] == 's' ) newPortStation = "443";
byte index = 0;
while( header[index] != '/' ) index ++;
index +=2;
while( header[index] != '/' ) {
newUrlStation += header[index];
index ++;
}
index ++;
for( byte k=index ; k < header.length() ; k++ ) newPathStation += header[k];
Serial.print("new url fields = ");
Serial.print(newUrlStation); Serial.print(" + "); Serial.println(newPathStation);
if( client.connect(newUrlStation, newPortStation.toInt()) ) {
client.print(String("GET ") + newPathStation + " HTTP/1.1\r\n" +
"Host: " + urlStation + "\r\n" +
"Connection: close\r\n\r\n");
} // end of client.connect test
header = client.readStringUntil('\n'); // read the header until \n
} // end of while on header
} // end of test on headerSearch
if( ++bufferNumber < 30 ) {
Serial.print("@@>");
client.read(mp3buff, buffSize);
for( int i=0; i<buffSize; i++ ) Serial.write( mp3buff[i] );
Serial.println();
}
} // end of client.available test
} // end of loop