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(
'mp3');
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)';
78 $keywords[
'asset_attribute_song_dynamic'] =
'Dynamic MP3 Keyword for Songs Name';
79 $keywords[
'asset_attribute_album_dynamic'] =
'Dynamic MP3 Keyword for Album';
80 $keywords[
'asset_attribute_artist_dynamic'] =
'Dynamic MP3 Keyword for Artist';
81 $keywords[
'asset_attribute_track_dynamic'] =
'Dynamic MP3 Keyword for Track';
82 $keywords[
'asset_attribute_bitrate_dynamic'] =
'Dynamic MP3 Keyword for Bit Rate';
83 $keywords[
'asset_attribute_length_dynamic'] =
'Dynamic MP3 Keyword for Length (in Minutes:Seconds)';
84 $keywords[
'asset_attribute_length_seconds_dynamic'] =
'Dynamic MP3 Keyword for Length (in Seconds)';
85 $keywords[
'asset_attribute_year_dynamic'] =
'Dynamic MP3 Keyword for Year';
86 $keywords[
'asset_attribute_genre_dynamic'] =
'Dynamic MP3 Keyword for Genre';
87 $keywords[
'asset_attribute_samplerate_dynamic'] =
'Dynamic MP3 Keyword for Sample Rate';
88 $keywords[
'asset_attribute_composer_dynamic'] =
'Dynamic MP3 Keyword for Composer';
89 $keywords[
'asset_attribute_copyright_dynamic'] =
'Dynamic MP3 Keyword for Copyright';
90 $keywords[
'asset_attribute_comments_dynamic'] =
'Dynamic MP3 Keyword for Comments';
91 $keywords[
'asset_attribute_lyrics_dynamic'] =
'Dynamic MP3 Keyword for Lyrics';
116 $full_keyword = $keyword;
117 $keyword = parse_keyword($keyword, $modifiers);
118 $contextid = extract_context_modifier($modifiers);
120 if ($contextid !== NULL) {
125 if ((
int)$contextid !== $GLOBALS[
'SQ_SYSTEM']->getContextId()) {
126 $GLOBALS[
'SQ_SYSTEM']->changeContext($contextid);
127 $contexted_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
id);
130 $replacement = $contexted_asset->getKeywordReplacement($keyword);
133 apply_keyword_modifiers($replacement, $modifiers, Array(
'assetid' => $contexted_asset->id));
135 unset($contexted_asset);
136 $GLOBALS[
'SQ_SYSTEM']->restoreContext();
146 case 'asset_attribute_length' :
148 $length = $this->
attr(
'length');
149 $minutes = floor($length / 60);
150 $seconds = $length % 60;
151 $replacement = $minutes.
':'.str_pad($seconds, 2,
'0', STR_PAD_LEFT);
154 case 'asset_attribute_length_seconds' :
156 $replacement = $this->
attr(
'length');
163 if (substr($keyword, -8) ===
'_dynamic') {
166 if ($tags === FALSE) $tags = Array();
169 $sub_keyword = substr($keyword, 16, -8);
170 switch ($sub_keyword) {
172 $replacement = array_get_index($tags,
'title',
'');
184 $replacement = array_get_index($tags, $sub_keyword,
'');
188 $bitrate = array_get_index($tags, $sub_keyword,
'');
189 if (is_numeric($bitrate)) {
192 $bitrate = floor($bitrate / 1000);
194 $replacement = $bitrate;
198 $replacement = array_get_index($tags,
'sample_rate',
'');
201 case 'length_seconds':
202 $length = array_get_index($tags,
'length',
'');
203 if (is_numeric($length)) {
205 $length = round($length);
207 $replacement = $length;
211 $length = array_get_index($tags,
'length',
'');
212 if (is_numeric($length)) {
214 $length = round($length);
217 $minutes = floor($length / 60);
218 $seconds = $length % 60;
219 $length = $minutes.
':'.str_pad($seconds, 2,
'0', STR_PAD_LEFT);
221 $replacement = $length;
228 if ($replacement !== NULL) {
229 if (count($modifiers) > 0) {
230 apply_keyword_modifiers($replacement, $modifiers, Array(
'assetid' => $this->
id));
234 $replacement = parent::getKeywordReplacement($full_keyword);
256 if ($this->
attr(
'extract_id3')) {
258 if ($tags !== FALSE) {
262 foreach ($tags as $tag_name => $tag_value) {
291 $this->
setAttrValue($tag_name, floor($tag_value / 1000));
312 if ($this->
attr(
'write_mp3') && SQ_TOOL_GETID3_ENABLED) {
320 $id3->setOption(array(
'encoding'=>$format));
323 require_once SQ_TOOL_GETID3_PATH.
'/write.php';
324 $tagwriter =
new getid3_writetags;
325 $tagwriter->filename = $file_path;
326 $tagwriter->tagformats = array(
'id3v1',
'id3v2.3');
329 $tagwriter->tag_encoding = $format;
332 $tag_data[
'title'][] = $this->
attr(
'song');
333 $tag_data[
'album'][] = $this->
attr(
'album');
334 $tag_data[
'artist'][] = $this->
attr(
'artist');
335 $tag_data[
'track'][] = $this->
attr(
'track');
336 $tag_data[
'year'][] = $this->
attr(
'year');
337 $tag_data[
'genre'][] = $this->
attr(
'genre');
338 $tag_data[
'composer'][] = $this->
attr(
'composer');
339 $tag_data[
'copyright'][] = $this->
attr(
'copyright');
340 $tag_data[
'comment'][] = $this->
attr(
'comments');
341 $tag_data[
'unsynchronised_lyrics'][] = $this->
attr(
'lyrics');
343 $tagwriter->tag_data = $tag_data;
346 if ($tagwriter->WriteTags()) {
347 if (!empty($tagwriter->warnings)) {
348 trigger_error(
'There were some ID3 warnings:<br />'.implode(
'<br /><br />', $tagwriter->warnings), E_USER_WARNING);
352 trigger_error(
'Failed to write ID3 tags:<br />'.implode(
'<br /><br />', $tagwriter->errors), E_USER_WARNING);
360 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');
399 if (!SQ_TOOL_GETID3_ENABLED)
return FALSE;
402 if (!is_dir(SQ_TOOL_GETID3_PATH)) {
403 trigger_error(
'Cannot extract ID3 metadata; path to getID3() external tool does not exist or is not a directory', E_USER_WARNING);
408 if (!is_file(SQ_TOOL_GETID3_PATH.
'/getid3.php')) {
409 trigger_error(
'Cannot extract ID3 metadata; path to getID3() external tool does not point to a valid getID3() install', E_USER_WARNING);
413 if (!is_file($file_name)) {
414 trigger_error(
'Cannot extract ID3 metadata; MP3 file path provided does not exist', E_USER_WARNING);
417 require_once SQ_TOOL_GETID3_PATH.
'/getid3.php';
421 $id3->Analyze($file_name);
423 if ($id3->info[
'fileformat'] !==
'mp3') {
424 trigger_error(
'Cannot extract ID3 metadata; File path passed is not an MP3 file', E_USER_WARNING);
470 'length' => $id3->info[
'playtime_seconds'],
471 'bitrate' => $id3->info[
'bitrate'],
472 'sample_rate' => $id3->info[
'audio'][
'sample_rate'],
473 'is_vbr' => ($id3->info[
'audio'][
'bitrate_mode'] ===
'vbr'),
474 'channels' => $id3->info[
'audio'][
'channels'],
477 $id3_tag_data = Array();
479 if (isset($id3->info[
'tags'][
'id3v2'])) {
480 $tag =& $id3->info[
'tags'][
'id3v2'];
483 foreach ($tag as $tag_index => $tag_value) {
484 if (is_array($tag_value)) {
485 $tag[$tag_index] = $tag_value[0];
489 if (isset($tag[
'content_type'])) {
490 $genres = getID3_ID3v2::ParseID3v2GenreString($tag[
'content_type']);
491 if (count($genres) > 0) {
492 $tag[
'genre'] = $genres[
'genre'][0];
496 if (isset($tag[
'track_number'])) {
497 $tag[
'track'] = $tag[
'track_number'];
499 }
else if (isset($id3->info[
'tags'][
'id3v1'])) {
500 $tag =& $id3->info[
'tags'][
'id3v1'];
503 foreach ($tag as $tag_index => $tag_value) {
504 if (is_array($tag_value)) {
505 $tag[$tag_index] = $tag_value[0];
511 if (isset($tag[
'title'])) {
512 $id3_tag_data[
'title'] = $tag[
'title'];
514 if (isset($tag[
'artist'])) {
515 $id3_tag_data[
'artist'] = $tag[
'artist'];
517 if (isset($tag[
'album'])) {
518 $id3_tag_data[
'album'] = $tag[
'album'];
520 if (isset($tag[
'track'])) {
521 $id3_tag_data[
'track'] = $tag[
'track'];
523 if (isset($tag[
'genre'])) {
524 $id3_tag_data[
'genre'] = $tag[
'genre'];
526 if (isset($tag[
'year'])) {
527 $id3_tag_data[
'year'] = $tag[
'year'];
529 if (isset($tag[
'composer'])) {
530 $id3_tag_data[
'composer'] = $tag[
'composer'];
532 if (isset($tag[
'copyright_message'])) {
533 $id3_tag_data[
'copyright'] = $tag[
'copyright_message'];
535 if (isset($tag[
'comments'])) {
536 $id3_tag_data[
'comments'] = $tag[
'comments'];
538 if (isset($tag[
'unsynchronised_lyric'])) {
539 $id3_tag_data[
'unsynchronised_lyric'] = $tag[
'unsynchronised_lyric'];
543 $data = array_merge($audio_data, $id3_tag_data);