Created
November 30, 2011 16:43
Revisions
-
feuvan revised this gist
Nov 30, 2011 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ if ($num == 0) $num =1; $response = file_get_contents("http://v.iask.com/v_play.php?vid=". $vid); if ($response === FALSE) { print "failed to read upstream json"; exit; } @@ -26,7 +26,7 @@ $info = simplexml_load_string($response); if ($info === NULL) { print "can't decode upstream data"; exit; } -
feuvan created this gist
Nov 30, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ <?php define('FFMPEG', '/usr/bin/ffmpeg'); define('WGET', '/usr/bin/wget'); set_time_limit(3600); /* we are working with small chunks of files */ ignore_user_abort(true); /* do not terminate script execution if disconnect */ @ini_set("output_buffering", 0); @ini_set('implicit_flush', 1); header("Connection: close"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); $vid = (int)$_GET['vid']; $num = (int)$_GET['num']; if ($num == 0) $num =1; $response = file_get_contents("http://v.iask.com/v_play.php?vid=". $vid); if ($response === FALSE) { print "failed to read upsteam json"; exit; } /* http://code.google.com/p/cnvideoapi/source/browse/trunk/VideoApi/Adapter/Sina.php?r=trunk */ /* to make simplexml happy */ $response = preg_replace("/\<\!\[CDATA\[(.*?)\]\]\>/ies", "base64_encode('$1')", $response); $info = simplexml_load_string($response); if ($info === NULL) { print "can't decode upsteam data"; exit; } $count = count($info->durl); if ($num > $count) { print "incorrect num ($num), exceeds video segment count ($count)"; exit; } $url = urldecode(urlencode(base64_decode($info->durl[$num-1]->url))); $dest = "vid".$vid."_".$num.".mp4"; if (file_exists($dest)) { print $dest; } else { // for sina iask, we just copy streams // $cmd = WGET ." \"". $url ."\" -O - |".FFMPEG ." -i - -vcodec copy -acodec copy ". $dest . " 2>&1"; print ("going to execute ".$cmd); passthru($cmd); } ?>