From 0bd2dde4d0248e449e12643cad316edd4fa7c33b Mon Sep 17 00:00:00 2001 From: Fahad Abbas Date: Tue, 15 Nov 2016 14:50:16 +0500 Subject: [PATCH] modified : cb reconvert issue completed --- .../styles/cb_2014/layout/video_manager.html | 16 +- .../classes/conversion/ffmpeg.class.php | 27 ++- upload/includes/functions.php | 78 ++++++-- upload/includes/functions_video.php | 176 ++++++++++++------ upload/player/CB_video_js/cb_video_js.html | 12 ++ upload/player/CB_video_js/cb_video_js.php | 15 +- upload/player/CB_video_js/js/timecomments.js | 5 +- upload/rss.php | 2 +- upload/styles/cb_28/theme/js/custom.js | 6 +- 9 files changed, 251 insertions(+), 86 deletions(-) diff --git a/upload/admin_area/styles/cb_2014/layout/video_manager.html b/upload/admin_area/styles/cb_2014/layout/video_manager.html index 93b4a3e0..d8050739 100644 --- a/upload/admin_area/styles/cb_2014/layout/video_manager.html +++ b/upload/admin_area/styles/cb_2014/layout/video_manager.html @@ -31,11 +31,7 @@ {if $videos} {foreach from=$videos item=video} - {if !isReconvertAble($video)} - {$noReconv = true} - {else} - {$noReconv = false} - {/if} + @@ -67,8 +63,9 @@ {$video.conv_progress} % Converted --> {/if*} - - {if $video.re_conv_status == 'done'}Reconverted{else if $video.re_conv_status == 'started'}Reconverting{else if $video.re_conv_status == 'failed' } Reconverting Failed {else if $noReconv == true} Non-reconvertable {/if} + + {if $video.featured=='yes'} Featured @@ -78,6 +75,11 @@ {foreach from=$cbvid->video_manager_link_new item=links} {$cbvid->video_manager_link_new($links,$video)} {/foreach} + {if !isReconvertAble($video)} + Non-Convertable + {else} + Re-Convertable + {/if} diff --git a/upload/includes/classes/conversion/ffmpeg.class.php b/upload/includes/classes/conversion/ffmpeg.class.php index 0553849c..e379b520 100644 --- a/upload/includes/classes/conversion/ffmpeg.class.php +++ b/upload/includes/classes/conversion/ffmpeg.class.php @@ -962,12 +962,15 @@ class FFMpeg{ { $video_width=(int)$value[0]; $video_height=(int)$value[1]; - - if($this->input_details['video_height'] > $video_height-1) + + $bypass = $this->check_threshold($this->input_details['video_height'],$video_height); + logData($bypass,'reindex'); + if($this->input_details['video_height'] > $video_height-1 || $bypass) { $more_res['video_width'] = $video_width; $more_res['video_height'] = $video_height; $more_res['name'] = $video_height; + logData($more_res['video_height'],'reindex'); $this->convert(NULL,false,$more_res); } @@ -1021,6 +1024,26 @@ class FFMpeg{ } } + + /** + * Used to checks if video is under threshold for conversion + * @param : { Array } { app_id } + * @todo : This Function checks if video is under threshold + * @example : check_threshold($input_vidoe_height,$current_video_height) { will check the threshold for 240p } + * @return : { Boolean } { True/ False } + * @since : 27th Oct, 2016 Feedback 1.0 + * @author : Fahad Abbas + */ + function check_threshold($input_video_height,$current_video_height){ + + $threshold = '200'; + if ($current_video_height == "240"){ + if ($input_video_height > $threshold){ + return True; + } + } + return False; + } public function generate_thumbs($input_file,$duration,$dim='120x90',$num=3,$prefix=NULL, $rand=NULL,$gen_thumb=FALSE,$output_file_path=false,$specific_dura=false) { diff --git a/upload/includes/functions.php b/upload/includes/functions.php index 34924ccd..2003c952 100644 --- a/upload/includes/functions.php +++ b/upload/includes/functions.php @@ -4309,23 +4309,47 @@ if(PHP_OS == "Linux") { $destination.'/'.$dest_name; $saveTo = $destination.'/'.$dest_name; - #exit($saveTo); - $fp = fopen ($saveTo, 'w+'); } elseif (PHP_OS == "WINNT") { $destination.'\\'.$dest_name; - $fp = fopen ($destination.'\\'.$dest_name, 'w+'); + $saveTo = $destination.'/'.$dest_name; } - - $ch = curl_init($snatching_file); - curl_setopt($ch, CURLOPT_TIMEOUT, 600); - curl_setopt($ch, CURLOPT_FILE, $fp); - curl_setopt($ch, CURLOPT_USERAGENT, - 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2'); - curl_exec($ch); - curl_close($ch); - fclose($fp); + cURLdownload($snatching_file, $saveTo); return $saveTo; - } + } + + /** + * This Function gets a file using curl method in php + * + * @param : { string } { $url } { file to be downloaded } + * @param : { string } { $file } { where to save the downloaded file } + */ + function cURLdownload($url, $file) { + + $ch = curl_init(); + if($ch) + { + $fp = fopen($file, "w"); + if($fp) + { + if( !curl_setopt($ch, CURLOPT_URL, $url) ) { + fclose($fp); // to match fopen() + curl_close($ch); // to match curl_init() + return "FAIL: curl_setopt(CURLOPT_URL)"; + } + if( !curl_setopt($ch, CURLOPT_FILE, $fp) ) return "FAIL: curl_setopt(CURLOPT_FILE)"; + if( !curl_setopt($ch, CURLOPT_HEADER, 0) ) return "FAIL: curl_setopt(CURLOPT_HEADER)"; + if( !curl_exec($ch) ) return "FAIL: curl_exec()"; + curl_close($ch); + fclose($fp); + return "SUCCESS: $file [$url]"; + } + else{ + return "FAIL: fopen()"; + } + }else{ + return "FAIL: curl_init()"; + } + } /** * Checks if CURL is installed on server @@ -5753,6 +5777,34 @@ } } + /** + * Check if a url exists using curl + * @param : { string } { $mainFile } { File to run check against } + * @author : Fahad Abbas + * @since : 14th November, 2016 + * + * @return : { boolean } { true or false matching pattern } + */ + + function is_url_exist($url){ + try{ + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_NOBODY, true); + curl_exec($ch); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + if($code == 200){ + $status = true; + }else{ + $status = false; + } + curl_close($ch); + return $status; + }catch(Exception $e){ + echo 'Caught exception: ', $e->getMessage(), "\n"; + } + + } + include( 'functions_db.php' ); include( 'functions_filter.php' ); diff --git a/upload/includes/functions_video.php b/upload/includes/functions_video.php index 682f7e6c..30435686 100644 --- a/upload/includes/functions_video.php +++ b/upload/includes/functions_video.php @@ -2015,24 +2015,48 @@ /** * Checks if given video is reconvertable or not * @param : { array } { $vdetails } { an array with all details regarding video } - * @since : 31st October, 2016 - * @author : Saqib Razzaq + * @since : 14th November October, 2016 + * @author : Fahad Abbas * * @return : { boolean } { returns true or false depending on matched case } */ function isReconvertAble($vdetails) { - global $cbvid; - if (is_array($vdetails)) { - if (empty($vdetails['embed_code']) || $vdetails['embed_code'] == 'none') { - $files = get_video_files($vdetails); - if (!empty($files)) { - if (is_array($files) || !strpos($files, 'no_video.mp4')) { - return true; + try{ + global $cbvid; + if (is_array($vdetails) && !empty($vdetails)) { + + $fileName = $vdetails['file_name']; + $fileDirectory = $vdetails['file_directory']; + $serverPath = $vdetails['file_server_path']; + + if(empty($vdetails['file_server_path'])){ + if(!empty($fileDirectory) ){ + $path = VIDEOS_DIR."/".$fileDirectory .'/'. $fileName."*"; + $vid_files = glob($path); } + else{ + $path = VIDEOS_DIR .'/'. $fileName."*"; + $vid_files = glob($path); + } + if (!empty($vid_files) && is_array($vid_files)){ + $is_convertable = true; + } + }else{ + $is_convertable = true; } + if ($is_convertable){ + return true; + }else{ + return false; + } + }else{ + return false; } + } catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "\n"; } + } /** @@ -2063,74 +2087,112 @@ // get details of single video $vdetails = $cbvid->get_video($daVideo); - if (!isReconvertAble($vdetails)) { - e("Video with id ".$vdetails['videoid']." is not re-convertable"); - continue; - } elseif (checkReConvStatus($vdetails['videoid']) == 'started') { - e("Video with id : ".$vdetails['videoid']." is already processing"); - continue; - } else { - $toConvert++; - e("Started re-conversion process for id ".$vdetails['videoid'],"m"); - } + if (!empty($vdetails['file_server_path'])){ - // grab all video files against single video - $video_files = get_video_files($vdetails); + if(empty($vdetails['file_directory'])){ + $vdetails['file_directory'] = str_replace('-', '/', $vdetails['datecreated']); + } + setVideoStatus($daVideo, 'Processing'); - // possible array of video qualities - $qualities = array('1080','720','480','360','240','hd','sd'); + $encoded['file_directory'] = $vdetails['file_directory']; + $encoded['file_name'] = $vdetails['file_name']; + $encoded['re-encode'] = true; - // loop though possible qualities, from high res to low - foreach ($qualities as $qualNow) { + $api_path = str_replace('/files', '', $vdetails['file_server_path']); + $api_path.= "/actions/re_encode.php"; - // loop through all video files of current video - // and match theme with current possible quality - foreach ($video_files as $key => $file) { + $request = curl_init($api_path); + curl_setopt($request, CURLOPT_POST, true); - // get quality of current url - $currentQuality = getStringBetween($file, '-', '.'); + curl_setopt($request,CURLOPT_POSTFIELDS,$encoded); + // output the response + curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($request, CURLOPT_RETURNTRANSFER, true); + $results_curl = curl_exec($request); + // pr($results_curl,true); + $results_curl_arr = json_decode($results_curl,true); + $returnCode = (int)curl_getinfo($request, CURLINFO_HTTP_CODE); + curl_close($request); + if(isset($results_curl_arr['success'])&&$results_curl_arr['success']=="yes"){ + e( lang( 'Your request for re-encoding '.$vdetails[ 'title' ].' has been queued.' ), 'm' ); + } + + if(isset($results_curl_arr['error'])&&$results_curl_arr['error']=="yes"){ + e( lang( $results_curl_arr['msg'] ) ); + } - // get extension of file - $currentExt = pathinfo($file, PATHINFO_EXTENSION); + }else{ + #pr($vdetails,true); + if (!isReconvertAble($vdetails)) { + e("Video with id ".$vdetails['videoid']." is not re-convertable"); + continue; + } elseif (checkReConvStatus($vdetails['videoid']) == 'started') { + e("Video with id : ".$vdetails['videoid']." is already processing"); + continue; + } else { + $toConvert++; + e("Started re-conversion process for id ".$vdetails['videoid'],"m"); + } - // if current video file matches with possible quality, - // we have found best quality video - if ($qualNow === $currentQuality || $currentExt == 'flv') { + // grab all video files against single video + $video_files = get_video_files($vdetails); - // You got best quality here, perform action on video - $subPath = str_replace(BASEURL, '', $video_files[$key]); - $fullPath = BASEDIR.$subPath; + // possible array of video qualities + $qualities = array('1080','720','480','360','240','hd','sd'); + + // loop though possible qualities, from high res to low + foreach ($qualities as $qualNow) { + + // loop through all video files of current video + // and match theme with current possible quality + foreach ($video_files as $key => $file) { + + // get quality of current url + $currentQuality = get_video_file_quality($file, '-', '.'); + // pex($currentQuality,true); + // get extension of file + $currentExt = pathinfo($file, PATHINFO_EXTENSION); + + // if current video file matches with possible quality, + // we have found best quality video + if ($qualNow === $currentQuality || $currentExt == 'flv') { + + // You got best quality here, perform action on video + $subPath = str_replace(BASEURL, '', $video_files[$key]); + $fullPath = BASEDIR.$subPath; - // change video status to processing - setVideoStatus($daVideo, 'Processing'); + // change video status to processing + setVideoStatus($daVideo, 'Processing'); - $file_name = $vdetails['file_name']; // e.g : 147765247515e0e - $targetFileName = $file_name.'.mp4'; // e.g : 147765247515e0e.mp4 - $file_directory = $vdetails['file_directory']; // e.g : 2016/10/28 - $logFile = LOGS_DIR.'/'.$file_directory.'/'.$file_name.'.log'; // e.g : /var/www/html/cb_root/files/logs/2016/10/28/147765247515e0e.log + $file_name = $vdetails['file_name']; // e.g : 147765247515e0e + $targetFileName = $file_name.'.mp4'; // e.g : 147765247515e0e.mp4 + $file_directory = $vdetails['file_directory']; // e.g : 2016/10/28 + $logFile = LOGS_DIR.'/'.$file_directory.'/'.$file_name.'.log'; // e.g : /var/www/html/cb_root/files/logs/2016/10/28/147765247515e0e.log - // remove old log file - unlink($logFile); + // remove old log file + unlink($logFile); - // path of file in temp dir - $newDest = TEMP_DIR.'/'.$targetFileName; + // path of file in temp dir + $newDest = TEMP_DIR.'/'.$targetFileName; - // move file from original source to temp - $toTemp = copy($fullPath, $newDest); + // move file from original source to temp + $toTemp = copy($fullPath, $newDest); - // add video in conversion qeue - $Upload->add_conversion_queue($targetFileName); + // add video in conversion qeue + $Upload->add_conversion_queue($targetFileName); - // begin the process of brining back from dead - exec(php_path()." -q ".BASEDIR."/actions/video_convert.php {$targetFileName} {$file_name} {$file_directory} {$logFile} > /dev/null &"); + // begin the process of brining back from dead + exec(php_path()." -q ".BASEDIR."/actions/video_convert.php {$targetFileName} {$file_name} {$file_directory} {$logFile} > /dev/null &"); - // set reconversion status - setVideoStatus($daVideo, 'started',true); - break 2; + // set reconversion status + setVideoStatus($daVideo, 'started',true); + break 2; + } } } } + } if ($toConvert >= 1) { e("Reconversion is underway. Kindly don't run reconversion on videos that are already reconverting. Doing so may cause things to become lunatic fringes :P","w"); diff --git a/upload/player/CB_video_js/cb_video_js.html b/upload/player/CB_video_js/cb_video_js.html index f535073c..2c3a5cbe 100755 --- a/upload/player/CB_video_js/cb_video_js.html +++ b/upload/player/CB_video_js/cb_video_js.html @@ -8,6 +8,7 @@ {$tcomments_params = ['function'=>'get_timeCommnets','videoid'=>$vdata.videoid]} +{$Comments_allowed = $myquery->is_commentable($vdata,'v') } {$timecomments = get_my_function($tcomments_params)} @@ -16,6 +17,13 @@ {$video_editor_enabled = get_my_function($v_editor_params)} +{$svg_manager_params = ['function'=>'get_svg_manager']} +{$svg_manager = get_my_function($svg_manager_params)} +{if $svg_manager} +{$svg_manager} +{/if} + + {if !$video_editor_enabled } {$intance_params = ['function'=>'get_slot','videoid'=>$vdata.videoid]} @@ -69,6 +77,7 @@ {$default_quality = get_cbvjs_quality_type($video_files)} +