diff --git a/_function.php b/_function.php new file mode 100644 index 0000000..6bac0b1 --- /dev/null +++ b/_function.php @@ -0,0 +1,165 @@ + true, + CURLOPT_URL => $url, + CURLOPT_TIMEOUT => 10, + CURLOPT_CONNECTTIMEOUT => 5, + CURLOPT_USERAGENT => $this->httph, + CURLOPT_COOKIE => $cookie, + CURLOPT_HEADER => 0 + ); + + if ($paramType == 'POST') + { + $opts[CURLOPT_POST] = true; + $opts[CURLOPT_POSTFIELDS] = $param; + } + + if($bodychk === true) + { + $opts[CURLOPT_HEADER] = 1; + $opts[CURLOPT_NOBODY] = $bodychk; + } + curl_setopt_array($ch, $opts); + $data = curl_exec($ch); + curl_close($ch); + return ($data) ? $data : false; + } + private function Download($url,$range=0) + { + $uri = parse_url($url); + $paramType = strtoupper($paramType); + if (!$uri['port']) $uri['port'] = 80; + if (!$uri['path']) $uri['path'] = "/"; + $ch = curl_init(); + $opts = array(CURLOPT_RETURNTRANSFER => true, + CURLOPT_URL => $url, + CURLOPT_TIMEOUT => 60, + CURLOPT_CONNECTTIMEOUT => 30, + CURLOPT_USERAGENT => $this->httph, + CURLOPT_COOKIE => $cookie, + CURLOPT_NOPROGRESS => false, + CURLOPT_WRITEFUNCTION => array($this, 'webecho'), + CURLOPT_HEADER => 0 + ); + if ($range) $opts[CURLOPT_RANGE]=$range; + curl_setopt_array($ch, $opts); + $data = curl_exec($ch); + curl_close($ch); + return ($data) ? $data : false; + } + public function Streaming($link, $streaming=false) + { + $link = abs(intval($link)); + if(!is_numeric($link)) exit; + $data = $this->WEBParsing('http://tvple.com/'.$link); + $name = htmlspecialchars_decode($this->splits($data, '"og:title" content="','"')); + + $api = $this->splits($data,'data-meta="','"'); + $data = $this->WEBParsing($api); + $url = $this->splits($data,'"mp4_avc": "','"'); + + if(!$url) return false; + $data = $this->WEBParsing($url,true); + // 2016-02-28 수정 + // FULL URL + while(strpos($data, 'HTTP/1.1 200 OK') === false) + { + $url = $this->splits($data,'Location: ',PHP_EOL); + $data = $this->WEBParsing($url,true); + } + $data = $this->WEBParsing($url,true); + + $size = $length = $this->splits($data, 'Content-Length: ', PHP_EOL); + + $start = 0; // Start byte + $end = $size - 1; // End byte + + if (isset($_SERVER['HTTP_RANGE'])) { + $rangeok=true; + $c_start = $start; + $c_end = $end; + list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2); + if (strpos($range, ',') !== false) { + header($_SERVER['SERVER_PROTOCOL'].' 416 Requested Range Not Satisfiable'); + header('Content-Range: bytes '.$start.'-'.$end.'/'.$size); + exit; + } + if ($range == '-') { + $c_start = $size - substr($range, 1); + }else{ + $range = explode('-', $range); + $c_start = $range[0]; + $c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size; + } + $c_end = ($c_end > $end) ? $end : $c_end; + if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) { + header($_SERVER['SERVER_PROTOCOL'].' 416 Requested Range Not Satisfiable'); + header('Content-Range: bytes '.$start.'-'.$end.'/'.$size); + exit; + } + $start = $c_start; + $end = $c_end; + $length = $end - $start + 1; + header($_SERVER['SERVER_PROTOCOL'].' 206 Partial Content'); + } + header('Accept-Ranges: 0-'.$length); + header('Content-Range: bytes '.$start.'-'.$end.'/'.$size); + header('Content-Length: '.$length); + + if ($streaming) header('Content-Type: video/mp4'); else header('Content-Type: video/MP2T'); + header('Accept-Ranges: bytes'); + header('Cache-Control: no-cache'); + $filename = $name.'.mp4'; + header('Content-Disposition: filename="'.$filename.'"'); + + set_time_limit(0); + ob_flush(); + flush(); + if ($rangeok) + $this->Download($url,$start.'-'.$end); + else + $this->Download($url); + ob_end_flush(); + } + } \ No newline at end of file diff --git a/help.php b/help.php new file mode 100644 index 0000000..0128d57 --- /dev/null +++ b/help.php @@ -0,0 +1,11 @@ += 1) ? true : false; + if($url) { + $tvpleurl = 'http://tvple.com/'; + if(substr($url,0,strlen($tvpleurl)) == $tvpleurl) $url = substr($url, strpos($url, $tvpleurl) + strlen($tvpleurl)); + if(!is_numeric($url)) echo 'Error... (URL Error)'; + else + { + $a = $aa->Streaming($url, $stream); + if(!$a) + echo 'Error...'; + else exit; + } + } +?> +
+ 티비플 주소 입력 :
+ --주소 형식--
+ ex1) http://tvple.com/1234
+ ex2) 1234
+
+ 티비플 접속해서 주소 가져오기
+

+ 동작 원리
+ Open Source! (PHP + php_curl) --- 소스 더러움. +
\ No newline at end of file