17 require_once SQ_CORE_PACKAGE_PATH.
'/files/file/file.inc';
18 require_once SQ_DATA_PATH.
'/private/conf/tools.inc';
41 public $allowed_extensions = Array(
'mov',
'avi',
'wmv',
'asf',
'flv',
'mp4',
'm4v',
'mpg',
'mpeg',
'ogv',
'ogg',
'webm');
52 parent::__construct($assetid);
73 $keywords = parent::getAvailableKeywords();
75 $keywords[
'asset_attribute_length'] =
'Length of File (in Minutes:Seconds)';
76 $keywords[
'asset_attribute_length_seconds'] =
'Length of File (in Seconds)';
79 $keywords[
'asset_attribute_alt_asset_X'] =
'Alternate Asset Reference for Accessibility (replace X with keyword)';
81 $keywords[
'asset_attribute_file_format_dynamic'] =
'Dynamic Keyword for File Format';
82 $keywords[
'asset_attribute_audio_codec_dynamic'] =
'Dynamic Keyword for Audio Codec';
83 $keywords[
'asset_attribute_channels_dynamic'] =
'Dynamic Keyword for Channels';
84 $keywords[
'asset_attribute_channel_mode_dynamic'] =
'Dynamic Keyword for Channel Mode';
85 $keywords[
'asset_attribute_bitrate_dynamic'] =
'Dynamic Keyword for Bit Rate';
86 $keywords[
'asset_attribute_sample_rate_dynamic'] =
'Dynamic Keyword for Sample Rate';
87 $keywords[
'asset_attribute_video_codec_dynamic'] =
'Dynamic Keyword for Video Codec';
88 $keywords[
'asset_attribute_width_dynamic'] =
'Dynamic Keyword for Width';
89 $keywords[
'asset_attribute_height_dynamic'] =
'Dynamic Keyword for Height';
90 $keywords[
'asset_attribute_fps_dynamic'] =
'Dynamic Keyword for Frames Per Second';
91 $keywords[
'asset_attribute_length_dynamic'] =
'Dynamic Keyword for Length (in Minutes:Seconds)';
92 $keywords[
'asset_attribute_length_seconds_dynamic'] =
'Dynamic Keyword for Length (in Seconds)';
93 $keywords[
'asset_attribute_video_title_dynamic'] =
'Dynamic Keyword for Video Title';
94 $keywords[
'asset_attribute_artist_dynamic'] =
'Dynamic Keyword for Artist';
95 $keywords[
'asset_attribute_album_dynamic'] =
'Dynamic Keyword for Album';
96 $keywords[
'asset_attribute_genre_dynamic'] =
'Dynamic Keyword for Genre';
97 $keywords[
'asset_attribute_comments_dynamic'] =
'Dynamic Keyword for Comments';
98 $keywords[
'asset_attribute_copyright_dynamic'] =
'Dynamic Keyword for Copyright';
99 $keywords[
'asset_attribute_year_dynamic'] =
'Dynamic Keyword for Year';
102 foreach ($keywords as $key => $val) {
103 if ($key ==
'asset_attribute_alt_asset') {
104 unset($keywords[$key]);
133 $full_keyword = $keyword;
134 $keyword = parse_keyword($keyword, $modifiers);
135 $contextid = extract_context_modifier($modifiers);
137 if ($contextid !== NULL) {
142 if ((
int)$contextid !== $GLOBALS[
'SQ_SYSTEM']->getContextId()) {
143 $GLOBALS[
'SQ_SYSTEM']->changeContext($contextid);
144 $contexted_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
id);
147 $replacement = $contexted_asset->getKeywordReplacement($keyword);
150 apply_keyword_modifiers($replacement, $modifiers, Array(
'assetid' => $contexted_asset->id));
152 unset($contexted_asset);
153 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
162 case 'asset_attribute_length' :
164 $length = $this->
attr(
'length');
165 $minutes = floor($length / 60);
166 $seconds = $length % 60;
167 $replacement = $minutes.
':'.str_pad($seconds, 2,
'0', STR_PAD_LEFT);
170 case 'asset_attribute_length_seconds' :
172 $replacement = $this->
attr(
'length');
178 if (strpos($keyword,
'asset_attribute_alt_asset_') !== FALSE) {
179 $alt_asset_key = substr($keyword, 26);
181 $alt_assetid = $this->
attr(
'alt_asset');
183 if (!empty($alt_assetid) && is_numeric($alt_assetid)) {
184 $alt_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($alt_assetid);
185 $replacement = !empty($alt_asset) ? $alt_asset->getKeywordReplacement($alt_asset_key) :
'';
193 if (substr($keyword, -8) ===
'_dynamic') {
196 if ($tags === FALSE) $tags = Array();
199 $sub_keyword = substr($keyword, 16, -8);
201 switch ($sub_keyword) {
203 $format = array_get_index($tags,
'file_format',
'');
204 $format = ucfirst($format);
205 $replacement = $format;
222 $replacement = array_get_index($tags, $sub_keyword,
'');
226 $channel_mode = array_get_index($tags,
'channel_mode',
'');
227 $channel_mode = ucfirst($channel_mode);
228 $replacement = $channel_mode;
232 $bitrate = array_get_index($tags, $sub_keyword,
'');
233 if (is_numeric($bitrate)) {
236 $bitrate = floor($bitrate / 1000);
238 $replacement = $bitrate;
241 case 'length_seconds':
242 $length = array_get_index($tags,
'length',
'');
243 if (is_numeric($length)) {
245 $length = round($length);
247 $replacement = $length;
251 $length = array_get_index($tags,
'length',
'');
252 if (is_numeric($length)) {
254 $length = round($length);
256 $minutes = floor($length / 60);
257 $seconds = $length % 60;
258 $length = $minutes.
':'.str_pad($seconds, 2,
'0', STR_PAD_LEFT);
260 $replacement = $length;
267 if (isset($replacement)) {
268 if (count($modifiers) > 0) {
269 apply_keyword_modifiers($replacement, $modifiers, Array(
'assetid' => $this->
id));
275 return parent::getKeywordReplacement($full_keyword);
295 if ($this->
attr(
'extract_id3')) {
297 if ($tags !== FALSE) {
301 foreach ($tags as $tag_name => $tag_value) {
304 $this->
setAttrValue(
'file_format', ucfirst($tag_value));
307 case 'channel_mode' :
308 $this->
setAttrValue(
'channel_mode', ucfirst($tag_value));
314 $this->
setAttrValue($tag_name, floor($tag_value / 1000));
352 return parent::saveAttributes($dont_run_updated);
374 if (is_null($file_name)) {
376 $file_name = $this->data_path_public.
'/'.$this->
attr(
'name');
378 $file_name = $this->data_path.
'/'.$this->
attr(
'name');
383 if (!SQ_TOOL_GETID3_ENABLED)
return FALSE;
386 if (!is_dir(SQ_TOOL_GETID3_PATH)) {
387 trigger_error(
'Cannot extract Video metadata; path to getID3() external tool does not exist or is not a directory', E_USER_WARNING);
392 if (!is_file(SQ_TOOL_GETID3_PATH.
'/getid3.php')) {
393 trigger_error(
'Cannot extract Video metadata; path to getID3() external tool does not point to a valid getID3() install', E_USER_WARNING);
397 if (!is_file($file_name)) {
398 trigger_error(
'Cannot extract Video metadata; Video file path provided does not exist', E_USER_WARNING);
401 require_once SQ_TOOL_GETID3_PATH.
'/getid3.php';
405 $id3->Analyze($file_name);
410 $file_samplerate = 0;
413 if ($id3->info[
'fileformat'] ==
'ogg') {
414 require_once SQ_DATA_PATH.
'/private/conf/tools.inc';
417 if (!SQ_TOOL_OGG_METADATA_EXTRACTION_ENABLED)
return FALSE;
419 if (!is_file(SQ_TOOL_OGG_METADATA_EXTRACTION_PATH)) {
420 trigger_error(
'Cannot extract OGG metadata; path to OGG Metadata Extraction external tool does not exist or is not a file', E_USER_WARNING);
428 require_once SQ_CORE_PACKAGE_PATH.
'/files/video_file/lib/Matrix_Ogg.inc';
433 $theora = isset($ogg->Streams[
'theora']) ? $ogg->Streams[
'theora'] : NULL;
435 $vorbis = isset($ogg->Streams[
'vorbis']) ? $ogg->Streams[
'vorbis'] : NULL;
438 $file_duration = $ogg->Streams[
'duration'];
439 $file_samplerate = isset($vorbis) ? $vorbis[
'samplerate'] : 0;
442 $file_bitrate = $theora[
'nombr'];
443 }
else if ($vorbis) {
444 $file_bitrate = $vorbis[
'bitrate'];
448 $file_duration = $id3->info[
'playtime_seconds'];
449 $file_bitrate = $id3->info[
'bitrate'];
450 $file_samplerate = isset($id3->info[
'audio'][
'sample_rate']) ? $id3->info[
'audio'][
'sample_rate'] : 0;
454 'length' => $file_duration,
455 'bitrate' => $file_bitrate,
456 'sample_rate' => $file_samplerate,
457 'file_format' => $id3->info[
'fileformat'],
460 $id3_tag_data = Array();
463 $tag_audio =& $id3->info[
'audio'];
464 $tag_video =& $id3->info[
'video'];
466 $tag_quicktime = NULL;
467 if (isset($id3->info[
'tags'][
'quicktime'])) {
468 $tag_quicktime =& $id3->info[
'tags'][
'quicktime'];
473 if (!is_null($vorbis)) {
474 $id3_tag_data[
'audio_codec'] = $vorbis[
'vendor'];
475 $id3_tag_data[
'channels'] = $vorbis[
'channels'];
476 $id3_tag_data[
'channel_mode'] = $vorbis[
'channels'] == 2 ?
'Stereo' :
'Mono';
478 if (!is_null($theora)) {
479 $id3_tag_data[
'video_codec'] = $theora[
'vendor'];
480 $id3_tag_data[
'width'] = $theora[
'width'];
481 $id3_tag_data[
'height'] = $theora[
'height'];
482 $id3_tag_data[
'fps'] = $theora[
'frate'];
485 if (isset($theora[
'comments'])) {
486 foreach($theora[
'comments'] as $comment) {
487 $comment_field = explode(
'=', $comment);
488 $cf = $comment_field[1];
489 switch ($comment_field[0]) {
491 $id3_tag_data[
'video_title'] = $cf;
494 $id3_tag_data[
'artist'] = $cf;
497 $id3_tag_data[
'album'] = $cf;
500 $id3_tag_data[
'genre'] = $cf;
503 $id3_tag_data[
'comments'] = $cf;
506 $id3_tag_data[
'copyright'] = $cf;
509 $id3_tag_data[
'year'] = $cf;
522 if (isset($tag_audio[
'codec'])) {
523 $id3_tag_data[
'audio_codec'] = $tag_audio[
'codec'];
525 if (isset($tag_audio[
'channels'])) {
526 $id3_tag_data[
'channels'] = $tag_audio[
'channels'];
528 if (isset($tag_audio[
'channelmode'])) {
529 $id3_tag_data[
'channel_mode'] = $tag_audio[
'channelmode'];
531 if (isset($tag_video[
'codec'])) {
532 $id3_tag_data[
'video_codec'] = $tag_video[
'codec'];
534 if (isset($tag_video[
'resolution_x'])) {
535 $id3_tag_data[
'width'] = $tag_video[
'resolution_x'];
537 if (isset($tag_video[
'resolution_y'])) {
538 $id3_tag_data[
'height'] = $tag_video[
'resolution_y'];
542 if (isset($tag_video[
'frame_rate'])) {
543 $id3_tag_data[
'fps'] = $tag_video[
'frame_rate'];
546 if (!is_null($tag_quicktime)) {
547 if (isset($tag_quicktime[
'title'][0])) {
548 $id3_tag_data[
'video_title'] = $tag_quicktime[
'title'][0];
550 if (isset($tag_quicktime[
'artist'][0])) {
551 $id3_tag_data[
'artist'] = $tag_quicktime[
'artist'][0];
553 if (isset($tag_quicktime[
'album'][0])) {
554 $id3_tag_data[
'album'] = $tag_quicktime[
'album'][0];
556 if (isset($tag_quicktime[
'genre'][0])) {
557 $id3_tag_data[
'genre'] = $tag_quicktime[
'genre'][0];
559 if (isset($tag_quicktime[
'comment'][0])) {
560 $id3_tag_data[
'comments'] = $tag_quicktime[
'comment'][0];
562 if (isset($tag_quicktime[
'copyright'][0])) {
563 $id3_tag_data[
'copyright'] = $tag_quicktime[
'copyright'][0];
565 if (isset($tag_quicktime[
'creation_date'][0])) {
566 $id3_tag_data[
'year'] = $tag_quicktime[
'creation_date'][0];
572 $data = array_merge($audio_data, $id3_tag_data);