<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

/**
 * Video Player - by Duktee
 *
 * @package		Video Player
 * @version		Version 2.5
 * @author		Benjamin David
 * @copyright	Copyright (c) 2011 - Duktee
 * @license		http://duktee.com/addons/video-player/license
 * @link		http://duktee.com/addons/video-player/
 *
 */
 
class Videoplayer_lib {
	
	var $services = array();
	
	/**
	 * Constructor
	 *
	 */
	function __construct()
	{
		$this->EE =& get_instance();
		
		
		// Video Player cache path
		
		$this->_cache_path = APPPATH.'cache/videoplayer/';
		
		
		// create cache folder if it doesn't exist
		
		if(!file_exists($this->_cache_path))
		{
			@mkdir($this->_cache_path, 0777);
		}
	}

	// --------------------------------------------------------------------	
	
	/**
	 * Endpoint serving given method (for ajax)
	 *
	 * @access	public
	 * @return	void
	 */
	function endpoint()
	{
		$method = $this->EE->input->get('videoplayer_method');
		
		if($method)
		{
			if(method_exists($this, 'ajax_'.$method)) 
			{
				$this->{'ajax_'.$method}();
			}
			
			die();
		}
	}

	// --------------------------------------------------------------------	
	
	/**
	 * Returns endpoint URL with given method
	 *
	 * @access	public
	 * @param	string
	 * @return	string
	 */
	function endpoint_url($method=false)
	{
		//ajax_action_url
		
		$url = $this->endpoint_base();

		if($url && $method)
		{
		
			// for both front and cp we need to add our custom method
			
			$url .= '&videoplayer_method='.$method;	
		}

		return $url;
	}

	// --------------------------------------------------------------------	
	
	/**
	 * Endpoint base URL for frontend & cp
	 *
	 * @access	public
	 * @return	void
	 */
	 
	function endpoint_base()
	{
		$url 			= false;
		$front_url 		= $this->EE->functions->fetch_site_index(0, 1);
		$cp_url 		= $this->EE->config->item('cp_url');
		$current_url 	= $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
		
		
		// this will help define if we are in cp and remove the http(s):// segment
		
		$is_cp_host = strpos($cp_url, $_SERVER['HTTP_HOST']);
		
		
		// default url used is the one for the front
		//(because we need more processing for cp)
		
		$url_type = 'front';
		
		if($is_cp_host !== false && $is_cp_host > 2)
		{
			// 	the current http_host is the same as CP's,
			//	now we have to check that we are really in CP

			if(strpos($current_url, substr($cp_url, $is_cp_host)) !== false)
			{
			
				// we are in cp
				
				$url_type = 'cp';
			}

		}
		
		switch($url_type)
		{
		
			case 'front':
				
				// add the action id
				$action_id = $this->EE->db->where(array('class' => 'Videoplayer', 'method' => 'ajax'))->get('actions')->row('action_id');
				$url = $front_url.QUERY_MARKER."ACT=".$action_id;
				
				break;
			
			
			case 'cp':
			
				
				// let's start by keeping only the http(s):// segment
				
				$url = substr($cp_url, 0, $is_cp_host);
				
				
				// add the host
				
				$url .= $_SERVER['HTTP_HOST'];
				
				// and the request URI
				
				$url .= $_SERVER['REQUEST_URI'];
				
				break;
		}
		
		return $url;
	}

	// --------------------------------------------------------------------	

	/**
	 * Return video defaults
	 *
	 * @access	public
	 * @return	array
	 */
	 
