/**
  * CRON upload video to archive
  * @author Oleg D.
  */
 function cronUploadVideosToArchive()
 {
     Configure::write('debug', 1);
     ini_set('mysql.connect_timeout', '6000');
     set_time_limit(6000);
     App::import('Vendor', 'YouTube', array('file' => 'class.YouTube.php'));
     $VideoTube = new YouTube();
     $videos = $this->Video->find('all', array('conditions' => array('is_downloaded' => '0', 'is_file' => 1, 'is_processed' => 1, 'is_deleted' => 0), 'limit' => 2));
     if (!empty($videos)) {
         foreach ($videos as $video) {
             if ($video['Video']['youtube_id']) {
                 $filename = '../webroot/video_archive/' . $video['Video']['youtube_id'];
                 $VideoTube->download_video($video['Video']['youtube_id'], $filename);
                 if (file_exists($filename . '.flv')) {
                     $this->Video->save(array('id' => $video['Video']['id'], 'is_downloaded' => 1));
                     echo $video['Video']['youtube_id'] . " - downloaded";
                     echo "<br/>";
                 }
             }
         }
     }
     exit;
 }