Changeset 26469


Ignore:
Timestamp:
Jan 6, 2014, 4:33:59 PM (10 years ago)
Author:
mistic100
Message:

update wat parser, compatible with dai.ly (dailymotion short url), use youtube-nocookie domain

Location:
extensions/gvideo
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/gvideo/include/functions.inc.php

    r20809 r26469  
    11<?php
    2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     2defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
    33
    44function parse_video_url($source_url, $safe_mode=false)
    55{
    6   $source_url = 'http://'.preg_replace('#^http(s?)://#', null, $source_url);
     6  $source_url = 'http://'.preg_replace('#^http(s?)://#', null, trim($source_url));
    77 
    88  $url = parse_url($source_url);
     
    3838      if (empty($video['video_id']))
    3939      {
     40        if ($url['host'][1] != 'be') return false;
    4041        $url['path'] = explode('/', $url['path']);
    4142        $video['video_id'] = $url['path'][1];
     
    122123    case 'dailymotion':
    123124    {
    124       $video['type'] = 'dailymotion';
    125      
    126125      $url['path'] = explode('/', $url['path']);
    127126      if ($url['path'][1] != 'video') return false;
    128127      $video['video_id'] = $url['path'][2];
     128    }
     129   
     130    case 'dai':  // dai.ly (short-url service)
     131    {
     132      $video['type'] = 'dailymotion';
     133     
     134      if (empty($video['video_id']))
     135      {
     136        if ($url['host'][1] != 'ly') return false;
     137        $video['video_id'] = ltrim($url['path'], '/');
     138      }
    129139     
    130140      $video['url'] = 'http://dailymotion.com/video/'.$video['video_id'];
    131       $video['title'] = $video['video_id'];
     141      $video['title'] = 'Dailymotion #'.$video['video_id'];
    132142     
    133143      if (!$safe_mode)
     
    157167    case 'wat':
    158168    {
    159       if (!$safe_mode) return false; // no safe_mode for wat.tv, must connect to get the video id
     169      if ($safe_mode) return false;
     170     
     171      $html = gvideo_download_remote_file($source_url, true);
     172
     173      if ($html===false || $html=='file_error') return false;
    160174     
    161175      $video['type'] = 'wat';
    162      
    163       $html = gvideo_download_remote_file($source_url, true);
    164      
    165       if ($html===false || $html=='file_error') return false;
    166      
    167       preg_match('#<meta property="og:video" content="http://www.wat.tv/swf2/([^"/>]+)" />#', $html, $matches);
     176      $video['url'] = $source_url;
     177     
     178      preg_match('#<meta name="twitter:player" content="https://www.wat.tv/embedframe/([^">]+)">#', $html, $matches);
    168179      if (empty($matches[1])) return false;
    169180      $video['video_id'] = $matches[1];
    170      
    171       $video['url'] = $source_url;
    172      
    173       preg_match('#<meta name="name" content="([^">]*)" />#', $html, $matches);
     181
     182      preg_match('#<meta property="og:title" content="([^">]*)">#', $html, $matches);
    174183      $video['title'] = $matches[1];
    175184     
    176       preg_match('#<p class="description"(?:[^>]*)>(.*?)</p>#s', $html, $matches);
     185      preg_match('#<meta property="og:description" content="([^">]*)">#s', $html, $matches);
    177186      $video['description'] = $matches[1];
    178187     
    179       preg_match('#<meta property="og:image" content="([^">]+)" />#', $html, $matches);
     188      preg_match('#<meta property="og:image" content="([^">]+)">#', $html, $matches);
    180189      $video['thumbnail'] = $matches[1];
    181190     
    182       $video['author'] = null;
    183      
    184       preg_match_all('#<meta property="video:tag" content="([^">]+)" />#', $html, $matches);
     191      preg_match('#<meta property="video:director" content="http://www.wat.tv/([^">]+)">#', $html, $matches);
     192      $video['author'] = $matches[1];
     193     
     194      preg_match_all('#<meta property="video:tag" content="([^">]+)">#', $html, $matches);
    185195      $video['tags'] = implode(',',  $matches[1]);
     196     
    186197      break;
    187198    }
     
    196207     
    197208      $video['url'] = 'http://wideo.fr/video/'.$video['video_id'].'.html';
    198       $video['title'] = $video['video_id'];
     209      $video['title'] = 'Wideo #'.$video['video_id'];
    199210     
    200211      if (!$safe_mode)
     
    207218        $video['title'] = $matches[1];
    208219       
    209         preg_match('#<meta property="og:description" content="([^">]*)" />#', $html, $matches);
     220        preg_match('#<meta property="og:description" content="([^">]*)" />#s', $html, $matches);
    210221        $video['description'] = $matches[1];
    211222       
     
    222233      break;
    223234    }
    224      
     235
    225236    default:
    226237      return false;   
     
    267278  $thumb_name = $video['type'].'-'.$video['video_id'].'-'.uniqid().'.'.$thumb_ext;
    268279  $thumb_source = $conf['data_location'].$thumb_name;
    269   if ( empty($video['thumbnail']) or gvideo_download_remote_file($video['thumbnail'], $thumb_source) !== true )
     280 
     281  if (empty($video['thumbnail']) or gvideo_download_remote_file($video['thumbnail'], $thumb_source) !== true)
    270282  {
    271283    $thumb_source = $conf['data_location'].get_filename_wo_extension($thumb_name).'.jpg';
     
    287299    );
    288300   
    289   if ( $config['sync_description'] and !empty($video['description']) )
     301  if ($config['sync_description'] and !empty($video['description']))
    290302  {
    291303    $updates['comment'] = pwg_db_real_escape_string($video['description']);
    292304  }
    293305 
    294   if ( $config['sync_tags'] and !empty($video['tags']) )
     306  if ($config['sync_tags'] and !empty($video['tags']))
    295307  {
    296308    $tags = pwg_db_real_escape_string($video['tags']);
     
    306318 
    307319  // register video
    308   if ( !preg_match('#^([0-9]*)$#', $config['width']) or !preg_match('#^([0-9]*)$#', $config['height']) )
     320  if (!preg_match('#^([0-9]*)$#', $config['width']) or !preg_match('#^([0-9]*)$#', $config['height']))
    309321  {
    310322    $config['width'] = $config['height'] = '';
    311323  }
    312   if ( $config['autoplay']!='0' and $config['autoplay']!='1' )
     324  if ($config['autoplay']!='0' and $config['autoplay']!='1')
    313325  {
    314326    $config['autoplay'] = '';
     
    362374  $return = ($dest === true) ? true : false;
    363375 
    364   array_push($headers, 'Accept-language: en');
     376  $headers[] = 'Accept-language: en';
    365377 
    366378  /* curl */
     
    385397    if (strpos($src, 'https://') !== false)
    386398    {
    387       curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    388       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     399      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     400      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    389401    }
    390402    if (!$return)
     
    394406    else
    395407    {
    396       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     408      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    397409    }
    398410   
     
    454466 * and film frame to an image (need GD library)
    455467 * @param: string source
    456  * @param: string destination (if null, the source si modified)
     468 * @param: string destination (if null, the source is modified)
    457469 * @return: void
    458470 */
     
    553565  }
    554566}
    555 
    556 ?>
  • extensions/gvideo/template/video_dailymotion.tpl

    r17307 r26469  
    1 <iframe src="http://www.dailymotion.com/embed/video/{$GVIDEO.video_id}?autoplay={$GVIDEO.autoplay}&amp;info={$GVIDEO.config.dailymotion.title}&amp;logo={$GVIDEO.config.dailymotion.logo}&amp;{$GVIDEO.config.dailymotion.color}"
     1<iframe src="http://www.dailymotion.com/embed/video/{$GVIDEO.video_id}?autoPlay={$GVIDEO.autoplay}&amp;info={$GVIDEO.config.dailymotion.title}&amp;logo={$GVIDEO.config.dailymotion.logo}&amp;{$GVIDEO.config.dailymotion.color}"
    22  width="{$GVIDEO.width}" height="{$GVIDEO.height}" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
  • extensions/gvideo/template/video_wideo.tpl

    r17307 r26469  
    99  <video poster="http://api.kewego.com/video/getHTML5Thumbnail/?playerKey=0df9b773a15b&sig={$GVIDEO.video_id}" height="{$GVIDEO.width}" width="{$GVIDEO.height}" preload="none" controls="controls"></video>
    1010  <script src="http://sa.kewego.com/embed/assets/kplayer-standalone.js"></script>
    11   <script defer="defer">kitd.html5loader("flash_kplayer_{$GVIDEO.video_id}");</script>
     11  <script defer="defer">kitd.html5loader("flash_kplayer_{$GVIDEO.video_id}","http://api.kewego.com/video/getHTML5Thumbnail/?playerKey=0df9b773a15b&sig={$GVIDEO.video_id}");</script>
    1212</object>
  • extensions/gvideo/template/video_youtube.tpl

    r17307 r26469  
    1 <iframe src="http://www.youtube.com/embed/{$GVIDEO.video_id}?autoplay={$GVIDEO.autoplay}" width="{$GVIDEO.width}" height="{$GVIDEO.height}" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe>
     1<iframe src="http://www.youtube-nocookie.com/embed/{$GVIDEO.video_id}?autoplay={$GVIDEO.autoplay}" width="{$GVIDEO.width}" height="{$GVIDEO.height}" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe>
Note: See TracChangeset for help on using the changeset viewer.