	function video_defaults()
	{
		$video = array(
			'url' 					=> false,
			'id' 					=> false,
			'service_key' 			=> false,
			'service_name' 			=> false,
			'embed' 				=> false,
			'embed_universal' 		=> false,	// currently defined for youtube, vimeo & dailymotion
			'embed_mobile' 			=> false,	// alias for universal
			'embed_flash' 			=> false,
			'embed_script' 			=> false,
			'width' 				=> "",
			'height' 				=> "",
			'thumbnail' 			=> false,	// vimeo + youtube
			'thumbnail_medium' 		=> false,	// vimeo
			'thumbnail_large' 		=> false,	// vimeo
			'thumbnail_1' 			=> false,	// youtube
			'thumbnail_2' 			=> false,	// youtube
			'thumbnail_3' 			=> false,	// youtube
			'title'		 			=> false,	// vimeo + youtube
			'description'			=> false,	// vimeo + youtube
			'username'	 			=> false,	// vimeo + youtube
			'author'	 			=> false,	// vimeo + youtube
			'date'		 			=> false,	// vimeo + youtube
			'plays'		 			=> false,	// vimeo + youtube
			'duration'	 			=> false,	// vimeo + youtube
			'duration_seconds'		=> false,	// vimeo + youtube
			'video_page'			=> false, 	// vimeo + youtube
			
			// deprecated tags
			'service' 				=> false, 	// deprecated since v1.3 - replaced by {service_key}
			'src' 					=> false, 	// deprecated since v1.2 - replaced by {url}
			'video_url' 			=> false, 	// deprecated since v2.5 - replaced by {url}
			'video_id' 				=> false, 	// deprecated since v2.5 - replaced by {id}
			'error' 				=> "",		// deprecated since 2.5
			'video_found' 			=> true,	// true by default because deprecated since 2.5
			'no_video' 				=> false,	// false by default because deprecated since 2.5
		);
		
		return $video;
	}
	 
	 
	// --------------------------------------------------------------------	

