2012-09-24 3 views
0

나는 youku에서 직접 파일 다운로드 링크를 얻으려고합니다.youku와 (과) 직접 동영상 다운로드 링크를받는 방법

URL의 예 : http://v.youku.com/v_show/id_XNDU0MTgxNzI0.html

나는 다운로드 경로를 모방려는 비디오 다운로드 웹 사이트를 사용했다. 나는 hxxp : // flvcd를 사용했다. co.kr에서 링크를 구문 분석하십시오. (검색 필드에 예제 URL을 붙여 넣으면 결과가 표시되며 4 개의 링크가 있어야합니다.)

일단 4 개의 직접 링크가 있으면 HTTP 출력을 캡처하는 데 fiddler2를 사용했습니다. 비디오의 첫 번째 부분을 찾을 수있었습니다 (flvcd 웹 사이트에 따라 4가되어야 함)

페이지 소스에서 직접 다운로드 링크 문자열을 검색해 보았지만 일치하는 항목을 찾을 수 없었습니다. 실제 직접 링크가 사이트 javascript를 사용하여 가져온다고 가정합니다.

아무에게도이 문제에 대한 의견을 개진 할 수 있습니까?

답변

0

이것은 내가 사용하고있는 코드입니다. 나는 여기에 다른 대답에서 그것을 smurfed,하지만 지금은 찾을 수 없습니다.

<?php 

class VideoUrlParser{ 
    private $video_code; 
    private $video_type; 
    private $success; 

    public function __construct($url = null, $type = null) { 
     $this->success = false; 

     if(!empty($url) && !empty($type)) { 
      $this->video_code = trim($url); 
      $this->video_type = trim($type); 
      $this->success = true; 
      return; 
     } 

     if(!empty($url)) { 
      $urls = parse_url(trim($url)); 

      //url is http://youtu.be/xxxx 
      if($urls['host'] == 'youtu.be'){ 
       $this->video_code = ltrim($urls['path'],'/'); 
       $this->video_type = "youtube"; 
       $this->success = true; 
      } 
      else if($urls['host'] == 'youtube.com' || $urls['host'] == 'www.youtube.com'){ 
       $this->video_type = "youtube"; 

       //url is http://www.youtube.com/embed/xxxx 
       if(strpos($urls['path'],'embed') == 1){ 
        $this->video_code = end(explode('/',$urls['path'])); 
        $this->success = true; 
       } 
       //http://www.youtube.com/watch?feature=player_embedded&v=m-t4pcO99gI 
       //url is http://www.youtube.com/watch?v=xxxx 
       else{ 
        parse_str($urls['query'],$parts); 
        $this->video_code = $parts['v']; 
        $this->success = true; 
       } 
      } 
      else if(strpos($urls['host'],'youku.com') > 0){ 
       $this->video_type = "youku"; 
       $regExp = "#/(?:player.php/sid/|v_show/id_)([a-zA-Z0-9]+)(?:/|\\.)#"; 

        if(preg_match($regExp, $urls['path'], $url_parts)){ 
         $this->video_code = $url_parts[1]; 
         $this->success = true; 
        } 
       } 
      //url is xxxx only 
      else if(strpos($url,'/')===false){ 
       $this->video_code = $url; 
       $this->video_type = "unknown"; 
      } 
      return; 
     } 
    } 

    public function success() { 
     return $this->success; 
    } 
    public function getVideoType() { 
     return $this->video_type; 
    } 
    public function getVideoCode() { 
     return $this->video_code; 
    } 
    public function getVideoURL() { 
     if($this->video_type == "youtube") { 
      return 'http://www.youtube.com/?v=' . $this->video_code; 
     } elseif($this->video_type == "youku") { 
      return "http://v.youku.com/v_show/id_" . $this->video_code . ".html"; 
     } 
    } 
    public function getEmbedCode($rel, $width, $height) { 
     if($this->video_type == "youtube") { 
      return '<iframe src="http://www.youtube.com/embed/'.$this->video_code.'?rel='.$rel.'" frameborder="0" width="'.($width?$width:560).'" height="'.($height?$height:349).'"></iframe>'; 
     } else if($this->video_type == "youku") { 
      return '<iframe width="'.($width?$width:560).'" height="'.($height?$height:349).'" src="http://player.youku.com/player.php/sid/'.$this->video_code.'/v.swf"></iframe>'; 
     } else { 
      return "unknown video type in class.video_url_parser"; 
     } 

    } 
} 
관련 문제