18 require_once SQ_CORE_PACKAGE_PATH.
'/files/file/file.inc';
19 require_once SQ_DATA_PATH.
'/private/conf/tools.inc';
41 public $allowed_extensions = Array(
'flv');
52 $this->_ser_attrs = TRUE;
53 parent::__construct($assetid);
56 $metadata = $this->
attr(
'attributes');
57 foreach ($metadata as $meta_name => $meta_val) {
58 $this->vars[$meta_name] = Array(
'value' => $meta_val,
'type' =>
'text',
'attrid' => 0);
80 $keywords = parent::getAvailableKeywords();
82 $keywords[
'asset_attribute_duration_string'] =
'Duration of the FLV file (in Minutes:Seconds)';
84 $keywords[
'asset_attribute_duration_int'] =
'Rounded duration of the FLV file in seconds';
85 $keywords[
'asset_attribute_width_int'] =
'The rounded width of the video in pixels';
86 $keywords[
'asset_attribute_height_int'] =
'The rounded height of the video in pixels';
87 $keywords[
'asset_attribute_framerate_int'] =
'Rounded number of frames per second';
88 $keywords[
'asset_attribute_videodatarate_int'] =
'Rounded video bit rate in kilobits per second';
89 $keywords[
'asset_attribute_videocodecid_int'] =
'The rounded video codec ID used in the file';
90 $keywords[
'asset_attribute_audiodatarate_int'] =
'Rounded audio bit rate in kilobits per second';
91 $keywords[
'asset_attribute_audiocodecid_int'] =
'The rounded audio codec ID used in the file';
92 $keywords[
'asset_attribute_audiosamplerate_int'] =
'The rounded frequency at which the audio stream is replayed';
93 $keywords[
'asset_attribute_audiosamplesize_int'] =
'The rounded resolution of a single audio sample';
95 $keywords[
'asset_attribute_XXX'] =
'Generic FLV metadata keyword';
96 $keywords[
'asset_attribute_XXX_int'] =
'Generic rounded FLV metadata keyword';
122 $full_keyword = $keyword;
123 $keyword = parse_keyword($keyword, $modifiers);
124 $contextid = extract_context_modifier($modifiers);
126 if ($contextid !== NULL) {
131 if ((
int)$contextid !== $GLOBALS[
'SQ_SYSTEM']->getContextId()) {
132 $GLOBALS[
'SQ_SYSTEM']->changeContext($contextid);
133 $contexted_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
id);
136 $replacement = $contexted_asset->getKeywordReplacement($keyword);
139 apply_keyword_modifiers($replacement, $modifiers, Array(
'assetid' => $contexted_asset->id));
141 unset($contexted_asset);
142 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
150 if (
'asset_attribute_' == substr($keyword, 0, 16)) {
151 if ($keyword ==
'asset_attribute_duration_string') {
153 $replacement = self::convertTimeToString($this->
attr(
'duration'));
157 if (
'_int' == substr($keyword, -4)) {
158 $keyword = substr($keyword, 0, -4);
162 $replacement = parent::getKeywordReplacement($keyword);
164 if (is_numeric($replacement)) {
167 $replacement = (int)(round($replacement));
172 $replacement = nl2br(htmlspecialchars($replacement));
177 if ($replacement !== NULL) {
178 if (count($modifiers) > 0) {
179 apply_keyword_modifiers($replacement, $modifiers, Array(
'assetid' => $this->
id));
183 $replacement = parent::getKeywordReplacement($full_keyword);
207 $stored_metadata = Array(
208 'duration' => Array(
'attr_name' =>
'duration',
'default' => 0),
209 'width' => Array(
'attr_name' =>
'width',
'default' => 0),
210 'height' => Array(
'attr_name' =>
'height',
'default' => 0),
211 'framerate' => Array(
'attr_name' =>
'framerate',
'default' => 0),
212 'videodatarate' => Array(
'attr_name' =>
'videodatarate',
'default' => 0),
213 'videocodecid' => Array(
'attr_name' =>
'videocodecid',
'default' => 0),
214 'audiodatarate' => Array(
'attr_name' =>
'audiodatarate',
'default' => 0),
215 'audiocodecid' => Array(
'attr_name' =>
'audiocodecid',
'default' => 0),
216 'audiosamplerate' => Array(
'attr_name' =>
'audiosamplerate',
'default' => 0),
217 'audiosamplesize' => Array(
'attr_name' =>
'audiosamplesize',
'default' => 0),
221 if ($this->
attr(
'extract_metadata')) {
223 if ($metadata !== FALSE) {
225 foreach ($stored_metadata as $meta_name => $attr) {
226 if (array_key_exists($meta_name, $metadata)) {
227 $this->
setAttrValue($attr[
'attr_name'], $metadata[$meta_name]);
228 unset($metadata[$meta_name]);
230 $this->
setAttrValue($attr[
'attr_name'], $attr[
'default']);
241 return parent::saveAttributes($dont_run_updated);
259 if (!SQ_TOOL_GETID3_ENABLED || !is_file(SQ_TOOL_GETID3_PATH.
'/getid3.php')) {
263 require_once SQ_TOOL_GETID3_PATH.
'/getid3.php';
267 if (empty($file_info)) {
271 $getID3 =
new getID3();
272 $file_info = $getID3->analyze($file_info[
'path']);
276 if (isset($file_info[
'flv'][
'meta'][
'onMetaData'])) {
277 foreach ($file_info[
'flv'][
'meta'][
'onMetaData'] as $key => $value) {
278 $metadata[$key] = $value;
283 if (!array_key_exists(
'duration', $metadata) && isset($file_info[
'playtime_seconds'])) {
284 $metadata[
'duration'] = $file_info[
'playtime_seconds'];
288 if (!array_key_exists(
'width', $metadata) && isset($file_info[
'video'][
'resolution_x'])) {
289 $metadata[
'width'] = $file_info[
'video'][
'resolution_x'];
291 if (!array_key_exists(
'height', $metadata) && isset($file_info[
'video'][
'resolution_y'])) {
292 $metadata[
'height'] = $file_info[
'video'][
'resolution_y'];
296 if (!array_key_exists(
'framerate', $metadata) && isset($file_info[
'video'][
'frame_rate'])) {
297 $metadata[
'framerate'] = $file_info[
'video'][
'frame_rate'];
314 $minutes = floor($time / 60);
315 $seconds = floor($time % 60);
317 return $minutes.
':'.str_pad($seconds, 2,
'0', STR_PAD_LEFT);