2014-11-05 3 views
0

다시 시작할 수있는 PHP를 통해 YouTube 비디오 링크를 다운로드 할 수 있습니까? youtube-dl을 통해 다운로드 링크를 쉽게 가져올 수 있습니다.재개 가능한 PHP를 통해 YouTube 비디오 링크를 다운로드 할 수 있습니까?

PHP를 다시 시작할 수있는 경우 비디오의 크기를 알아야합니다. 하지만 링크를 통해 크기를 가져올 수 없으므로 PHP를 통해 다시 시작할 수 있습니다.

하자 링크는 말 : [MP4]

https://r10---sn-hp576n7z.googlevideo.com/videoplayback?mt=1415174349&itag=22&fexp=915516%2C930666%2C932404%2C934601%2C947209%2C947215%2C948124%2C952302%2C952901%2C953912%2C957103%2C957201&key=yt5&upn=xe1em66NCSc&sparams=gcr%2Cid%2Cip%2Cipbits%2Citag%2Cmime%2Cmm%2Cms%2Cmv%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cexpire&ipbits=0&ratebypass=yes&gcr=us&mv=u&id=o-ANmao-OacohTVjp7yijSePI5a3vvlERcSs6uL3WLfOA7&ms=au&expire=1415196179&sver=3&ip=176.576.184.114&mime=video%2Fmp4&requiressl=yes&source=youtube&mm=31&signature=29046D03C1EC013A78BD20E4CDD362BBA62ADF4B.A0E2E8E104769DD664202597A91F0888F9E554B3 

답변

1

이 얻을 수있는 파일 크기를보십시오 :

<?php 
/** 
* Returns the size of a file without downloading it, or -1 if the file 
* size could not be determined. 
* 
* @param $url - The location of the remote file to download. Cannot 
* be null or empty. 
* 
* @return The size of the file referenced by $url, or -1 if the size 
* could not be determined. 
*/ 
function curl_get_file_size($url) { 
    // Assume failure. 
    $result = -1; 

    $curl = curl_init($url); 

    // Issue a HEAD request and follow any redirects. 
    curl_setopt($curl, CURLOPT_NOBODY, true); 
    curl_setopt($curl, CURLOPT_HEADER, true); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($curl, CURLOPT_USERAGENT, 'user_agent_string'); 

    $data = curl_exec($curl); 
    curl_close($curl); 

    if($data) { 
     $content_length = "unknown"; 
     $status = "unknown"; 

     if(preg_match("/^HTTP\/1\.[01] (\d\d\d)/", $data, $matches)) { 
      $status = (int)$matches[1]; 
     } 

     if(preg_match("/Content-Length: (\d+)/", $data, $matches)) { 
      $content_length = (int)$matches[1]; 
     } 

     // http://en.wikipedia.org/wiki/List_of_HTTP_status_codes 
     if($status == 200 || ($status > 300 && $status <= 308)) { 
      $result = $content_length; 
     } 
    } 

    return $result; 
} 

사용법 :

$file_size = curl_get_file_size($url); 
+0

OH 위대한! 그래, 크기와 잘 작동하고있어. 내가 재개 가능한 옵션에 대한 PHP와 함께 보자. – Jaki

+0

안녕하세요 makhov !! PHP를 통해 다운로드 할 수있는 다운로드에 컬을 사용할 수 있습니까? – Jaki

+0

@Jaki, [this] (http://www.ankur.com/blog/106/php/resume-http-downloads-php-curl-fsockopen/) 도움이 될 수 있습니다. – makhov