| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * @file 5 * Class file used to wrap the transcoder functions. 6 * 7 * @todo need more commenting 8 * - Add Metadata support 9 * Add autoloading 10 * # http://stackoverflow.com/questions/3343208/php-class-lazy-loading 11 * # http://php.net/manual/en/language.oop5.autoload.php 12 * 13 */ 14 15 class video_transcoder { 16 17 private $transcoder; 18 19 public function __construct($transcoder = null) { 20 $this->transcoder = $this->get_instance($transcoder); 21 } 22 23 /** 24 * 25 * @param <type> $transcoder 26 */ 27 private function get_instance($transcoder = null) { 28 //get our configured transcoder. 29 if (!isset($transcoder)) 30 $transcoder = variable_get('vid_convertor', 'video_ffmpeg'); 31 // module_load_include('inc', 'video', '/transcoders/' . $transcoder); 32 if (!module_load_include('inc', 'video', '/transcoders/' . $transcoder)) { 33 $modules = module_list(); 34 $files = array(); 35 foreach ($modules as $module) { 36 $module_path = drupal_get_path('module', $module) . '/transcoders'; 37 $inc_files = file_scan_directory($module_path, '^.*\.inc$'); 38 if (!empty($inc_files)) 39 $files[$module] = $inc_files; 40 } 41 // @TODO : add lazy load 42 foreach ($files as $module => $_files) { 43 foreach ($_files as $file) { 44 if ($file->name == $transcoder) 45 module_load_include('inc', $module, '/transcoders/' . $file->name); 46 } 47 } 48 } 49 50 if (class_exists($transcoder)) { 51 $transcoder_instance = new $transcoder; 52 $this->transcoder = $transcoder_instance; 53 return $transcoder_instance; 54 } else { 55 drupal_set_message(t('The transcoder is not configured properly.'), 'error'); 56 } 57 } 58 59 public function generate_thumbnails($video) { 60 return $this->transcoder->generate_thumbnails($video); 61 } 62 63 public function convert_video(&$video) { 64 module_load_include('inc', 'video', '/includes/preset'); 65 $video_preset = new video_preset(); 66 $presets = $video_preset->properties(); 67 $video->presets = $presets; 68 $output = $this->transcoder->convert_video($video); 69 // if successfully converted the video then update the status to publish 70 if ($output) 71 // Update our node id to published. We do not do a node_load as it causes editing problems when saving. 72 db_query("UPDATE {node} SET status=%d WHERE nid=%d", 1, $video->nid); 73 74 // If they are using metadata. 75 // @TODO : add meta data support 76 // if (variable_get('video_metadata', FALSE)) { 77 // module_load_include('inc', 'video', '/includes/metadata'); 78 // $metadata = new video_metadata; 79 // $metadata->process($converted); 80 // } 81 return $output; 82 } 83 84 public function admin_settings() { 85 $form = array(); 86 $options = $this->_transcoders(); 87 $form['vid_convertor'] = array( 88 '#type' => 'radios', 89 '#title' => t('Video transcoder'), 90 '#default_value' => variable_get('vid_convertor', 'video_ffmpeg'), 91 '#options' => $options['radios'], 92 '#description' => t('Selecting a video transcoder will help you convert videos and generate thumbnails. !list', array('!list' => theme('item_list', $options['help']))), 93 '#prefix' => '<div id="transcoder-radios">', 94 '#suffix' => '</div>', 95 ); 96 $form = $form + $options['admin_settings']; 97 return $form; 98 } 99 100 public function admin_settings_validate($form, &$form_state) { 101 return $this->transcoder->admin_settings_validate($form, $form_state); 102 } 103 104 private function _transcoders() { 105 // @TODO : think to change this to observer patteren 106 $files = array(); 107 // Lets find our transcoder classes and build our radio options 108 // We do this by scanning our transcoders folder 109 $form = array('radios' => array(), 'help' => array(), 'admin_settings' => array()); 110 $path = drupal_get_path('module', 'video') . '/transcoders'; 111 $files = file_scan_directory($path, '^.*\.inc$'); 112 // check inside sub modules 113 $modules = module_list(); 114 foreach ($modules as $module) { 115 $mobule_files = array(); 116 $module_path = drupal_get_path('module', $module) . '/transcoders'; 117 $mobule_files = file_scan_directory($module_path, '^.*\.inc$'); 118 $files = array_merge($files, $mobule_files); 119 } 120 121 foreach ($files as $file) { 122 if (!module_load_include('inc', 'video', '/transcoders/' . $file->name)) 123 require_once $file->filename; 124 $focus = new $file->name; 125 $form['radios'][$focus->get_value()] = $focus->get_name(); 126 $form['help'][] = $focus->get_help(); 127 $form['admin_settings'] = $form['admin_settings'] + $focus->admin_settings(); 128 } 129 // //we need to move our video/thumbnail fieldsets to the bottom of our form as they are used for each trancoder 130 // $autothumb = $form['admin_settings']['autothumb']; 131 // $autoconv = $form['admin_settings']['autoconv']; 132 // unset($form['admin_settings']['autothumb'], $form['admin_settings']['autoconv']); 133 // if(!$this->transcoder->is_wsod()) 134 // $form['admin_settings']['autothumb'] = $autothumb; 135 // $form['admin_settings']['autoconv'] = $autoconv; 136 return $form; 137 } 138 139 public function get_dimensions($video) { 140 return $this->transcoder->get_dimensions($video); 141 } 142 143 public function create_job($video) { 144 return $this->transcoder->create_job($video); 145 } 146 147 public function update_job($video) { 148 return $this->transcoder->update_job($video); 149 } 150 151 public function delete_job($video) { 152 return $this->transcoder->delete_job($video); 153 } 154 155 /** 156 * Load a file based on the file id ($fid) 157 * 158 * @param $fid 159 * Integer of the file id to be loaded. 160 */ 161 public function load_job($fid) { 162 return $this->transcoder->load_job($fid); 163 } 164 165 public function load_job_queue() { 166 return $this->transcoder->load_job_queue(); 167 } 168 169 public function load_completed_job(&$video) { 170 return $this->transcoder->load_completed_job($video); 171 } 172 173 } 174 175 interface transcoder_interface { 176 177 public function create_job($video); 178 179 public function update_job($video); 180 181 public function delete_job($video); 182 183 public function load_job($fid); 184 185 public function load_job_queue(); 186 187 public function load_completed_job(&$video); 188 189 public function change_status($vid, $status); 190 191 public function generate_thumbnails($video); 192 193 public function convert_video($video); 194 195 public function get_name(); 196 197 public function get_value(); 198 199 public function get_help(); 200 201 public function admin_settings(); 202 203 public function admin_settings_validate($form, &$form_state); 204 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |