묻고답하기

<?



class winamp_cast_information {

          var $now_listen;
          var $max_listen_persons;
          var $cast_title;
          var $cast_song;
          var $cast_kbps;
          var $cast_peak;

          var $cast_a_l_time;
              var $cast_genre;
                  var $cast_url;
                  var $cast_aim;
                  # var $cast_irc;

#--------------------------------------------------------------
        # 단일서버 정보 얻어 오기 메소드
        function winamp_cast($cast_ip){
                  
                                  $listen = $this->winamp_shoutcast_listen($cast_ip);            

                  # 현재 청취자수 와 최대청취할수 있는 인원
                  $this->now_listen = $listen[0];
                  $this->max_listen_persons =  $listen[1];  
              
                  $cast_info = $this->winamp_shoutcast_info($cast_ip);

                  if($cast_info[title]){  $this->cast_title = $this->str_re("title",$cast_info[title]);   }
                  if($cast_info[song]){    $this->cast_song =  $this->str_re("song",$cast_info[song]); }

                  $this->cast_kbps =  $cast_info[kbps];
                  $this->cast_peak =  $cast_info[peak];

                  $this->cast_a_l_time =  $cast_info[a_l_time];
                                  $this->cast_genre = $cast_info[genre];
                                  $this->cast_url = $cast_info[url];
                                 $this->cast_aim = urldecode($cast_info[aim]);
                                  # $this->cast_irc = $cast_info[irc];


       }
#--------------------------------------------------------------    
      # 멀티방송 서버 정보 얻어 오기 메소드
      function winamp_cast_array_list($array_cast_ip_list){

                  for($i=0;$i < sizeof($array_cast_ip_list);$i++){  
                        
                                           $server_ip =  $array_cast_ip_list[$i];
                       $listen = $this->winamp_shoutcast_listen($server_ip);            

                       # 현재 청취자수 와 최대청취할수 있는 인원
                       $this->now_listen += $listen[0];
                       $this->max_listen_persons +=  $listen[1];  
              
                       $cast_info = $this->winamp_shoutcast_info($server_ip);

                       if($cast_info[title]){ $this->cast_title = $this->str_re("title",$cast_info[title]);}
                       if($cast_info[song]){ $this->cast_song = $this->str_re("song",$cast_info[song]);}
                          
                          $this->cast_kbps =  $cast_info[kbps];
                          $this->cast_peak +=  $cast_info[peak];

                          $this->cast_a_l_time =  $cast_info[a_l_time];
                          $this->cast_genre = $cast_info[genre];
                          $this->cast_url = $cast_info[url];
                          $this->cast_aim = $cast_info[aim];
                          #$this->cast_irc = $cast_info[irc];

                       }
          
       }
      
#--------------------------------------------------------------

     ### 방송정보를 알아내는 메소드 시작 - 방송제목(title), 현재곡(song) ###
     function winamp_shoutcast_info($server_ip){

                  $info = array();

                  $ip = $this->shoutcast_ip_filter($server_ip);

                  $address = $ip["address"];
                  $port = $ip["port"];

                  $data = $this->shoutcast_data_read($address,$port,"info","no");

                 #문단 1 시작
                 if(!$data){
                                          
                      $info[ok] = 0;

                 }else{

                      $info[ok] = 1;

                      $data = strip_tags ("$data");

                       if(eregi("(([1-9]){2,3}) kbps",$data,$arr)){ $info[kbps] =  $arr[1]; }
      
                      
                      # 최고 청취자수 얻기
                      $one = explode ("Listener Peak:", $data);
                      $two = explode ("Average Listen Time:",$one[1]);

                      $info["peak"] = $two[0];

                      $data = $two[1];

                     # --------------------
                    
                      # 방송정보(평춘청취시간,방송타이틀,방송장르,URL,AIM,IRC채널) 얻기
                      $val = array("a_l_time","title","genre","url","aim","irc");

                      $explode_word = array("Stream Title:","Stream Genre:","Stream URL:","Stream AIM:","Stream IRC:","Current Song:");

                     for($i=0;$i < 6;$i++){

                          $one = explode ($explode_word[$i], $data);

                          $info[$val[$i]] = $one[0];

                          $data = $one[1];

                      }
                   # --------------------
                    
                    # 현재곡명 얻기
                    $info["song"] = $data;


                 }

      # 결과 리턴
      return $info;

}  
### 방송정보를 알아내는 메소드 끝 - 방송제목(title), 현재곡(song) ###
#--------------------------------------------------------------
     # 청취자수 알아내는 메소드 시작
     function winamp_shoutcast_listen($server_ip){

          $listen = array();

          $ip = $this->shoutcast_ip_filter($server_ip);

          $address = $ip["address"];
          $port = $ip["port"];

           $data = $this->shoutcast_data_read($address,$port,"info","no");
          
                  if(!$data){

                       # 청취자수
               $listen[0] =  0;
                  
               # 최대 청취자수
               $listen[1] =  0;  
        
             }else{

               $data = strip_tags ("$data");

               if(eregi("with (([0-9]){1,}) of (([0-9]){1,}) listeners", $data,$arr)){
                  
                  # 청취자수
                  $listen[0] =  $arr[1];
                  
                  # 최대 청취자수
                  $listen[1] =  $arr[3];
                          
                  }  
  
         #문단 2 끝
         }

       # 결과 리턴
       return $listen;

   # 청취자수 알아내는 메소드 끝
   }
#--------------------------------------------------------------
     function str_re($what,$value){
      
         if($what == "title"){

            $end = str_replace("Content Type: audio/mpeg","", $value);
                                            


         }else if($what == "song"){

                     $end = str_replace("Written by Stephen 'Tag Loomis, Tom Pepper and Justin Frankel","", $value);

                                     $end = str_replace("Copyright Nullsoft Inc. 1998-2002","", $end);


                 }

    
       return $end;
    
}

#--------------------------------------------------------------
   #### 주소 필터
   function shoutcast_ip_filter($server_ip){


      $server_ip = str_replace("http://", "", $server_ip);
      $server_ip = str_replace("/", "", $server_ip);
  
      # 방송주소을 (:)으로 주소(ip)와 포트(port)로 나눈다
      $addre = explode(":","$server_ip");

      $ip = array();
  
      $ip["address"] = $addre[0];
      $ip["port"] = $addre[1];

      return $ip;

   }

#--------------------------------------------------------------
   function shoutcast_data_read($address,$port,$option,$pls_file_name){

         if($option == "info") {

                   $fp = fsockopen("$address", $port, $errno, $errstr);
                    
                                        if($fp){
                                        
                                                # 소켓을 이용해서 서버에 html 형태로 테이타를 보내라고 명령한다
                        fputs ($fp, "GET /index.html HTTP/1.0nUser-Agent: Mozilla/4.0nn");
                      
                                           # 소켓의 마지막(eof) 까지 데이타를 읽는다(1024바이트씩)
                       while(!feof($fp)){
                           $data .= fgets($fp,1024);
                                                }                                
                  
                                      # 소켓을 닫는다
                      fclose($fp);
                                  
                                   }else{

                                      return 0;
                                  
                                   }


                 }else if($option == "history") {

                
              $fp = fsockopen("$address","$port", $errno, $errstr);
              
                              # 문단1-1 시작
                   if($fp){
                   fputs ($fp, "GET /played.html HTTP/1.0nUser-Agent: Mozilla/4.0nn");

                   while(!feof($fp)){
                    $data .= fgets($fp,1024);
                    }                                
                    
                                        # 소켓을 닫는다
                    fclose($fp);
             }else{

                        return 0;
                
                         }
                
                }else if($option == "pls_file") {


                           $fp = fsockopen("$address","$port", $errno, $errstr);
                
                           if($fp){
                            
                      $out = "GET /${pls_file_name} HTTP/1.1rn";
                      $out .= "Host: $addressrn";
                      $out .= "Connection: Closernrn";

                      fputs($fp, $out);


                                   while(!feof($fp)){
                    $data .= fgets($fp,1024);
                    }                                
                    
                                        # 소켓을 닫는다
                    fclose($fp);

                }else{

                        return 0;
                
                           }

                
                }

    return $data;
  
   }

#--------------------------------------------------------------
########## 방송 히스토리 정보 얻어오기  메소드 시작
function winamp_shoutcast_history($server_ip){

     $ip = $this->shoutcast_ip_filter($server_ip);

     $address = $ip["address"];
     $port = $ip["port"];

     $data = $this->shoutcast_data_read($address,$port,"history","no");

     if(!$data){
                
                   echo "방송히스토리를 가져올수 없습니다";
                  
        
         }else{

            $data = strip_tags ("$data",'<td>');
          
                    $haha = explode ("<td>", $data);
          
              for($i=0;$i <= sizeof($haha);$i++){
                  
                                  #$haha 배열변수의 $i번째에 속한것이 시간이면  배열변수  $time에 넣는다
                              if(eregi("(([0-9]){2}):(([0-9]){2}):(([0-9]){2})", $haha[$i])){
                                         $time[] = strip_tags ($haha[$i]);
                                  }else{
                     $tmp[] = $haha[$i];
                                  }
              
                          }
                          
             for($i=0;$i <= sizeof($tmp)-1;$i++){
                      
                      # $tmp배열에 $i 번째에 속한 내용이 타이틀을 경우 배열변수 $history_title에 넣는다
                      if(!$this->history_title_ck($tmp[$i])){ $history_title[] = strip_tags ($tmp[$i]); }

                          }
                        
                                    


         }                
                        
           # 이차원 배열로 시간과 타이틀을 묶어버린다
           $history  = array("time" => $time, "title" => $history_title);  
                
           return $history;
          
  
        


}
########## 방송 히스토리 정보 얻어오기 메소드 끝


# 방송히스토리 타이틀인가 아닌가를 구분
function history_title_ck($title){


        if(eregi("HTTP/1.0 200 OK",$title) or eregi("Server Version",$title) or eregi("Played @",$title)
                or eregi("Song Title",$title) or eregi("Current Song",$title) or eregi("Written by Stephen 'Tag Loomis",$title)){ $v = 1; }else{ $v = 0; }

    

  
        return $v;

}

#----------------------------



function winamp_cast_inlive_type($address,$pls_file_name){

   $data = $this->shoutcast_data_read($address,80,"pls_file",$pls_file_name);
  
  $data_array = spliti( "file[0-9]{1,2}", $data);

  
for($i=0;$i <= sizeof($data_array);$i++){

if(eregi("http://(([a-zA-Z0-9]){1,}).(([a-zA-Z0-9]){1,}).(([a-zA-Z0-9]){1,}).(([a-zA-Z0-9]){1,}):(([0-9]){1,})", $data_array[$i],$aa)){

    if($tmp  != $data_array[$i]){ $ip[] = $aa[0]; }

    $tmp = $data_array[$i];

  }


}

  
if(sizeof($ip) > 1){
      
   $this->winamp_cast_array_list($ip);

}else{

   $this->winamp_cast($ip[0]);
    

}



}


function info_reset(){

        $this->now_listen = "";
        $this->max_listen_persons  = "";
        $this->cast_title  = "";
        $this->cast_song  = "";
        $this->cast_kbps  = "";
        $this->cast_peak  = "";
        $this->cast_a_l_time = "";
        $this->cast_genre = "";
        $this->cast_url = "";
        $this->cast_aim = "";
        $this->cast_irc = "";

}
#------------------------
}
?>
이게 php란의 소스에 올라와 이는 방송보기 소스 인데.

