<?php
if (!isset($gCms)) exit;


if (! $this->CheckPermission('Use Play'))
{
	return $this->DisplayErrorPage($id, $params, $returnid,$this->Lang('accessdenied'));
}

include_once dirname(__FILE__).'/class.ffmpeg.php';

$curdir = (isset($params['curdir']) ? $params['curdir'] : "");
$file = (isset($params['file']) ? $params['file'] : "");
$format = (isset($params['format']) ? $params['format'] : "flv");



$inputfile = cms_join_path($gCms->config['uploads_path'],$curdir,$file);


$ffmpeg = new pFFmpeg($this->getpreference('ffmpeg','ffmpeg'));
switch ($format) {
	case "flv" : 
		$outputfile = cms_join_path($gCms->config['uploads_path'],$curdir,substr($file,0, strrpos($file, '.')).".flv");
		$result = $ffmpeg->converttoFLV($inputfile,$outputfile);
		break;
	case "mp3" :
		$outputfile = cms_join_path($gCms->config['uploads_path'],$curdir,substr($file,0, strrpos($file, '.')).".mp3");
		$result = $ffmpeg->converttoMP3($inputfile,$outputfile);
		break;
	default :
		$result=false;
}

if (!$result)
{
	$params['error'] = $this->lang("error_ffmpeg_convert")."<pre>".$ffmpeg->output."</pre>";
}
else
{
	if (isset($params['convert']) && $params['convert']=='yes')
		@unlink($inputfile);
}

require_once(dirname(__FILE__).'/action.browse.php');




?>