2014-11-05 74 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

哦,太好了!是的,它的尺寸正常。讓我試用它的可恢復選項的PHP。 – Jaki 2014-11-05 09:54:04

+0

你好makhov!是否有可能通過PHP使用curl進行可恢復的下載? – Jaki 2014-11-05 10:50:57

+0

@Jaki,[this](http://www.ankur.com/blog/106/php/resume-http-downloads-php-curl-fsockopen/)可以幫助。 – makhov 2014-11-05 11:36:33

相關問題