<?php

class EWRmedio_Services_Ustream extends XenForo_Model
{
	public static function dumpMedia($service, $matches)
	{
		$client = new Zend_Http_Client('https://api.ustream.tv/videos/'.$matches['sval1'].'.json');
		$feed = $client->request()->getBody();
		$json = json_decode($feed, true);
		
		if (!empty($json['error']))
		{
			throw new XenForo_Exception($json['msg'], true);
		}
		
		$json = $json['video'];
		
		$media = array(
			'media_value1' => $json['id'],
			'media_value2' => '',
			'media_thumb' => $json['thumbnail']['default'],
			'media_title' => $json['title'],
			'media_description' => $json['description'],
			'media_duration' => $json['length'],
			'media_keywords' => '',
		);
		
		return $media;
	}
}