Ignore:
Timestamp:
Jul 29, 2009, 9:15:06 PM (15 years ago)
Author:
patdenice
Message:

Allow to add videos from Wat.tv.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/gvideo/admin/add_page.php

    r3609 r3697  
    33if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    44
    5 $video_types = array('google', 'youtube', 'dailymotion', 'wideo', 'vimeo');
     5$video_types = array('google', 'youtube', 'dailymotion', 'wideo', 'vimeo', 'wat');
    66
    77function get_video_infos($url, $type)
     
    6868    return $video;
    6969
     70  case "wat":
     71    if (fetchRemote($url, $source))
     72    {
     73      @preg_match('#link rel="video_src" href="http://www.wat.tv/swf2/(.*?)"#i', $source, $id);
     74      if (empty($id[1])) return false;
     75      $video['id'] = $id[1];
     76      $video['ext'] = 'wat';
     77      if ($_POST['thumbnail'] == 'thumb_from_server')
     78      {
     79        @preg_match('#link rel="image_src" href="(.*?)"#', $source, $matches);
     80        $video['thumb_url'] = @str_replace('120x90', '320x240', $matches[1]);
     81      }
     82      return $video;
     83    }
     84
    7085  default:
    7186    return false;
    72   }
    73 }
    74 
    75 /* MUST BE REMOVED WITH PIWIGO 2.0.0 */
    76 if (!function_exists('fetchRemote'))
    77 {
    78   function fetchRemote($src, &$dest, $user_agent='Piwigo', $step=0)
    79   {
    80     // After 3 redirections, return false
    81     if ($step > 3) return false;
    82 
    83     // Initialize $dest
    84     is_resource($dest) or $dest = '';
    85 
    86     // Try curl to read remote file
    87     if (function_exists('curl_init'))
    88     {
    89       $ch = @curl_init();
    90       @curl_setopt($ch, CURLOPT_URL, $src);
    91       @curl_setopt($ch, CURLOPT_HEADER, 1);
    92       @curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
    93       @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    94       $content = @curl_exec($ch);
    95       $header_length = @curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    96       $status = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
    97       @curl_close($ch);
    98       if ($content !== false and $status >= 200 and $status < 400)
    99       {
    100         if (preg_match('/Location:\s+?(.+)/', substr($content, 0, $header_length), $m))
    101         {
    102           return fetchRemote($m[1], $dest, $user_agent, $step+1);
    103         }
    104         $content = substr($content, $header_length);
    105         is_resource($dest) ? @fwrite($dest, $content) : $dest = $content;
    106         return true;
    107       }
    108     }
    109 
    110     // Try file_get_contents to read remote file
    111     if (ini_get('allow_url_fopen'))
    112     {
    113       $content = @file_get_contents($src);
    114       if ($content !== false)
    115       {
    116         is_resource($dest) ? @fwrite($dest, $content) : $dest = $content;
    117         return true;
    118       }
    119     }
    120 
    121     // Try fsockopen to read remote file
    122     $src = parse_url($src);
    123     $host = $src['host'];
    124     $path = isset($src['path']) ? $src['path'] : '/';
    125     $path .= isset($src['query']) ? '?'.$src['query'] : '';
    126    
    127     if (($s = @fsockopen($host,80,$errno,$errstr,5)) === false)
    128     {
    129       return false;
    130     }
    131 
    132     fwrite($s,
    133       "GET ".$path." HTTP/1.0\r\n"
    134       ."Host: ".$host."\r\n"
    135       ."User-Agent: ".$user_agent."\r\n"
    136       ."Accept: */*\r\n"
    137       ."\r\n"
    138     );
    139 
    140     $i = 0;
    141     $in_content = false;
    142     while (!feof($s))
    143     {
    144       $line = fgets($s);
    145 
    146       if (rtrim($line,"\r\n") == '' && !$in_content)
    147       {
    148         $in_content = true;
    149         $i++;
    150         continue;
    151       }
    152       if ($i == 0)
    153       {
    154         if (!preg_match('/HTTP\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/',rtrim($line,"\r\n"), $m))
    155         {
    156           fclose($s);
    157           return false;
    158         }
    159         $status = (integer) $m[2];
    160         if ($status < 200 || $status >= 400)
    161         {
    162           fclose($s);
    163           return false;
    164         }
    165       }
    166       if (!$in_content)
    167       {
    168         if (preg_match('/Location:\s+?(.+)$/',rtrim($line,"\r\n"),$m))
    169         {
    170           fclose($s);
    171           return fetchRemote(trim($m[1]),$dest,$user_agent,$step+1);
    172         }
    173         $i++;
    174         continue;
    175       }
    176       is_resource($dest) ? @fwrite($dest, $line) : $dest .= $line;
    177       $i++;
    178     }
    179     fclose($s);
    180     return true;
    18187  }
    18288}
Note: See TracChangeset for help on using the changeset viewer.