/**
  * Method to store the category
  *
  * @access	public
  * @return	boolean	True on success
  * @since	1.5
  */
 function store($data, $batchupload = 0)
 {
     $row =& $this->getTable('jomtube_videos', '');
     $user =& JFactory::getUser();
     $c = jomtube_configs::get_instance();
     // bind it to the table
     if (!$row->bind($data)) {
         JError::raiseError(500, $this->_db->getErrorMsg());
         return false;
     }
     //var_dump($row); exit();
     // Make sure the data is valid
     if (!$row->check()) {
         $this->setError($row->getError());
         return false;
     }
     if ($batchupload == 0) {
         // ###########################################################
         // ###### CONVERT VIDEO TO FLV OR MP4-H264
         // ###########################################################
         if ($c->use_ffmpeg) {
             //convert video to flv or mp4
             $path_file = $data['catdir'] . '/' . $row->video_url;
             if ($c->h264_convert2mp4) {
                 $path_new = $data['catdir'] . '/' . $row->video_url . '.mp4';
                 JTHelper::movieToMp4H264_alduccino($path_file . $vidfile, $path_new, $c);
                 //update video_url
                 $row->video_url = $data['video_url'] . '.mp4';
             } else {
                 $path_new = $path_file . $vidfile . '.flv';
                 $ext = JTHelper::getFileExt($vidfile);
                 if ($ext != 'flv') {
                     JTHelper::movieToFlv($path_file . $vidfile, $path_new, $c);
                     //update video_url
                     $row->video_url = $data['video_url'] . '.flv';
                 }
             }
         }
         //manual upload video thumbnail
         $thumb_dir = $data['catdir'] . "/_thumbs";
         if (!is_dir($thumb_dir)) {
             mkdir($thumb_dir);
         }
         $thumb_file = $_FILES['thumbnail']['name'];
         if (move_uploaded_file($_FILES['thumbnail']['tmp_name'], "{$thumb_dir}/{$thumb_file}")) {
             $row->video_thumb = $thumb_file;
             //resize image
             @JTHelper::SizeImage(120, 90, "{$thumb_dir}/{$thumb_file}", "{$thumb_dir}/{$thumb_file}");
             //if ($row->duration == "")
             //$row->duration = "00:02";
         } else {
             //create thumbnail by FFMPEG
             //var_dump("$thumb_dir/$thumb_file"); exit();
             //create thumb
             if ($c->use_php_ffmpeg) {
                 $sec = JTHelper::getMovieDuration($data['catdir'] . '/' . $row->video_url);
             } else {
             }
             //continue with rest of process
             if ($sec == "" || !is_numeric($sec)) {
                 $sec = 6;
                 $duration = JTHelper::sec2hms($sec);
                 //covert to 00:00:00 i.e. hrs:min:sec
             } else {
                 $duration = JTHelper::sec2hms($sec);
                 //covert to 00:00:00 i.e. hrs:min:sec
                 $row->duration = $duration;
             }
             if ($c->use_ffmpeg) {
                 //get the middle of the movie (time; 00:00:00 format) for thumbnail
                 $sec2 = $sec / 2;
                 $sec2 = @round($sec2);
                 $thumb_position = JTHelper::sec2hms($sec2);
                 //$thumb_position = 10;
                 JTHelper::flvToThumbnail($data['catdir'] . '/' . $row->video_url, $data['catdir'] . '/_thumbs/' . $row->video_url . '.jpg', 120, 90, $thumb_position, $c);
                 if (!is_dir($data['catdir'] . '/_display')) {
                     $oldumask = umask(0);
                     @mkdir($data['catdir'] . '/_display', 0755);
                     umask($oldumask);
                 }
                 JTHelper::flvToThumbnail($data['catdir'] . '/' . $row->video_url, $data['catdir'] . '/_display/' . $row->video_url . '.jpg', 470, 320, $thumb_position, $c);
                 $row->video_thumb = $row->video_url . '.jpg';
             }
             //if ($c->use_ffmpeg)
         }
     }
     if ($row->id == 0) {
         $row->user_id = $user->id;
     }
     // Store it in the db
     if (!$row->store()) {
         JError::raiseError(500, $this->_db->getErrorMsg());
         return false;
     }
     return $row->id;
 }
 /**
  * Enter description here...
  *
  * @param unknown_type $data
  * @param unknown_type $type
  * $type = 0: batchupload, = 1: add remote video, =2: upload from local
  *  @return unknown
  */
 function store($data, $type = 0)
 {
     $row =& $this->getTable('jomtube_videos', '');
     $user =& JFactory::getUser();
     // bind it to the table
     if (!$row->bind($data)) {
         JError::raiseError(500, $this->_db->getErrorMsg());
         return false;
     }
     // Make sure the data is valid
     if (!$row->check()) {
         $this->setError($row->getError());
         return false;
     }
     if ($this->checkDuplicateRemoteVideo($row->remote_id) > 0) {
         return 1;
     }
     //var_dump($row); exit();
     if ($type == 0) {
         //batchupload
         // ###########################################################
         // ###### CONVERT VIDEO TO FLV OR MP4-H264
         // ###########################################################
         //get all settings
         $path_original = $data['catdir'] . '/' . $row->video_url;
         $c = jomtube_configs::get_instance();
         if ($c->use_ffmpeg) {
             $path_parts = pathinfo($row->video_url);
             if ($c->h264_convert2mp4) {
                 $path_new = $data['catdir'] . DS . $path_parts['filename'] . '.mp4';
                 JTHelper::movieToMp4H264_alduccino($path_original, $path_new, $c);
                 //update video_url
                 $row->video_url = $path_parts['filename'] . '.mp4';
             } else {
                 $path_new = $data['catdir'] . DS . $path_parts['filename'] . '.flv';
                 //echo $path_original;echo '<br>';
                 //echo $path_new;echo '<br>';
                 JTHelper::movieToFlv($path_original, $path_new, $c);
                 //update video_url
                 $row->video_url = $path_parts['filename'] . '.flv';
             }
             //delete original file
             if ($c->delete_orignial_file) {
                 @unlink($path_original);
             }
         }
         // ###########################################################
         // ###### CREATE THUMBNAIL FROM FLV OR MP4
         // ###########################################################
         $flv_path = $data['catdir'] . '/' . $row->video_url;
         $thumb_path = $data['catdir'] . '/_thumbs/' . $row->video_url . '.jpg';
         $display_path = $data['catdir'] . '/_display/' . $row->video_url . '.jpg';
         //get movie duration
         //$file_name = $data['filename_random'];
         //echo $file_name;echo '<pre>';echo $flv_path;
         //$path_temp = $data['catdir'] . '/' . $file_name;
         $videoInfo = JTHelper::getVideoInfo($flv_path, $c);
         //print_r($videoInfo);die();
         /*if ($c->use_php_ffmpeg) {//use php-ffmpeg
               $sec = JTHelper::getMovieDuration($flv_path);
               $duration = JTHelper::sec2hms($sec); //covert to 00:00:00 i.e. hrs:min:sec
           } else {//not use php-ffmpeg
               $sec = 6;
               $duration = '';
           }*/
         $row->duration = $videoInfo['duration']['hms'];
         $display_folder = $data['catdir'] . '/_display/';
         $thumbs_folder = $data['catdir'] . '/_thumbs/';
         if (!is_dir($display_folder)) {
             JFolder::create($display_folder, 775);
             //$oldumask=umask(0);
             // @mkdir ($display_path, 0755);
             //umask($oldumask);
         }
         if (!is_dir($thumbs_folder)) {
             JFolder::create($thumbs_folder, 775);
             //$oldumask=umask(0);
             // @mkdir ($display_path, 0755);
             //umask($oldumask);
         }
         //get the middle of the movie (time; 00:00:00 format) for thumbnail
         if ($c->use_ffmpeg) {
             //use ffmpeg
             $sec2 = $sec / 2;
             $sec2 = @round($sec2);
             $thumb_position = JTHelper::sec2hms($sec2);
             JTHelper::flvToThumbnail($flv_path, $thumb_path, 120, 90, $thumb_position, $c);
             JTHelper::flvToThumbnail($flv_path, $display_path, $c->video_player_width, $c->video_player_height, $thumb_position, $c);
             $row->video_thumb = $row->video_url . '.jpg';
         } else {
             // not use ffmpeg
             $orignial_thumb = $data['catdir'] . '/' . $row->video_thumb;
             JTHelper::SizeImage(120, 90, $orignial_thumb, $thumb_path);
             JTHelper::SizeImage($c->video_player_width, $c->video_player_height, $orignial_thumb, $display_path);
             $row->video_thumb = $row->video_url . '.jpg';
             if (file_exists($orignial_thumb)) {
                 unlink($orignial_thumb);
             }
         }
     }
     $row->user_id = $user->id;
     // Store it in the db
     //var_dump($row); exit();
     if (!$row->store()) {
         JError::raiseError(500, $this->_db->getErrorMsg());
         return false;
     }
     return $row->id;
 }