modified : cb reconvert issue completed

This commit is contained in:
Fahad Abbas 2016-11-15 14:50:16 +05:00
parent 8b5a091c6e
commit 0bd2dde4d0
9 changed files with 251 additions and 86 deletions

View file

@ -31,11 +31,7 @@
</tr>
{if $videos}
{foreach from=$videos item=video}
{if !isReconvertAble($video)}
{$noReconv = true}
{else}
{$noReconv = false}
{/if}
<tr>
<td>
<input name="check_video[]" type="checkbox" id="check_video" value="{$video.videoid}"/>
@ -67,8 +63,9 @@
{$video.conv_progress} % Converted
</span> -->
{/if*}
<span class="label {if $video.re_conv_status=='started'}label-warning{else if $video.re_conv_status=='failed'}label-danger{else if $video.re_conv_status=='done'}label-success{else}label-primary{/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} </span>
<!-- <span class="label {if $video.re_conv_status=='started'}label-warning{else if $video.re_conv_status=='failed'}label-danger{else if $video.re_conv_status=='done'}label-success{else}label-primary{/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} </span> -->
{if $video.featured=='yes'}
<span class="label label-info">
Featured</span>
@ -78,6 +75,11 @@
{foreach from=$cbvid->video_manager_link_new item=links}
{$cbvid->video_manager_link_new($links,$video)}
{/foreach}
{if !isReconvertAble($video)}
<span class="label label-warning">Non-Convertable</span>
{else}
<span class="label label-info">Re-Convertable</span>
{/if}
</div>
</div>

View file

@ -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)
{

View file

@ -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' );

View file

@ -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");

View file

@ -8,6 +8,7 @@
<!-- This code is added for timecomments plugin-->
{$tcomments_params = ['function'=>'get_timeCommnets','videoid'=>$vdata.videoid]}
{$Comments_allowed = $myquery->is_commentable($vdata,'v') }
{$timecomments = get_my_function($tcomments_params)}
<!-- End -->
@ -16,6 +17,13 @@
{$video_editor_enabled = get_my_function($v_editor_params)}
<!-- End -->
{$svg_manager_params = ['function'=>'get_svg_manager']}
{$svg_manager = get_my_function($svg_manager_params)}
{if $svg_manager}
{$svg_manager}
{/if}
<!-- This code is added for instance manager Interactive ads plugin intances-->
{if !$video_editor_enabled }
{$intance_params = ['function'=>'get_slot','videoid'=>$vdata.videoid]}
@ -69,6 +77,7 @@
{$default_quality = get_cbvjs_quality_type($video_files)}
<video id="cb_video_js" class="video-js vjs-default-skin" height="{$height}" width="{$width}" poster="{getThumb vdetails=$vdata size=768x432}" >
{foreach $video_files as $file}
{$quality = get_cbvjs_quality($file)}
@ -83,6 +92,7 @@
</video>
<script type="text/javascript">
var vid_id = "{$vdata.videoid}";
var videotitle = "{$vdata.title|escape_quotes}";
@ -112,6 +122,7 @@
var user_id = "{userid()}";
var username = "{username()}";
var user_profile = "{$userquery->avatar('','m',userid())}";
var allow_comments = "{$Comments_allowed}";
}
var play_ad = "{$play_ad}"; // Ad settings starts to pass on to player
@ -173,6 +184,7 @@
userid : user_id,
userprofile : user_profile,
username : username,
allowComments : allow_comments,
forceShow : true
}
cb_vjs.timecomments(comments_options);

View file

@ -79,7 +79,12 @@ if (!function_exists('cb_video_js'))
*/
function get_cbvjs_quality_type($video_files){
if ($video_files){
$one_file = get_cbvjs_quality($video_files[0]);
if (!empty($video_files[240])){
$video_file = $video_files[240];
}else{
$video_file = $video_files[0];
}
$one_file = get_cbvjs_quality($video_file);
if (is_numeric($one_file)){
$cb_combo_res = True;
}else{
@ -166,6 +171,14 @@ if (!function_exists('cb_video_js'))
return false;
}
}
case 'get_svg_manager':{
if ( IA_ADS_INSTALLED == 'installed' ){
$svg_manager = svg_manager();
return $svg_manager;
}else{
return false;
}
}
case 'get_slot':{
if ( IA_ADS_INSTALLED == 'installed' ){
global $ia_ads;

View file

@ -18,8 +18,9 @@ TimeComments.prototype.init = function(){
}else{
timecomments.comments = timecomments.GetTimeComments(timecomments.settings.dummy);
}
/*console.log(timecomments.comments);*/
timecomments.AddComment();
if (timecomments.settings.allowComments){
timecomments.AddComment();
}
timecomments.AddControlBArMenu();
timecomments.Structure();
timecomments.playPause();

View file

@ -99,7 +99,7 @@ subtitle($title);
?>
<item>
<author><?=$video['username']?></author>
<![CDATA[ <title><?=substr($video['title'],0,50)?></title> ]]>
<title><?=substr($video['title'],0,50)?></title>
<link><?=video_link($video)?></link>
<description>
<![CDATA[

View file

@ -7,10 +7,10 @@ function headerFooter()
cont_height = $("#container").height();
headerheight = $("#header").outerHeight();
footerheight = $("#footer").outerHeight();
console.log('headerheight=>'+headerheight+',footerheight=>'+footerheight);
console.log("cont_height"+cont_height)
/*console.log('headerheight=>'+headerheight+',footerheight=>'+footerheight);
console.log("cont_height"+cont_height)*/
cont_height_new = cont_height - (headerheight + footerheight);
console.log("cont_height_new"+cont_height_new)
/*console.log("cont_height_new"+cont_height_new)*/
$("#container").css('padding-top',headerheight+'px');
$("#container").css('padding-bottom',footerheight+'px');