indiephp Posted January 14, 2011 Share Posted January 14, 2011 Hi, php newbie here.. Can you explain how can i use this stuff in php? http://www.smackfu.com/stuff/programming/shoutcast.html I found a phyton script: http://jasonlebrun.info/2006/12/31/icy-metadata-shoutcast-song-titles/ and Java code (i guess): http://www.codeproject.com/KB/audio-video/SHOUTcastRipper.aspx But i didn't found any php solution for this problem anywhere Quote Link to comment https://forums.phpfreaks.com/topic/224420-retrieving-shoutcast-metadata/ Share on other sites More sharing options...
indiephp Posted January 14, 2011 Author Share Posted January 14, 2011 i found this code and it works.. <?php header("Content-type: audio/mpeg"); $fp = fsockopen("74.208.71.58", 8000, $errno, $errstr, 30); if ($fp == false) { echo "$errstr ($errno)"; } else { fputs($fp, "GET / HTTP/1.1\r\n"); fputs($fp, "User-Agnet: WinampMPEG/2.9\r\n"); fputs($fp, "Accept: */*\r\n"); fputs($fp, "Icy-MetaData:1\r\n"); fputs($fp, "Connection: Close\r\n\r\n"); while (!feof($fp)) { $buf = fread($fp, 1024 / 16); echo $buf; } fclose($fp); } ?> Result is very strange for me. But at the same time it contains data which i need. (red line) ICY 200 OK icy-notice1:<BR>This stream requires <a href="http://www.winamp.com/">Winamp</a><BR> icy-notice2:SHOUTcast Distributed Network Audio Server/win32 v1.9.5<BR> icy-name:Radio Dismuke - 1920s & 1930s Popular Music & Jazz icy-genre:Jazz Big Band Swing icy-url:http://RadioDismuke.com content-type:audio/mpeg icy-pub:1 icy-metaint:8192 icy-br:24 §ÿğN˜ZiÂïw¹Nÿ‚B§å3•õw é8?ŞAîÌøCòÿÿıSZ¿‡ØA©=íÒ÷ğl.5؃q¢ıW*•š¤Ìî±Î³Ó ï~ÌŽ%fßÚµİcOG-Š“Ϊ9§i—âF“ìŞëÇ”r¯ UÙéé¯oSD–ò:·½]¤mÿã0tÕIhQ=Æ®p”ª%[Z¡Y«ªQÔùÕ¼øŠ¦N×u£4¹}oóTŠ}fqWV¦¿„Ú\YmŠZ³ÛyŞëT’ÿã0tÑmoh ‹.n®£-‚Žm_ÿã0t×íIlQ<ÏÒMZÖ“¤3K•¿:ô¿|d'¾Íë8b_¾öªãZ×p‰µ’¢øg“«~íLu-çåúÊíJñ༌»pÓT×6Â$öªµÿã0tÖ…Ò¶h]ƒ|£F¶Que2Öè’½=fÈFZ?à¸WåßäžëÄqÿßÿÿÿœºÎ«4§ïß8èĞK¼í²ôØJLjìªÎ/r´Úü[À¥iÚ…[”` aÅòÖ>7K‡³ıݶ§İPã_U/eÇÕC•ÿã0tÙáknP=â€ÀÜ®Zf¤žËÍ®D#Å+匰‡õÅ…[Ä-?™á†9ç÷(ăϗRöÃE^®T´ïãÛ_e‘{XŒÇ¿M~–Èû¼Éÿã0t×Y^?NØùMúœQN¤ƒÎGÿÿÿù|ãWÍp¦>`Ïw’;İG‹ÀÇùŸS–Ú¢x¡İ¼ğÃÑ`Î-+)w‘†6m¬áXÈ©q/>uH˜Õ$ÿıÉŠhÜ´?áëÿã0tÕ-g\s8Ë6Y8„Ô*åêÒRxÿ×ÿÿÿø½ ¹=SyÓ7]žG•w‚‚®ñû{«yñcGÎ/YTå’Å¿}¶lŽ9ƒßxğÍƆoàĶ¯8Ú%-©¢0w}qF›Âêÿã0tÜm—lÿ™m FİA¸v'!ÿã0tÑYl =†ŠÿßÿÿÿœºÎ«4§ïß8èĞK¼í²ôØJLjìªÎ/r´Úü[À¥iÚ…[”`aÅòÖ>7K‡³ıݶ§İPã_U/eÇÕC•ÿã0tÙáknP= â€ÀÜ®@ò;Z¦ÿã0tÍí=n¡=+v…Ò¶h]ƒ|£F¶Que2Öè’ StreamTitle='Lawrence Gray - The Whole Darned Things For You'; ½=fÈFZ?à¸WåßäžëÄqÿßÿÿÿœºÎ«4§ïß8èĞK¼í²ôØJLjìªÎ/r´Úü[À¥iÚ…[”` aÅòÖ>7K‡³ıݶ§İPã_U/eÇÕC•ÿã0tÙáknP= â€ÀÜ® Actualy, the result is too long more than this. I think this is streaming audio data. Now, don't know how can i pick StreamTitle. I read again "Shoutcast Metadata Protocol document. He talks about metadata lenght. Step 3: Get the metadata This is the important part. Read the data stream as you normally would, keeping a byte count as you go. When the number of bytes equals the metadata interval, you will get a metadata block. The first part of the block is a length specifier, which is the next byte in the stream. This byte will equal the metadata length / 16. Multiply by 16 to get the actual metadata length. (Max byte size = 255 so metadata max length = 4080.) Now read that many bytes and you will have a string containing the metadata. Restart your byte count, and repeat. Success! Note that the metadata length is set to 0 most of the time, meaning there is no metadata. The metadata is normally sent at two particular places: immediately after connecting and when the song changes. It seems as if some servers aren't real diligent about the former, so it might take a while to get your first block. Also, be sure you don't count the bytes in the metadata length field or the metadata when you're figuring out whether you've hit the interval. Only the MP3 data counts. So you can't be lazy and just keep a total byte count and mod it. How to figure out? I am realy stuck. Quote Link to comment https://forums.phpfreaks.com/topic/224420-retrieving-shoutcast-metadata/#findComment-1159339 Share on other sites More sharing options...
indiephp Posted January 14, 2011 Author Share Posted January 14, 2011 I didnt paste all of the result because of special characters. Therefore i attach screenshot. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/224420-retrieving-shoutcast-metadata/#findComment-1159416 Share on other sites More sharing options...
QuickOldCar Posted January 14, 2011 Share Posted January 14, 2011 Ever try this? http://www.icecast.org/ Quote Link to comment https://forums.phpfreaks.com/topic/224420-retrieving-shoutcast-metadata/#findComment-1159439 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.