여기서

타이틀 방송제목 부분이죠..
$this->cast_genre = ""; 이 함수를..
방송중이 아닐때는 방송중이지 않습니다.로
방송중일때는 cast_genre 로 나타나게 하는방법이 있을거 같은데 무언지 모르겠습니다.

2틀을 찾아 해매다 못해... 질문을 던집니다...
조언 부탁 드려요.
글쓴이 제목 최종 글
XE 공지 글 쓰기,삭제 운영방식 변경 공지 [16] 2019.03.05 by 남기남
오지명 호스팅 받고있는데요.. [3] 2007.08.10
안정섭 게시판위치 조정 어떻게 하나요?  
동해랑 PHP 구문중.. 질문이 있습니다... [2] 2007.08.10
JS블루 웹마스터 과정 배울려고 하는데요.. 윈도우? 리눅스? 뭘 배울까요? ㅠㅠ 조언 좀 부탁드립니다.  
풯두 안녕하세요 부탁입니다 알려주세요 [1] 2007.08.10
Leaf 포토샵에서 이미지를 일정하게 자르는것좀 가르쳐주세요.. [1] 2007.08.10
허정필 [리눅스]디렉토리 이동이 않되네요 ㅠ_ㅠ 도와주세요 제발....  
자도르 유닉스 서버에서도 셋팅 가능해요? [2] 2007.08.10
최윤성 index.htm->main.php [5] 2007.08.10
patzzi 홈이 늦게 뜨는데요.. [1] 2007.08.10
케이이치 새창띄우기에서 자꾸 여백이 생겨요~ [2] 2007.08.10
고강용 홈페이지 제작 관련 ~~~급해서 부탁드립니다 [1] 2007.08.10
보드대박 여러분은 이럴때 어떤 보정을 해주시나요?  
호피 화면전체에 마우스를 따라 십자선이 움직이는 효과.  
kunbi 홈페이지로 넘어가는 소스~  
김종운 홈페이지 상단 공백? [3] 2007.08.10
김태형 echo문 안에서 php 함수를 불러 올수 없나요???? [4] 2007.08.10
박창준 브라우저의 폭을 알수 있는 방법이 궁금합니다. [1] 2007.08.10
이경륜 아이피 주소를 치면 연결이 되는데 도메인명으로 입력하면 연결이 안되요? [1] 2007.08.10
고송희 포토샵에서 먼가 만든후 저장해서 다시 열어보면.. 지져분..  
윤영하 PHP: 변수명에 다른 변수값이 들어갈때.. [1] 2007.08.10
BigStone 함수내에서 $HTTP_SESSION_VARS를 global 지정한 효과? [1] 2007.08.10
박근영 서브메뉴사라지지않게하려면? [1] 2007.08.10
(: 안호진 :) [방송정보 얻어오기에서] 타이틀 부분 관련  
한제훈 멀티 게시판을 만들고 싶은데요.. [2] 2007.08.10
이진희 노프레임 질문입니다.  
박희정 음악..`  
황석봉 include 에 대한 질문입니다..; [2] 2007.08.10
이용욱 저도 PHP include의 관련 질문 입니다.  
초보흐흑.. 첫화면에 바로 일기장게시판 연결.. [2] 2007.08.10