Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Version: 0.1.2
- Author: Milen Ivanov / criobot<at>gmail<dot>com
- CHANGES:
- v.0.1.2
- - Updated subtitles support (vbox7 added url encoding to the json subs /how lame/).
- v.0.1.1
- - Updated subtitles support (SUB newline fix, also etc-link update).
- v.0.1
- - Init;
- */
- class vbox7{
- public $url = null;
- public $code = null;
- public $title = null;
- public $thumbnail = null;
- public $flvUrl = null;
- public $subtitles = null;
- public $subtitlesExtension = 'srt';
- public function __construct($url, $subs = 'srt'){
- if(preg_match("/.*play:([a-fA-F0-9]{8})/",$url, $match)){
- $this->url = $match[0];
- $this->code = $match[1];
- $src = file_get_contents($this->url);
- if(preg_match("/<title>(.*) \/ VBOX7<\/title>/", $src, $found)){
- $this->title = $found[1];
- }
- $src = file_get_contents("http://www.vbox7.com/etc/ext.do?key=".$this->code."&antiCacheStamp=1234");
- if(preg_match("/&flv_addr=(.*?)&jpg_addr=(.*?)&subsEnabled=(?:true&subsData=)?(.*?)&related=[0-1]$/", $src, $parts)){
- $this->flvUrl = "http://".$parts[1];
- $this->thumbnail = "http://".$parts[2];
- if($parts[3]){
- if($subs == 'sub'){
- $subs = new SUBFile(json_decode(urldecode($parts[3])));
- $this->subtitlesExtension = 'sub';
- }else{
- $subs = new SRTFile(json_decode(urldecode($parts[3])));
- }
- $this->subtitles = $subs->parse();
- }
- }
- }else{
- throw new Exception("Невалиден линк");
- }
- }
- }
- /**
- * SRT File Class
- * 1\r\n
- * 00:00:04,680 --> 00:00:08,500\r\n
- * Кой даде идеята?\r\n
- * - Ти.\r\n
- * \r\n
- *
- */
- class SRTFile{
- private $source = null;
- public function __construct($src){
- if($src)
- $this->source = $src;
- }
- public function parse(){
- $number = 1;
- $return = "";
- for($i=0; $i<sizeof($this->source);$i++){
- $return .= ($i+1) . "\r\n";
- $return .= $this->formatTime($this->source[$i]->f) . " --> " . $this->formatTime($this->source[$i]->t) . "\r\n";
- $return .= str_replace("<br>", "\r\n", $this->source[$i]->s . "\r\n");
- $return .= "\r\n";
- }
- return $return;
- }
- private function leadingNull($number){
- if($number < 10) return "0".$number;
- return $number;
- }
- private function formatTime($seconds){
- $hours = $this->leadingNull((int)($seconds/360));
- $minutes =$this->leadingNull((int)($seconds/60));
- $seconds = $this->leadingNull($seconds - (((int)($seconds/360))*360 + ((int)($seconds/60))*60));
- return $hours.":".$minutes.":".$seconds.",000";
- }
- }
- /**
- * SUB File Class
- * {from*fps}{to*fps}Content(nl as |)\r\n
- *
- */
- class SUBFile{
- private $source = NULL;
- public function __construct($src){
- if($src)
- $this->source = $src;
- }
- public function parse($fps = 30){
- //Свалих 2-3 клипа от vbox7 и всичките бяха с FPS 30.0 така, че го оставям така по подразбиране.
- $return = "";
- for($i=0; $i<sizeof($this->source);$i++){
- $return .= "{". $fps * $this->source[$i]->f ."}{" . $fps * $this->source[$i]->t . "}" . $this->newLineFix($this->source[$i]->s) . "\r\n";
- }
- return $return;
- }
- public function newLineFix($string){
- $nl = array("\r\n", "\r", "\n", "<br>");
- return str_replace($nl, "|", $string);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment