muhku / FreeStreamer

A low-memory footprint streaming audio player for iOS and OS X
http://muhku.github.io/FreeStreamer/
Other
2.11k stars 436 forks source link

Get station names from the stream #39

Closed skopanev closed 10 years ago

skopanev commented 10 years ago

Hi, many thanks for this great streamer!

My question is - how can I get the stations name from the stream? I noticed, that some playlists contains the station name (for example PLS from di.fm).

The first point - would be great to add some notification that you got station name. Second - some stations have no playlists with name inside, but iTunes show the name for them correctly. For example, http://stream21.group-network.net:9012

Thanks in advance,

muhku commented 10 years ago

Commit 98bb9eda304d235bc0874bd1353b091255a4fc8a gets the station name from http://stream21.group-network.net:9012 (the parameter seems to be called StreamUrl)

We currently have the audioStreamMetaDataAvailable notification, would that do? https://github.com/muhku/FreeStreamer/blob/master/FreeStreamerMobile/FSPlayerViewController.m#L93

skopanev commented 10 years ago

Thanks for answer.

When the stream back me URL - then I can try to get staion name - thats good - will looking to some solutions and back to you if find something great.

Second point that "audioStreamMetaDataAvailable" can not contain station name, but I think it would great feature to use only stream url to get station name. As I described in previous post - some stations provide their names in playlist. But which is right way to get station names?

May be add new method like "station name available" or add station name to "audioStreamMetaDataAvailable".

What do you think? Thanks,

Leandros commented 10 years ago

There is no right way to get a station name in the shoutcast protocol, it's old and rusty, but still the most used out there.

skopanev commented 10 years ago

Thanks Leandros!

I have a bit experimented and found that the my lovely freestreamer not parse "ICY 200 OK" fully. So, that I found in method "parseHttpHeadersIfNeeded" first header for shoutcast stations shows something like that: ICY 200 OK icy-notice1:
This stream requires Winamp
icy-notice2:SHOUTcast Distributed Network Audio Server/Linux v1.9.8

And then, the method locked by variable "m_httpHeadersParsed", but the headers give us needed info (for Tempomix radio): icy-name:TEMPOMIX RADIO icy-genre:Dance icy-url:http://www.tempomixradio.com content-type:audio/mpeg icy-pub:1 icy-metaint:32768 icy-br:128

So, it looks like really good to collect this info! I plan to experiment with other my stations, which are seems not ICY-cast. It will be really great if you can add this parsing to code.

Many thanks,

Leandros commented 10 years ago

Well, this is a bit complicated. ShoutCast is, as already said, old and rusty, and don't use HTTP headers. They just write those icy-xx: stuff into the data stream, you have to check for the ICY 200 OK, instead of HTTP 200 OK and then parse the data, or not if it's HTTP. It it's HTTP you got a IceCast (or something else, which complies to `HTTP).

PS: I hate the ShoutCast protocol so hard ...

skopanev commented 10 years ago

So, seems like it is busted! I've got station names for each my 6 station with a different format. The station name received on step, when freestreamer detect stream type and take metaint (it contains in header).

I want to prepare commit but need your confirm to do it and let's decide - will we add new notification for it? We can put into this notification: Genre, Station Name, Url and Content-type.

Thx,

Leandros commented 10 years ago

Great! Seems like your stations are complying to the protocol, however, you should add checks for the stations who aren't complying.

skopanev commented 10 years ago

So, can I add notification to detect station name? For sure, I will add it only for Icy-cast protocol, and then If I found station which not fit to it will investigate and find solution.

Leandros commented 10 years ago

It's @muhku who has to decide, what will be integrated into FreeStreamer. ;)

skopanev commented 10 years ago

Hola,

There are zip (http://cl.ly/3I1f2e1U3G1l) with freestreamer code (common and astreamer) folders which sending notification when found station name. May be we should add genre too.

I would like to see it in main code. Many thanks,

muhku commented 10 years ago

Thanks.

So basically what the patch adds is the parsing of the icy-name header from Shoutcast/Icecast streams? Did I get that right?

If that's so, I would simplify this by storing the parsed icy-name in an instance variable, say, m_icyName and pushing the value out in the existing audioStreamMetaDataAvailable map.

skopanev commented 10 years ago

Mukhu,

You are right, but I think that this info not correlate with metadata. For example one of my station (which I'm using to experiments) does not send me the metadata but has a name. And last one, this info sends only one time per connection that I would like you use different notification for that.

So, what do you think?

Thx,

muhku commented 10 years ago

We just need to make sure that the metadata map gets sent if it contains any data. That's possibly another modification.

I was thinking that at the player side, you check if the metadata contains the icy name, then you use that as a station name. So basically you need to go thru what you happen to have in the metadata map and decide based on that what to display to the user. It is not perfect but the world of audio streaming protocols is a bit broken from not having proper standards for everything.

skopanev commented 10 years ago

Do not understand you. What do you mean?

The station name contains in headers beside the meta-int and other tags.

muhku commented 10 years ago

The station name is now parsed and made available to the audio player in the metadata map, if available in the icy-name header. Commit 97fa42ccc4a7e8892f54af301c399330114c7e83

If the station doesn't give any other metadata, the station name is pushed out first. Commit 0821a85fbe612031caeb23260f24f27f98d8bf93

muhku commented 10 years ago

And now we use StreamUrl as a title, if no other title is available. Commit c3e24d98f8b5905de0f21aa8c2ce0a250397b1a3

muhku commented 10 years ago

The playlist name is also now utilized.

Let's close this issue and open a new one if there are still remaining cases that cannot be solved. A summary:

skopanev commented 10 years ago

Muhku,

For me the best way is to provide three variables: station name, playlist items array and stream URL. And developers will be decided what exactly they needed.

For example, if we have no name sometime better show nothing instead of playlist item or url.

Thanks,

skopanev commented 10 years ago

Muhku,

It would be great to add const strings for variables "IcecastStationName", "StreamTitle" and "StreamTitle". What do you think?

Thx,

muhku commented 10 years ago

@skopanev: What would be the benefit? The keys are not supposed to change.

skopanev commented 10 years ago

@muhku Ok. Thanks :+1:

skopanev commented 10 years ago

@muhku Sorry for bothering you but just found that not all stations has a names... You have added only half of station names detecting from my suggestion :( Could you do it to please! There is link to my old zip file (http://cl.ly/3I1f2e1U3G1l) Please take a look at it: http://cl.ly/image/0E1n1c0h3L2E this is from repo code, and this http://cl.ly/image/3R161O100Q1I from my zip files.

I will be really happy if you would add it to the repo! Many thanks.

muhku commented 10 years ago

@skopanev: Could you please add a pull request and add what is missing on the top of the current codebase? I have no time to start comparing the codebase with your changes from the zip.

skopanev commented 10 years ago

@muhku Thanks for answer! I'm not a guru in this. Please take a look at this file - I hope it is exactly what you looking for: http://f.cl.ly/items/1G1c0V3F3j3x381Q2P1t/http_stream.cpp.txt

Many thanks,

muhku commented 10 years ago

@skopanev: Pushed. The code is not bullet-proof. It can break because of the hard-coded character encoding but better than nothing.

skopanev commented 10 years ago

Thanks! May be add to some todo lists add encodings.