Help Grabbing Metadata

Discussion in 'PHP' started by Hecky, Jan 25, 2010.

  1. #1
    Hi,

    I've been trying to get a script to grab the information from a SHOUTcast server, and I'm having difficulty.

    Here's the information that I need to obtain :

    http://92.114.47.12:8000/7.html

    ( sample radio, may not be online always )

    and it just has a string of numbers that correspond to the different variables of the radio, eg listeners, bitrate, etc.

    I can't for the life of me seem to grab the page in my PHP, I've used a few different methods and it just wont work.

    Can anyone try and help me, it'd be really appreciated :)

    Thanks!
     
    Hecky, Jan 25, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Assuming you'd want to retrieve the data within the page's body e.g. "2,0,8,75,2,64,Sum 41 - Still Waiting".

    Then try this: (untested).

    <?php
    
    $shoutcast = file_get_contents("http://92.114.47.12:8000/7.html");
    
    preg_match("/<body.*>(.*)<\/body>/smU",$shoutcast, $match);
    
    echo $match[1];
    
    ?>
    PHP:
     
    danx10, Jan 25, 2010 IP
  3. Hecky

    Hecky Like a Dungeon Dragon!

    Messages:
    5,656
    Likes Received:
    284
    Best Answers:
    1
    Trophy Points:
    0
    #3
    danx10, thanks for your help.

    I've tried using file_get_contents with no success - the page just grinds away and produces no result (times out). Could it be the page blocking my attempt to view it?

    Thanks
     
    Hecky, Jan 25, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    Im not sure, to be honest im tired, so i may not be myself until tommorow when im wide awake - lol.

    But try this:

    <?php
    
    $curl = curl_init();  
    curl_setopt($curl, CURLOPT_URL, "http://92.114.47.12:8000/7.html");  
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);  
    curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2');  
    $shoutcast = curl_exec($curl);  
    
    
    preg_match("/<body.*>(.*)<\/body>/smU",$shoutcast, $match);
    
    echo $match[1];
    
    ?>
    PHP:
     
    danx10, Jan 25, 2010 IP
  5. Hecky

    Hecky Like a Dungeon Dragon!

    Messages:
    5,656
    Likes Received:
    284
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Ah, little update. It seems like it's working on other servers but not that one. That's just one I picked randomly, any idea why it might be rejecting these attempts to pull data from it?

    Thank-you so much by the way, you've helped tremdously :)
     
    Hecky, Jan 25, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    i just tried on my local file_get_contents() doesn't seem to work,

    It looks like your shoutcast server seems to give this reponse:

    ICY 404 Resource Not Found
    icy-notice1:<BR>SHOUTcast Distributed Network Audio Server/Linux v1.9.8<BR>
    icy-notice2:The resource requested was not found<BR>
    Code (markup):

    but my second method did (via curl).

    So i suggest you follow -> http://forums.digitalpoint.com/showpost.php?p=13453651&postcount=4 (if you haven't already).
     
    danx10, Jan 25, 2010 IP
  7. Hecky

    Hecky Like a Dungeon Dragon!

    Messages:
    5,656
    Likes Received:
    284
    Best Answers:
    1
    Trophy Points:
    0
    #7
    Hecky, Jan 25, 2010 IP
  8. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #8
    That url doesn't seem to load for me.

    The curl method works perfectly for me, so im unsure why it don't work for you, perhaps the shoutcast server has blocked your site from connecting/refering?.
     
    danx10, Jan 25, 2010 IP
  9. Hecky

    Hecky Like a Dungeon Dragon!

    Messages:
    5,656
    Likes Received:
    284
    Best Answers:
    1
    Trophy Points:
    0
    #9
    Hmm, still no success here.

    They shouldn't have blocked my server, I've never done anything like this before. If you have any ideas, that'd be great to hear.
     
    Hecky, Jan 27, 2010 IP