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

View file

@ -962,12 +962,15 @@ class FFMpeg{
{ {
$video_width=(int)$value[0]; $video_width=(int)$value[0];
$video_height=(int)$value[1]; $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_width'] = $video_width;
$more_res['video_height'] = $video_height; $more_res['video_height'] = $video_height;
$more_res['name'] = $video_height; $more_res['name'] = $video_height;
logData($more_res['video_height'],'reindex');
$this->convert(NULL,false,$more_res); $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) 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") { if(PHP_OS == "Linux") {
$destination.'/'.$dest_name; $destination.'/'.$dest_name;
$saveTo = $destination.'/'.$dest_name; $saveTo = $destination.'/'.$dest_name;
#exit($saveTo);
$fp = fopen ($saveTo, 'w+');
} elseif (PHP_OS == "WINNT") { } elseif (PHP_OS == "WINNT") {
$destination.'\\'.$dest_name; $destination.'\\'.$dest_name;
$fp = fopen ($destination.'\\'.$dest_name, 'w+'); $saveTo = $destination.'/'.$dest_name;
} }
cURLdownload($snatching_file, $saveTo);
$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);
return $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 * 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_db.php' );
include( 'functions_filter.php' ); include( 'functions_filter.php' );

View file

@ -2015,24 +2015,48 @@
/** /**
* Checks if given video is reconvertable or not * Checks if given video is reconvertable or not
* @param : { array } { $vdetails } { an array with all details regarding video } * @param : { array } { $vdetails } { an array with all details regarding video }
* @since : 31st October, 2016 * @since : 14th November October, 2016
* @author : Saqib Razzaq * @author : Fahad Abbas
* *
* @return : { boolean } { returns true or false depending on matched case } * @return : { boolean } { returns true or false depending on matched case }
*/ */
function isReconvertAble($vdetails) { function isReconvertAble($vdetails) {
global $cbvid; try{
if (is_array($vdetails)) { global $cbvid;
if (empty($vdetails['embed_code']) || $vdetails['embed_code'] == 'none') { if (is_array($vdetails) && !empty($vdetails)) {
$files = get_video_files($vdetails);
if (!empty($files)) { $fileName = $vdetails['file_name'];
if (is_array($files) || !strpos($files, 'no_video.mp4')) { $fileDirectory = $vdetails['file_directory'];
return true; $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 // get details of single video
$vdetails = $cbvid->get_video($daVideo); $vdetails = $cbvid->get_video($daVideo);
if (!isReconvertAble($vdetails)) { if (!empty($vdetails['file_server_path'])){
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");
}
// grab all video files against single video if(empty($vdetails['file_directory'])){
$video_files = get_video_files($vdetails); $vdetails['file_directory'] = str_replace('-', '/', $vdetails['datecreated']);
}
setVideoStatus($daVideo, 'Processing');
// possible array of video qualities $encoded['file_directory'] = $vdetails['file_directory'];
$qualities = array('1080','720','480','360','240','hd','sd'); $encoded['file_name'] = $vdetails['file_name'];
$encoded['re-encode'] = true;
// loop though possible qualities, from high res to low $api_path = str_replace('/files', '', $vdetails['file_server_path']);
foreach ($qualities as $qualNow) { $api_path.= "/actions/re_encode.php";
// loop through all video files of current video $request = curl_init($api_path);
// and match theme with current possible quality curl_setopt($request, CURLOPT_POST, true);
foreach ($video_files as $key => $file) {
// get quality of current url curl_setopt($request,CURLOPT_POSTFIELDS,$encoded);
$currentQuality = getStringBetween($file, '-', '.'); // 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 }else{
$currentExt = pathinfo($file, PATHINFO_EXTENSION); #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, // grab all video files against single video
// we have found best quality video $video_files = get_video_files($vdetails);
if ($qualNow === $currentQuality || $currentExt == 'flv') {
// You got best quality here, perform action on video // possible array of video qualities
$subPath = str_replace(BASEURL, '', $video_files[$key]); $qualities = array('1080','720','480','360','240','hd','sd');
$fullPath = BASEDIR.$subPath;
// 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 // change video status to processing
setVideoStatus($daVideo, 'Processing'); setVideoStatus($daVideo, 'Processing');
$file_name = $vdetails['file_name']; // e.g : 147765247515e0e $file_name = $vdetails['file_name']; // e.g : 147765247515e0e
$targetFileName = $file_name.'.mp4'; // e.g : 147765247515e0e.mp4 $targetFileName = $file_name.'.mp4'; // e.g : 147765247515e0e.mp4
$file_directory = $vdetails['file_directory']; // e.g : 2016/10/28 $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 $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 // remove old log file
unlink($logFile); unlink($logFile);
// path of file in temp dir // path of file in temp dir
$newDest = TEMP_DIR.'/'.$targetFileName; $newDest = TEMP_DIR.'/'.$targetFileName;
// move file from original source to temp // move file from original source to temp
$toTemp = copy($fullPath, $newDest); $toTemp = copy($fullPath, $newDest);
// add video in conversion qeue // add video in conversion qeue
$Upload->add_conversion_queue($targetFileName); $Upload->add_conversion_queue($targetFileName);
// begin the process of brining back from dead // 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 &"); exec(php_path()." -q ".BASEDIR."/actions/video_convert.php {$targetFileName} {$file_name} {$file_directory} {$logFile} > /dev/null &");
// set reconversion status // set reconversion status
setVideoStatus($daVideo, 'started',true); setVideoStatus($daVideo, 'started',true);
break 2; break 2;
}
} }
} }
} }
} }
if ($toConvert >= 1) { 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"); 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--> <!-- This code is added for timecomments plugin-->
{$tcomments_params = ['function'=>'get_timeCommnets','videoid'=>$vdata.videoid]} {$tcomments_params = ['function'=>'get_timeCommnets','videoid'=>$vdata.videoid]}
{$Comments_allowed = $myquery->is_commentable($vdata,'v') }
{$timecomments = get_my_function($tcomments_params)} {$timecomments = get_my_function($tcomments_params)}
<!-- End --> <!-- End -->
@ -16,6 +17,13 @@
{$video_editor_enabled = get_my_function($v_editor_params)} {$video_editor_enabled = get_my_function($v_editor_params)}
<!-- End --> <!-- 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--> <!-- This code is added for instance manager Interactive ads plugin intances-->
{if !$video_editor_enabled } {if !$video_editor_enabled }
{$intance_params = ['function'=>'get_slot','videoid'=>$vdata.videoid]} {$intance_params = ['function'=>'get_slot','videoid'=>$vdata.videoid]}
@ -69,6 +77,7 @@
{$default_quality = get_cbvjs_quality_type($video_files)} {$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}" > <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} {foreach $video_files as $file}
{$quality = get_cbvjs_quality($file)} {$quality = get_cbvjs_quality($file)}
@ -83,6 +92,7 @@
</video> </video>
<script type="text/javascript"> <script type="text/javascript">
var vid_id = "{$vdata.videoid}"; var vid_id = "{$vdata.videoid}";
var videotitle = "{$vdata.title|escape_quotes}"; var videotitle = "{$vdata.title|escape_quotes}";
@ -112,6 +122,7 @@
var user_id = "{userid()}"; var user_id = "{userid()}";
var username = "{username()}"; var username = "{username()}";
var user_profile = "{$userquery->avatar('','m',userid())}"; 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 var play_ad = "{$play_ad}"; // Ad settings starts to pass on to player
@ -173,6 +184,7 @@
userid : user_id, userid : user_id,
userprofile : user_profile, userprofile : user_profile,
username : username, username : username,
allowComments : allow_comments,
forceShow : true forceShow : true
} }
cb_vjs.timecomments(comments_options); cb_vjs.timecomments(comments_options);

View file

@ -79,7 +79,12 @@ if (!function_exists('cb_video_js'))
*/ */
function get_cbvjs_quality_type($video_files){ function get_cbvjs_quality_type($video_files){
if ($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)){ if (is_numeric($one_file)){
$cb_combo_res = True; $cb_combo_res = True;
}else{ }else{
@ -166,6 +171,14 @@ if (!function_exists('cb_video_js'))
return false; return false;
} }
} }
case 'get_svg_manager':{
if ( IA_ADS_INSTALLED == 'installed' ){
$svg_manager = svg_manager();
return $svg_manager;
}else{
return false;
}
}
case 'get_slot':{ case 'get_slot':{
if ( IA_ADS_INSTALLED == 'installed' ){ if ( IA_ADS_INSTALLED == 'installed' ){
global $ia_ads; global $ia_ads;

View file

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

View file

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

View file

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