糖豆网解析源码

杂文糖豆网解析源码

糖豆网解析源码

  1. <?php   
  2.   
  3. echo json_encode(TangDou::parse1($url));  
  4.   
  5. class TangDou  
  6. {  
  7.     public static function parse1($url)  
  8.     {  
  9.         $content = self::curl($url);  
  10.         preg_match(“#poster:'(.*?)’#",$content,$images);  
  11.         preg_match(“#video:'(.*?)’#",$content,$urls);  
  12.         preg_match(“#class=\"title\">(.*?)</div>#",$content,$titles);  
  13.         $videoinfo['code’] = 200;  
  14.         $videoinfo['play’] = 'h5mp4’;  
  15.         $videoinfo['data’]['url’] = $urls[1];  
  16.         $videoinfo['data’]['title’] = $titles[1];  
  17.         $videoinfo['data’]['poster’] = $images[1];  
  18.         return $videoinfo;  
  19.     }  
  20.     public static function parse($url)  
  21.     {  
  22.         $content = self::curl($url);  
  23.         preg_match(“#vid\s*=\s*'(\d+)’#",$content,$_vid);  
  24.         preg_match(“#videourl\s*=\s*'(\w+)’#",$content,$vurl);  
  25.         $vid = $_vid[1];  
  26.         if(!emptyempty($vurl[1])){  
  27.             $hash = $vurl[1];  
  28.         }else{  
  29.             preg_match('#vid:\s*“(\w+)"#’,$content,$_vurl);  
  30.             if(!emptyempty($_vurl[1])){  
  31.                 $hash = $_vurl[1];  
  32.             }else{  
  33.                 preg_match('#id=“cc_([\w]{32})"#’,$content,$cc);  
  34.                 if (!emptyempty($cc[1])) {  
  35.                     $hash = $cc[1];  
  36.                 }  
  37.             }  
  38.         }  
  39.         return self::get_video_url($vid,$hash);  
  40.     }  
  41.     public static function get_video_url($vid,$hash)  
  42.     {  
  43.         $api = “http://share.tangdou.com/mp4.php?vid={$vid}&videourl={$hash}";  
  44.         $content = self::curl($api);  
  45.         preg_match('#src=\\\“(.*?)\\\"#’,$content,$vurl); 
  46.         $video['code’] = 200; 
  47.         $video[“data“][“url“] = $vurl[1]; 
  48.         $video[“play“] = “h5mp4“; 
  49.         return $video; 
  50.     } 
  51.     public static function curl($url) 
  52.     { 
  53.         $params[“ua“] = “Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36″;  
  54.         return GlobalBase::curl($url,$params);  
  55.     }  
  56. }  
  57.  ?>  

Posted by 柴郡猫