r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!REBOL3-OLD1]

shadwolf
2-Dec-2009
[19978x2]
in php they do it like that 

	function getHTML($page=False)
	{
		if (!$page)
			$page = $this->path;
		$contents = "";

  $domain = (substr($this->domain, 0, 7) == "http://") ? substr($this->domain, 
  7) : $this->domain;



  if (@$fp = fsockopen($domain, $this->port, $this->errno, $this->errstr, 
  2))
		{
			fputs($fp, "GET ".$page." HTTP/1.1\r\n".

    "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\r\n".
				"Accept: */*\r\n".
				"Host: ".$domain."\r\n\r\n");

			$c = 0;
			while (!feof($fp) && $c <= 20)
			{
				$contents .= fgets($fp, 4096);
				$c++;
			}

			fclose ($fp);

			$this->encodeContent($contents);

			preg_match("/(Content-Type:)(.*)/i", $contents, $matches);
			if (count($matches) > 0)
			{
				$contentType = trim($matches[2]);


    preg_match("/(meta http-equiv=\"Content-Type\" content=\"(.*); charset=(.*)\")/iU", 
    $contents, $matches);
				if (isset($matches[3]))
				{
					$this->setStreamEncoding($matches[3]);
				}
				if ($contentType == "text/html")
				{
					$this->isShoutcast = True;
					return $contents;
				}
				else
				{
					$this->isShoutcast = False;


     $htmlContent = substr($contents, 0, strpos($contents, "\r\n\r\n"));


     $dataStr = str_replace("\r", "\n", str_replace("\r\n", "\n", $contents));
					$lines = explode("\n", $dataStr);
					foreach ($lines AS $line)
					{
						if ($dp = strpos($line, ":"))
						{
							$key = substr($line, 0, $dp);
							$value = trim(substr($line, ($dp+1)));
							if (preg_match("/genre/i", $key))
								$this->nonShoutcastData['Stream Genre'] = $value;
							if (preg_match("/name/i", $key))
								$this->nonShoutcastData['Stream Title'] = $value;
							if (preg_match("/url/i", $key))
								$this->nonShoutcastData['Stream URL'] = $value;
							if (preg_match("/content-type/i", $key))
								$this->nonShoutcastData['Content Type'] = $value;
							if (preg_match("/icy-br/i", $key))

        $this->nonShoutcastData['Stream Status'] = "Stream is up at ".$value."kbps";
							if (preg_match("/icy-notice2/i", $key))
							{

        $this->nonShoutcastData['Server Status'] = "This is <span style=\"color: 
        red;\">not</span> a Shoutcast server!";
								if (preg_match("/ultravox/i", $value))

         $this->nonShoutcastData['Server Status'] .= " But an <a href=\"http://ultravox.aol.com/\" 
         target=\"_blank\">Ultravox</a> Server";
								$this->altServer = $value;
							}
						}
					}
					return nl2br($htmlContent);
				}
			}
			else
				return $contents;
		}
		else
		{
			return False;
		}
	}
but as they you the Mozilla thing i think they are working on the 
HTML version and not the meta tag
Oldes
2-Dec-2009
[19980]
p: open/direct/no-wait/binary http://ifb.impek.com:8000/
buf: copy/part p 2048
probe as-string copy/part  buf find buf "^M^/^M^/"
close p
shadwolf
2-Dec-2009
[19981]
** Script Error: copy expected range argument of type: number series 
port pair
** Where: getHTML
** Near: probe as-string copy/part buf find
Oldes
2-Dec-2009
[19982x7]
after the ICY info there is MP3 stream which can contain ID3 tags
you can get the stream using something like:
while [not none? buf: copy/part p 2048][probe buf]
that means that there was not found the "^M^/^M^/"
so you want the HTML?
for MP3 use:
system/schemes/http/user-agent: "Winamp"
and use trace/net on to see what's going on
also.. I see... I'm using R2, not R3
shadwolf
2-Dec-2009
[19989x2]
i got that {icy-notice1:<BR>This stream requires <a href="http://www.winamp.com/">Winamp</a><BR>^M

icy-notice2:SHOUTcast Distributed Network Audio Server/Linux v1.9.8<BR>^M
icy-name:OUIFM^M
icy-genre:Rock^M
icy-url:http://www.ouifm.fr^M
content-type:audio/mpeg^M
icy-pub:1^M
icy-br:128}
>>
ok in my opinion the metatag data stack retreived from the MP3 is 
 faster and more beautyfull way than parsing HTML data
Oldes
2-Dec-2009
[19991]
to get the HTML, just use:

