Guest User

Crio

a guest
Dec 22nd, 2009
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.79 KB | None | 0 0
  1. /*
  2.     Version: 0.1.2
  3.     Author: Milen Ivanov / criobot<at>gmail<dot>com
  4.    
  5.     CHANGES:
  6.     v.0.1.2
  7.     - Updated subtitles support (vbox7 added url encoding to the json subs /how lame/).
  8.    
  9.     v.0.1.1
  10.     - Updated subtitles support (SUB newline fix, also etc-link update).
  11.    
  12.     v.0.1
  13.     - Init;
  14.     */
  15.  
  16.     class vbox7{
  17.         public $url = null;
  18.         public $code = null;
  19.         public  $title = null;
  20.         public  $thumbnail = null;
  21.         public  $flvUrl = null;
  22.         public  $subtitles = null;
  23.         public  $subtitlesExtension = 'srt';
  24.         public function __construct($url, $subs = 'srt'){
  25.             if(preg_match("/.*play:([a-fA-F0-9]{8})/",$url, $match)){
  26.                 $this->url = $match[0];
  27.                 $this->code = $match[1];
  28.            
  29.                 $src = file_get_contents($this->url);
  30.                
  31.                 if(preg_match("/<title>(.*) \/ VBOX7<\/title>/", $src, $found)){
  32.                     $this->title = $found[1];
  33.                 }
  34.            
  35.                 $src = file_get_contents("http://www.vbox7.com/etc/ext.do?key=".$this->code."&antiCacheStamp=1234");
  36.                
  37.                 if(preg_match("/&flv_addr=(.*?)&jpg_addr=(.*?)&subsEnabled=(?:true&subsData=)?(.*?)&related=[0-1]$/", $src, $parts)){
  38.                     $this->flvUrl = "http://".$parts[1];
  39.                     $this->thumbnail = "http://".$parts[2];
  40.                     if($parts[3]){
  41.                         if($subs == 'sub'){
  42.                             $subs = new SUBFile(json_decode(urldecode($parts[3])));
  43.                             $this->subtitlesExtension = 'sub';
  44.                         }else{
  45.                             $subs = new SRTFile(json_decode(urldecode($parts[3])));
  46.                         }
  47.                         $this->subtitles = $subs->parse();
  48.                     }
  49.                 }
  50.             }else{
  51.                 throw new Exception("&#1053;&#1077;&#1074;&#1072;&#1083;&#1080;&#1076;&#1077;&#1085; &#1083;&#1080;&#1085;&#1082;");
  52.             }
  53.         }
  54.     }
  55.     /**
  56.      * SRT File Class
  57.      *  1\r\n
  58.      *  00:00:04,680 --> 00:00:08,500\r\n
  59.      *  &#1050;&#1086;&#1081; &#1076;&#1072;&#1076;&#1077; &#1080;&#1076;&#1077;&#1103;&#1090;&#1072;?\r\n
  60.      *  - &#1058;&#1080;.\r\n
  61.      *  \r\n
  62.      *
  63.      */
  64.     class SRTFile{
  65.         private $source = null;
  66.         public function __construct($src){
  67.             if($src)
  68.                 $this->source = $src;
  69.         }
  70.        
  71.         public function parse(){
  72.             $number = 1;
  73.             $return = "";
  74.             for($i=0; $i<sizeof($this->source);$i++){
  75.                 $return .= ($i+1) . "\r\n";
  76.                 $return .= $this->formatTime($this->source[$i]->f) . " --> " . $this->formatTime($this->source[$i]->t) . "\r\n";
  77.                 $return .= str_replace("<br>", "\r\n", $this->source[$i]->s . "\r\n");
  78.                 $return .= "\r\n";
  79.             }
  80.             return $return;
  81.         }
  82.         private function leadingNull($number){
  83.             if($number < 10) return "0".$number;
  84.             return $number;
  85.         }
  86.        
  87.         private function formatTime($seconds){
  88.             $hours = $this->leadingNull((int)($seconds/360));
  89.             $minutes =$this->leadingNull((int)($seconds/60));
  90.             $seconds = $this->leadingNull($seconds - (((int)($seconds/360))*360 + ((int)($seconds/60))*60));
  91.             return $hours.":".$minutes.":".$seconds.",000";
  92.         }
  93.     }
  94.    
  95.     /**
  96.      * SUB File Class
  97.      * {from*fps}{to*fps}Content(nl as |)\r\n
  98.      *
  99.      */
  100.     class SUBFile{
  101.         private $source = NULL;
  102.         public function __construct($src){
  103.             if($src)
  104.                 $this->source = $src;
  105.         }
  106.        
  107.         public function parse($fps = 30){
  108.             //&#1057;&#1074;&#1072;&#1083;&#1080;&#1093; 2-3 &#1082;&#1083;&#1080;&#1087;&#1072; &#1086;&#1090; vbox7 &#1080; &#1074;&#1089;&#1080;&#1095;&#1082;&#1080;&#1090;&#1077; &#1073;&#1103;&#1093;&#1072; &#1089; FPS 30.0 &#1090;&#1072;&#1082;&#1072;, &#1095;&#1077; &#1075;&#1086; &#1086;&#1089;&#1090;&#1072;&#1074;&#1103;&#1084; &#1090;&#1072;&#1082;&#1072; &#1087;&#1086; &#1087;&#1086;&#1076;&#1088;&#1072;&#1079;&#1073;&#1080;&#1088;&#1072;&#1085;&#1077;.
  109.             $return = "";
  110.             for($i=0; $i<sizeof($this->source);$i++){
  111.                 $return .= "{". $fps * $this->source[$i]->f ."}{" . $fps * $this->source[$i]->t . "}" . $this->newLineFix($this->source[$i]->s) . "\r\n";
  112.             }
  113.             return $return;
  114.         }
  115.        
  116.         public function newLineFix($string){
  117.             $nl = array("\r\n", "\r", "\n", "<br>");
  118.             return str_replace($nl, "|", $string);
  119.         }
  120.     }
Advertisement
Add Comment
Please, Sign In to add comment