	/**
	 * gets the video from given options
	 *
	 * @access	public
	 * @param	array
	 * @return	array
	 */
	function get_video($video_opts = array())
	{
		$this->set_services();
		
		
		// set video defaults

		$video = $this->video_defaults();
		
		
		// mix default array with given ones
		
		$video = array_merge($video, $video_opts);
		
		
		// use old src parameter if necessary (to be deprecated)
		
		if(!$video['url'] && $video['src'])
		{
			$video['url'] = $video['src'];
		}

		
		// clean spaces in the url
		
		$video['url'] = trim($video['url']);
		
		
		// check if slashes are encoded and decodes html if so
		
		if(preg_match("/&#47;/", $video['url']))
		{
			$video['url'] = html_entity_decode($video['url']);
		}
		
		// default width and height values
		
		$video['width'] 	= ($video['width']) ? $video['width'] : 425;
		$video['height'] 	= ($video['height']) ? $video['height'] : 344;

		
		foreach($this->services as $service_key => $service)
		{
		
			// Check if there is a video service for the given URL
			
			if(preg_match($service['regexp'][0], $video['url'], $matches, PREG_OFFSET_CAPTURE) > 0)
			{
			
				// regexp match key
				
				$match_key = $service['regexp'][1];
				
				
				// define video id
				
				$video_id = $matches[$match_key][0];
				
				
				// Fixes the youtube &feature_gdata bug
				
				if(strpos($video_id, "&"))
				{
					$video_id = substr($video_id, 0, strpos($video_id, "&"));
				}
				
				
				// define some variables & aliases for the video array
				
				$video['id'] 			= $video_id;
				$video['service_key'] 	= $service_key;
				$video['service'] 		= $service_key;		// deprecated
				$video['service_name'] 	= $service['name'];
				$video['video_url'] 	= $video['url'];
				

				// load more data if possible
				// check if the metadata function exists for this service
				
				if(method_exists($this, 'metadata_'.$video['service_key']))
				{
				
					// get video service specific metadata
					
					if($video = $this->{'metadata_'.$video['service_key']}($video))
					{							
						
						// post process date and other variables we want to improve
						
						$video['duration_seconds'] = $video['duration'];
						$video['duration'] = $this->format_duration($video['duration_seconds']);
					}
				}


				// universal (mobile), flash and script embeds
				
				$video['embed_universal'] 	= $this->get_universal_embed($service['universal_url'], $video_id, $video['width'], $video['height']);
				$video['embed_mobile'] 		= $video['embed_universal']; // alias for mobile
				$video['embed_flash'] 		= $this->get_flash_embed($service['flash_url'], $video_id, $video['width'], $video['height']);
				$video['embed_script'] 		= $this->get_flash_embed($service['script'], $video_id, $video['width'], $video['height']);
				
				
				// now that we have setup all possible embed,
				// choose the one to use by default in this order : universal, flash, script
				
				if($video['embed_universal'])
				{
					$video['embed'] = $video['embed_universal'];
				}
				elseif($video['embed_flash'])
				{
					$video['embed'] = $video['embed_flash'];
				}
				elseif($video['embed_script'])
				{
					$video['embed'] = $video['embed_script'];
				}
			}
		}

		return $video;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Get universal embed embed
	 *
	 * @access	public
	 * @param	string
	 * @param	string
	 * @param	int
	 * @param	int
	 * @return	string
	 */
	function get_universal_embed($format, $video_id, $width, $height)
	{
		if(!$format)
		{
			return false;
		}
			
		$embed = sprintf($format, $video_id, $width, $height);
		
		return $embed;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Get flash embed
	 *
	 * @access	public
	 * @param	string
	 * @param	string
	 * @param	int
	 * @param	int
	 * @return	string
	 */
	function get_flash_embed($format, $video_id, $width, $height)
	{
		if(!$format)
		{
			return false;
		}
			
		// Video packed in an embed tag
		
		$video_url = sprintf($format, $video_id);

		
		// embed html tag
		
		$embed = '
			<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'.$width.'" height="'.$height.'">
				<param name="movie" value="'.$video_url.'"></param>
				<!--[if !IE]>-->
				<object type="application/x-shockwave-flash" width="'.$width.'" height="'.$height.'" style="width: '.$width.'px; height: '.$height.'px;" data="'.$video_url.'">
				<param name="wmode" value="transparent"></param>
				<!--<![endif]-->
				
				<!--[if !IE]>-->
				</object>
				<!--<![endif]-->
			</object>
		';
		
		return $embed;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Get javascript embed
	 *
	 * @access	public
	 * @param	string
	 * @param	string
	 * @param	int
	 * @param	int
	 * @return	string
	 */
	function get_script_embed($format, $video_id, $width, $height)
	{
		if(!$format)
		{
			return false;
		}
		
		$embed = sprintf($format, $video_id, $width, $height);
		
		return $embed;
	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Check if video exists from the video page header status
	 *
	 * @access	public
	 * @param	string
	 * @return	bool
	 */
	function video_exists($url)
	{
		
		// set video URL in the parameters
		
		$params['url'] = $url;
		
		
		// get the video with given parameters
		
		$this->video = $this->get_video($params);
		$video = $this->video;
		
		if($video['url'])
		{
			$video_headers = get_headers($video['url']);

			if((strpos($video_headers[0], "200") !== false))
			{
				return true;
			}
		}

		return false;

	}
	
	// --------------------------------------------------------------------
	
	/**
	 * Get Video Meta Data from Youtube
	 *
	 * @access	private
	 * @param	array
	 * @return	array
	 */
	function metadata_youtube($video)
	{

		// api url
		
		$url = "http://gdata.youtube.com/feeds/api/videos/".$video['id']."?format=5";
		
		
		// api url hash (for the cache)
		
		$url_hash = md5($url);

		
		// create cache if it doesn't exist
		
		if(!$data = $this->cache_get($url_hash))
		{
			$data = @file_get_contents($url);
			
			$this->cache_save($url_hash, $data, (60 * 60 * 24 * 1));
		}
		

		if(!$data)
		{
		
			// if there is an error with the previous file_get_contents, we stop here
			
			return $video;
		}
		
		$data = simplexml_load_string($data);
		
		$v = $data;
		
		
		// video attributes
		
		$media = $v->children('http://search.yahoo.com/mrss/');
		$yt = $v->children('http://gdata.youtube.com/schemas/2007');
		$yt_media = $media->children('http://gdata.youtube.com/schemas/2007');
		$yt_attrs = $yt_media->duration->attributes();
		$yt_attrs2 = $yt->statistics;
		
		
		// view count to zero if not found
		
		$view_count = 0;
		
		if($yt_attrs2)
		{
			$view_count = (string) $yt_attrs2->attributes()->viewCount;
		}
		
		
		// assign new variables
		
		$video['title'] 			= (string) $v->title;
		$video['description'] 		= (string) $v->content;
		$video['username'] 			= (string) $v->author->name;
		$video['author'] 			= (string) $v->author->name;
		$video['date'] 				= (string) strtotime($v->published);
		$video['plays'] 			= (string) $view_count;
		$video['duration'] 			= (string) $yt_attrs['seconds'];
		$video['thumbnail'] 		= (string) $media->group->thumbnail[1]->attributes()->url;
		$video['thumbnail_1'] 		= (string) $media->group->thumbnail[1]->attributes()->url;
		$video['thumbnail_2'] 		= (string) $media->group->thumbnail[2]->attributes()->url;
		$video['thumbnail_3'] 		= (string) $media->group->thumbnail[3]->attributes()->url;
		$video['thumbnail_medium'] 	= false;
		$video['thumbnail_large'] 	= (string) $media->group->thumbnail[0]->attributes()->url;
		$video['video_page']		= (string) $v->link->attributes()->href;
		
		return $video;

	}

	// --------------------------------------------------------------------	
	
	/**
	 * Get Video Meta Data from Vimeo
	 *
	 * @access	private
	 * @param	array
	 * @return	array
	 */
	function metadata_vimeo($video)
	{
	
		// api call
		
		$url = "http://vimeo.com/api/v2/video/".$video['id'].".php";
		$url_hash = md5($url);
		
		
		// cache file if it doesn't exist
		
		if(!$contents = $this->cache_get($url_hash))
		{
			$contents = @file_get_contents($url);
			$this->cache_save($url_hash, $contents, (60 * 60 * 24 * 1));
		}
		
		if(!$contents)
		{
			
			// if there is an error with the previous file_get_contents, we stop here
			
			return $video;
		}
		
		
		// unserialize response
		
		$v = unserialize($contents);
		
		if(isset($v[0]))
		{
			$v = $v[0];
	
			
			// assign new variables
			
			$video['title'] 			= (string) $v['title'];
			$video['description'] 		= (string) $v['description'];
			$video['username'] 			= (string) $v['user_name'];
			$video['author'] 			= (string) $v['user_name'];
			$video['date'] 				= (string) strtotime($v['upload_date']);
			$video['plays'] 			= (string) $v['stats_number_of_plays'];
			$video['duration'] 			= (string) $v['duration'];
			$video['thumbnail'] 		= (string) $v['thumbnail_small'];
			$video['thumbnail_medium'] 	= (string) $v['thumbnail_medium'];
			$video['thumbnail_large'] 	= (string) $v['thumbnail_large'];
			$video['video_page'] 		= (string) $v['url'];
		}

		return $video;
	}

	// --------------------------------------------------------------------	
	
	/**
	 * Load the Video Player box
	 *
	 * @access	public
	 * @return	void
	 */
	function ajax_box()
	{
		$this->EE->load->library('videoplayer_lib');
		$this->EE->load->helper(array('url', 'form'));
		echo $this->EE->load->view('box', false, true);
		die();
	}

	// --------------------------------------------------------------------	
	
	/**
	 * Load the video HTML embed with ajax
	 *
	 * @access	public
	 * @return	void
	 */
	function ajax_video()
	{
		$this->EE->load->library('videoplayer_lib');
		if($this->EE->input->get('video_url'))
		{
			$video_url = urldecode($this->EE->input->get('video_url'));
			
			
			// video options
			
			$video_opts = array();
			$video_opts['url'] = $video_url;
			$video_opts['width'] = 376;
			$video_opts['height'] = 250;
			
			$video = $this->get_video($video_opts);
			
			echo $video['embed'];
		}
		
		die();
	}

	// --------------------------------------------------------------------	
	
	/**
	 * Search videos using service APIs
	 *
	 * @access	public
	 * @return	void
	 */
	function ajax_search()
	{

		$videos = array();
		
		$q = rawurldecode($this->EE->input->get('q'));
		$q = trim($q);

		if(!empty($q))
		{
		
			// search youtube videos
			
			$videos['youtube'] = $this->_ajax_search_youtube($q);
			
			
			// search vimeo videos
			
			$videos['vimeo'] = $this->_ajax_search_vimeo($q);

			
			// fetch services
			
			foreach($videos as $vservice => $v_videos)
			{
				
				if(count($v_videos) > 0)
				{
				
					// fetch videos
					
					foreach($v_videos as $k => $video)
					{
						
						// fetch video parameters
						
						foreach($video as $video_k => $v_v)
						{
						
							// reformat some data for the results
							
							switch($video_k)
							{
								case "title":
								
									// shorten title
									
									if(strlen($videos[$vservice][$k]['title']) > 50)
									{
										$videos[$vservice][$k]['title'] = substr($videos[$vservice][$k]['title'], 0, 47)."&hellip;";
									}
									
									
									// no spaces in the first 30 caracters ?
									// then make it even shorter just in case
									
									if(strpos(substr($videos[$vservice][$k]['title'], 0, 30), " ") == false)
									{
										$videos[$vservice][$k]['title'] = substr($videos[$vservice][$k]['title'], 0, 30)."&hellip;";
									}
									
									break;
							
								case "plays":
									$videos[$vservice][$k]['plays'] = $videos[$vservice][$k]['plays'] * 1;
									break;
								
								case "date":
									$videos[$vservice][$k]['date'] = strftime("%m.%d.%Y", $videos[$vservice][$k]['date']);
									break;
								
								case "duration":
									$duration_seconds = $v_v;
									$videos[$vservice][$k]['duration_seconds'] 	= $duration_seconds;
									$videos[$vservice][$k]['duration'] 			= $this->format_duration($duration_seconds);
									break;
							}
						}
					}
				}
			}
					
		}
		
		$vars['videos'] = $videos;
		
		echo $this->EE->load->view('search-results', $vars, true);
		
		die();

	}

	// --------------------------------------------------------------------	
	
	/**
	 * Search Youtube videos
	 *
	 * @access	private
	 * @param	string
	 * @return	array
	 */
	function _ajax_search_youtube($q)
	{
		$videos = array();
		$q = str_replace(" ", "+", $q);
		$url = "http://gdata.youtube.com/feeds/api/videos?q=".$q."&start-index=1&max-results=30&v=2&format=5";
		$r = simplexml_load_file($url);

		foreach($r->entry as $v)
		{
			
			$new_v = array();
			$media = $v->children('http://search.yahoo.com/mrss/');
			$yt = $v->children('http://gdata.youtube.com/schemas/2007');
			
			$yt_media = $media->children('http://gdata.youtube.com/schemas/2007');
			$yt_attrs = $yt_media->duration->attributes();
			$yt_attrs2 = $yt->statistics;
			
			$view_count = 0;
			
			if($yt_attrs2)
			{
				$view_count = (string) $yt_attrs2->attributes()->viewCount;
			}
			
			
			// assign new variables
			
			$new_v['title'] 		= (string) $v->title;
			$new_v['service_name'] 	= "YouTube";
			$new_v['description'] 	= (string) $v->content;
			$new_v['username'] 		= (string)$v->author->name;
			$new_v['author'] 		= (string) $v->author->name;
			$new_v['date'] 			= (string) strtotime($v->published);
			$new_v['plays'] 		= (string) $view_count;
			$new_v['duration'] 		= (string) $yt_attrs['seconds'];
			$new_v['thumbnail'] 	= (string) $media->group->thumbnail[0]->attributes()->url;
			$new_v['video_page'] 	= (string) $v->link->attributes()->href;			
			
			array_push($videos, $new_v);
		}

		return $videos;

	}
	
	// --------------------------------------------------------------------	

	/**
	 * Search Vimeo videos
	 *
	 * @access	private
	 * @param	string
	 * @return	array
	 */	
	function _ajax_search_vimeo($q)
	{

		$videos = array();

		if (class_exists('phpVimeo') === false)
		{
			require_once(PATH_THIRD.'videoplayer/libraries/vimeo/vimeo.php');
		}
		
		$vimeo = new phpVimeo('0bed9fb9a553dba6264d28defc2081e0', '9a1a41c9c9d68c0a');
		
		$params = array(
			'query' 		=> $q,
			'full_response'	=> true,
			'per_page' 		=> 20,
			'format' 		=> 'php'
		);

		$r = $vimeo->call('vimeo.videos.search', $params);
		
		if(isset($r->videos->video))
		{
			foreach($r->videos->video as $v)
			{
				$new_v = array();
				$new_v['service_name'] 	= "Vimeo";					
				$new_v['title'] 		= (string) $v->title;
				$new_v['description'] 	= (string) $v->description;
				$new_v['username']		= (string) $v->owner->display_name;
				$new_v['author'] 		= (string) $v->owner->display_name;
				$new_v['date'] 			= (string) strtotime($v->upload_date);
				$new_v['plays']			= (string) $v->number_of_plays;
				$new_v['duration'] 		= (string) $v->duration;
				$new_v['thumbnail'] 	= (string) $v->thumbnails->thumbnail[0]->_content;

				
				// find the video url
				
				$v_urls = $v->urls->url;

				foreach($v_urls as $v_url)
				{
					if($v_url->type == "video")
					{
						$new_v['video_page'] = (string) $v_url->_content;
					}
				}
				
				array_push($videos, $new_v);
			}
		}

		return $videos;

	}
	
	// --------------------------------------------------------------------	

	/**
	 * Get cache file
	 *
	 * @access	private
	 * @param	string
	 * @return	string
	 */
	function cache_get($id)
	{
	
		$this->EE->load->helper('file');
		
		if ( ! file_exists($this->_cache_path.$id))
		{
			return FALSE;
		}
		
		$data = read_file($this->_cache_path.$id);

		$data = unserialize($data);
		
		if (time() >  $data['time'] + $data['ttl'])
		{
			unlink($this->_cache_path.$id);
			return FALSE;
		}
		
		return $data['data'];
	}
	
	// --------------------------------------------------------------------	

	/**
	 * Save cache file with time to live
	 *
	 * @access	private
	 * @param	string
	 * @param	string
	 * @param	integer
	 * @return	string
	 */
	function cache_save($id, $data, $ttl = 60)
	{
		
		$this->EE->load->helper('file');
		
		$contents = array(
				'time'		=> time(),
				'ttl'		=> $ttl,			
				'data'		=> $data
			);
		
		if (write_file($this->_cache_path.$id, serialize($contents)))
		{
			@chmod($this->_cache_path.$id, 0777);
			return TRUE;			
		}

		return FALSE;

	}
	
	// --------------------------------------------------------------------	
	
	/**
	 * Returns Video Player theme URL
	 *
	 * @access	public
	 * @return	string
	 */
	function theme_url()
	{
		$url = $this->EE->config->item('theme_folder_url')."third_party/videoplayer/";
		
		return $url;
	}
	
	// --------------------------------------------------------------------	
	
	/**
	 * Format duration from seconds to 00:00
	 *
	 * @access	private
	 * @param	integer
	 * @return	string
	 */
	 
	function format_duration($duration_seconds)
	{
		$temp_minutes = (floor($duration_seconds/60));								
		$temp_seconds = ($duration_seconds - (60 * floor($duration_seconds/60)));
		
		if($temp_seconds < 10)
		{
			$temp_seconds = "0".$temp_seconds;
		}

		$r = $temp_minutes.":".$temp_seconds;
		
		return $r;
	}
	 
	// --------------------------------------------------------------------
	
	/**
	 * Set video services
	 *
	 * @access	private
	 * @param	string
	 * @return	string
	 */
	private function set_services()
	{
		/* 
		
		Configuration of each video service :
	
		- regexp : regular expression for identifying the video service and extracting the video ID
		- embed : pattern of the video URL to call from an embed tag (%s : video id)
		- script : javascript tag for services that don't use an embed tag (%d : video id, %d : width, %d : height)
			
		*/

		
		// YouTube
		
		$this->services['youtube']['name'] 				= "YouTube";
		$this->services['youtube']['regexp'] 			= array('/^https?:\/\/(www\.youtube\.com|youtube\.com|youtu\.be).*\/(watch\?v=)?(.*)/', 3);
		$this->services['youtube']['universal_url']		= '<iframe src="http://www.youtube.com/embed/%s?wmode=transparent" width="%d" height="%d" frameborder="0" allowfullscreen></iframe>';
		$this->services['youtube']['flash_url'] 		= "http://www.youtube.com/v/%s";
		$this->services['youtube']['script']			= false;
		

		// Vimeo
		
		$this->services['vimeo']['name'] 				= "Vimeo";
		$this->services['vimeo']['regexp'] 				= array('/^https?:\/\/(www\.)?vimeo\.com\/([0-9]*)/', 2);
		$this->services['vimeo']['universal_url']		= '<iframe src="http://player.vimeo.com/video/%s" width="%d" height="%d" frameborder="0"></iframe>';
		$this->services['vimeo']['flash_url'] 			= "http://vimeo.com/moogaloop.swf?clip_id=%s&amp;server=vimeo.com";
		$this->services['vimeo']['script']				= false;
		
		
		// Dailymotion
		
		$this->services['dailymotion']['name'] 			= "Dailymotion";
		$this->services['dailymotion']['regexp'] 		= array('/^https?:\/\/(www\.)?dailymotion\.com\/video\/([^\/]*)/', 2);
		$this->services['dailymotion']['universal_url']	= '<iframe src="http://www.dailymotion.com/embed/video/%s" width="%d" height="%d" frameborder="0"></iframe>';
		$this->services['dailymotion']['flash_url'] 	= "http://www.dailymotion.com/swf/%s";
		$this->services['dailymotion']['script'] 		= false;
		
		
		//Veoh
		
		$this->services['veoh']['name'] 				= "Veoh";
		$this->services['veoh']['regexp'] 				= array('/^https?:\/\/(www\.)?veoh\.com.*\/watch\/([^\/]*)/', 2);
		$this->services['veoh']['universal_url'] 		= false;
		$this->services['veoh']['flash_url'] 			= "http://www.veoh.com/static/swf/webplayer/WebPlayer.swf?&permalinkId=%s&videoAutoPlay=0";
		$this->services['veoh']['script'] 				= false;
		
		
		
		// MySpace
		
		$this->services['myspace']['name'] 				= "MySpace";
		$this->services['myspace']['regexp'] 			= array('/^https?:\/\/(www\.)?myspace\.com.*\/([0-9]*)/', 2);
		$this->services['myspace']['universal_url'] 	= false;
		$this->services['myspace']['flash_url'] 		= "http://mediaservices.myspace.com/services/media/embed.aspx/m=%s,t=1,mt=video";
		$this->services['myspace']['script'] 				= false;
		
		
		// Metacafe
		
		$this->services['metacafe']['name'] 			= "Metacafe";
		$this->services['metacafe']['regexp'] 			= array('/^https?:\/\/(www\.)?metacafe\.com.*\/watch\/(.*)/', 2);
		$this->services['metacafe']['universal_url'] 	= false;
		$this->services['metacafe']['flash_url'] 		= "http://www.metacafe.com/fplayer/%s.swf";
		$this->services['metacafe']['script'] 			= false;
		
		
		// Rever
		
		$this->services['revver']['name'] 				= "Revver";
		$this->services['revver']['regexp'] 			= array('/^https?:\/\/(www\.)?revver\.com\/video\/([0-9]*)\/.*/', 2);
		$this->services['revver']['universal_url'] 		= false;
		$this->services['revver']['flash_url'] 			= false;
		$this->services['revver']['script'] 			= '<script src="http://flash.revver.com/player/1.0/player.js?mediaId:%d;width:%d;height:%d;" type="text/javascript"></script>';
	}
}

// END Videoplayer_lib class

/* End of file Videoplayer_lib.php */
/* Location: ./system/expressionengine/third_party/videoplayer/libraries/Videoplayer_lib.php */