system/schemes/http/user-agent: "Mozilla/4.0 (compatible; MSIE 6.0; 
Windows NT 5.0)"
buf: read http://ifb.impek.com:8000/
print buf
shadwolf
2-Dec-2009
[19992]
same i'm using R2 ... i don't code with R3 ... and yeah taht the 
R3  group .. shame on me ... I won't get a gift for Xmas...
Oldes
2-Dec-2009
[19993]
but we are in Rebol3 group!
shadwolf
2-Dec-2009
[19994x8]
why in  the php version they use this size ?
while (!feof($fp) && $c <= 20)
			{
				$contents .= fgets($fp, 4096);
				$c++;
			}
and you 2048 ?
in that  stack i'm supposed to get  mp3 >metatag>mp3
that's supposed to be the structure
i don't understand  in teh reply it's supposed to have the title 
of the song and the artist information ...
can this help you oldes ? http://www.smackfu.com/stuff/programming/shoutcast.html
can i do this oldes ? p: open/direct/no-wait/binary http://ifb.impek.com:8000/
insert p "GET path HTTP/1.0 ^/ Icy-MetaData:1 ^/^/"
user-agent winamp doesn't work in fact the reply we have is like 
an HTTP document not found ...
Oldes
2-Dec-2009
[20002]
opening http scheme is doing the GET for you, so no, you can't do 
that.
shadwolf
2-Dec-2009
[20003x2]
cause you use the http:// scheme no ?
in your url ?  using the tcp:// would it be possible ?
Oldes
2-Dec-2009
[20005]
yes
shadwolf
2-Dec-2009
[20006x5]
: open/direct/no-wait/binary tcp://ifb.impek.com:8000/
insert p "GET path HTTP/1.0 ^/ Icy-MetaData:1 ^/^/"
like that ?
how can i inject request to the socket ?
to do what is explained here http://www.smackfu.com/stuff/programming/shoutcast.html
oldes ?
Oldes
2-Dec-2009
[20011x5]
you can use something like:

 maxlen: 20 * 4096
 p: open/no-wait/direct tcp://ifb.impek.com:8000
 insert p "GET / HTTP/1.0 ^/Icy-MetaData:1 ^/^/"
 data: copy #{}
 while [not none? buf: copy/part p 2048][
 	append data buf
 	if maxlen <= length? data [break]
 ]
;do something with data 
 close p
but why? You get the ICY using the method above as well. And if yu 
need song data, these will be in ID3 tags.
and the ID3 will be on the song start so this would require to listen 
the stream for some time and parse it
also instead of:
 while [not none? buf: copy/part p 2048][
using:
while [buf: copy/part p 2048][
which is more ROBOLious :)
I just don't get why REBOL is changing the LF to CRLF, but I was 
not doing network coding for a very long time.
shadwolf
2-Dec-2009
[20016x5]
in fact the ICY we get with your method is a warning notice inviting 
you to use winamp and not the ICY with the song title and artist 
name wich are the information i want ...
anyway i can work with the HTML version ...
oldes have you read the  site i gave earlier ?
oh osrry i didn't read the whole replies ...
ok thank you very much i will try that
Oldes
2-Dec-2009
[20021]
no.. I don't have much time now.. I don't think it's warning. I can 
try to sniff real winamp communitacion later. Also we are really 
off topic here
shadwolf
2-Dec-2009
[20022x2]
but with the request injection the reply is the data ....
rhat's what the PHP script does it  get the raw data tehn locate 
the metatag part and extract the needed data
Oldes
2-Dec-2009
[20024]
check this:
 maxlen: 20 * 4096
 p: open/direct/binary tcp://ifb.impek.com:8000
 insert p "GET / HTTP/1.0 ^/Icy-MetaData:1 ^/^/"
 data: copy #{}
 while [buf: copy/part p 20048][
 	append data buf
 	probe length? buf
 	if f: find buf "StreamTitle" [
 		probe as-string copy/part f find f ";"
 		break
 	]
 	if maxlen <= length? data [break]
 ]
 probe length? data
 close p
shadwolf
2-Dec-2009
[20025]
oldes with you last methode we get the information i want 
oldes with you last methode we get the information i want 

StreamTitle='RACHID TAHA     BONJOUR';StreamUrl='';            vMQ(@K 
                 @  abm@]kaz 
Oldes
2-Dec-2009
[20026]
I know:) but you should parse it using some better way, if you want 
to also store the MP3
shadwolf
2-Dec-2009
[20027]
so i do a find "StreamTitle=" or a parse data [ some [ "StreamTile=" 
 copy artistsong thru ";StreamUrl="]