views:

254

answers:

3

I'm creating an application in Objective-C and I need to get the metadata from a SHOUTcast stream. I tried this:

NSURL *URL = [NSURL URLWithString:@"http://202.4.100.2:8000/"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
    [request addValue:@"1" forHTTPHeaderField:@"icy-metadata"];
    [request addValue:@"Winamp 5/3" forHTTPHeaderField:@"User-Agent"];
    [request addValue:@"audio/mpeg" forHTTPHeaderField:@"Content-Type"];
    [NSURLConnection connectionWithRequest:request delegate:self];

I would have to get the headers from this request in order to get the information, right? Unfortunately it keeps returning these headers:

Date = "17 Apr 2010 21:57:14 -0200";

"Max-Age" = 0;

What I'm doing wrong?

A: 

It seems that shoutcast does not follow HTTP exchange standards and its response headers and body are not separated by two newlines. NSURLConnection/NSURLResponse are unable to parse out the headers; however, connection:didReceiveResponse: is still fired, just with an empty NSURLResponse. This becomes clear if we take a look at data coming in connection:didReceiveData:. The first chunk received will contain metadata headers.

freeatnet
Thanks! I tried this and sometimes it returns the metadata, sometimes it doesn't. Is there another way to do that? I tried this:-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ NSString *metadata = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; NSRange range = [metadata rangeOfString:@"StreamTitle=" options:(NSCaseInsensitiveSearch | NSBackwardsSearch)]; if(range.length > 0){ NSLog(@"%@", metadata); } else { NSLog(@"%@ no range", metadata); }}
Fernando Valente
http://www.smackfu.com/stuff/programming/shoutcast.html — this might be helpful.
freeatnet
I tried this with no luck :(
Fernando Valente
A: 

Hi, Fernando, i trie to something like this, but i don't find a way to do, if you found something can you help me please, my email is [email protected]

Saulo
A: 

I found an answer to this question. Simply append a 7.html at the end of the URL and parse the file.

I.E. http://38.96.148.138:7534/7.html

Fernando Valente