'yes'));
}else
echo json_encode(array('err'=>'Invalid remote url'));
exit();
}
//error_reporting(E_ALL); /**/
/**
* Call back function of cURL handlers
* when it downloads a file, it works with php >= 5.3.0
* @param $download_size total file size of the file
* @param $downloaded total file size that has been downloaded
* @param $upload_size total file size that has to be uploaded
* @param $uploadsed total file size that is uploaded
*
* Writes the log in file
*/
if(!isCurlInstalled())
{
exit(json_encode(array("error"=>"Sorry, we do not support remote upload")));
}
//checking if user is logged in or not
if(!userid())
exit(json_encode(array('error'=>'You are not logged in')));
if(isset($_POST['youtube']))
{
$youtube_url = $_POST['file'];
$filename = $_POST['file_name'];
$ParseUrl = parse_url($youtube_url);
parse_str($ParseUrl['query'], $youtube_url_prop);
$YouTubeId = isset($youtube_url_prop['v']) ? $youtube_url_prop['v'] : '';
if(!$YouTubeId)
{
exit(json_encode(array("error"=>"Invalid youtube url")));
}
########################################
# YouTube Api 3 Starts #
########################################
/**
* After deprecation of YouTube Api 2, ClipBucket is now evolving as
* it allos grabbing of youtube videos with API 3 now.
* @author Saqib Razzaq
*
* Tip: Replace part between 'key' to '&' to use your own key
*/
// grabs video details (snippet, contentDetails)
$youtube_content = file_get_contents('https://www.googleapis.com/youtube/v3/videos?id='.$YouTubeId.'&key=AIzaSyDOkg-u9jnhP-WnzX5WPJyV1sc5QQrtuyc&part=snippet,contentDetails');
$content = json_decode($youtube_content);
//$content = xml2array('http://gdata.youtube.com/feeds/api/videos/'.$YouTubeId);
// getting things such as title out of Snippet
$data = $content->items[0]->snippet;
// getting time out of contentDetails
$time = $content->items[0]->contentDetails->duration;
/**
* Converting YouTube Time in seconds
*/
function getStringBetween($str,$from,$to)
{
$sub = substr($str, strpos($str,$from)+strlen($from),strlen($str));
return substr($sub,0,strpos($sub,$to));
}
$str = $time;
$str = str_replace("P", "", $str);
$from = "T";
$to = "H";
$hours = getStringBetween($str,$from,$to);
$from = "H";
$to = "M";
$mins = getStringBetween($str,$from,$to);
$from = "M";
$to = "S";
$secs = getStringBetween($str,$from,$to);
$hours = $hours * 3600;
$mins = $mins * 60;
$total = $hours + $mins + $secs;
/* $match_arr =
array
(
"title"=>"//",
"description"=>"//",
"tags" =>"//",
"embed_code" => "//",
"duration" => "/([0-9\:]+)<\/span>/"
);
$vid_array = array();
foreach($match_arr as $title=> $match)
{
preg_match($match,$content,$matches);
$vid_array[$title] = $matches[1];
}*/
$vid_array['title'] = $data->title;
$vid_array['description'] = $data->description;
$vid_array['tags'] = $data->title;
$vid_array['duration'] = $total;
$vid_array['thumbs'] =
array('http://i3.ytimg.com/vi/'.$YouTubeId.'/1.jpg','http://i3.ytimg.com/vi/'.
$YouTubeId.'/2.jpg','http://i3.ytimg.com/vi/'.$YouTubeId.'/3.jpg',
'big'=>'http://i3.ytimg.com/vi/'.$YouTubeId.'/0.jpg');
$vid_array['embed_code'] = '