? .DS_Store ? filefield-480754-1.patch ? filefield-480754.patch ? filefield_meta/.DS_Store Index: filefield_meta/filefield_meta.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield_meta/filefield_meta.info,v retrieving revision 1.6 diff -u -p -r1.6 filefield_meta.info --- filefield_meta/filefield_meta.info 1 Apr 2009 08:57:49 -0000 1.6 +++ filefield_meta/filefield_meta.info 27 Jun 2009 09:19:32 -0000 @@ -6,3 +6,10 @@ dependencies[] = getid3 package = CCK core = 6.x php = 5.0 + +; Information added by drupal.org packaging script on 2009-06-07 +version = "6.x-3.x-dev" +core = "6.x" +project = "filefield" +datestamp = "1244333315" + Index: filefield_meta/filefield_meta.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield_meta/filefield_meta.install,v retrieving revision 1.8 diff -u -p -r1.8 filefield_meta.install --- filefield_meta/filefield_meta.install 22 May 2009 21:14:52 -0000 1.8 +++ filefield_meta/filefield_meta.install 27 Jun 2009 09:19:32 -0000 @@ -87,7 +87,42 @@ function filefield_meta_schema() { ), 'primary key' => array('fid'), ); - + $schema['filefield_meta_audio'] = array( + 'description' => t('Extended data about audio files.'), + 'fields' => array( + 'fid' => array( + 'description' => 'The file id.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'tag' => array( + 'type' => 'varchar', + 'length' => 45, + 'not null' => TRUE, + 'default' => '', + ), + 'value' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), + 'clean' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), + ), + //'primary key' => array('vid', 'tag', 'value'), + 'primary key' => array('fid', 'tag', 'value'), + 'indexes' => array( + 'filefield_meta_audio' => array('clean'), + ), + ); + return $schema; } @@ -129,4 +164,4 @@ function filefield_meta_update_1() { 'default' => '', )); return $ret; -} \ No newline at end of file +} Index: filefield_meta/filefield_meta.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield_meta/filefield_meta.module,v retrieving revision 1.14 diff -u -p -r1.14 filefield_meta.module --- filefield_meta/filefield_meta.module 20 Apr 2009 22:29:24 -0000 1.14 +++ filefield_meta/filefield_meta.module 27 Jun 2009 09:19:32 -0000 @@ -30,6 +30,11 @@ function filefield_meta_cron() { while ($file = db_fetch_object($result)) { db_query('DELETE FROM {filefield_meta} WHERE fid = %d', $file->fid); } + $result = db_query('SELECT fm.fid FROM {filefield_meta_audio} fm LEFT JOIN {files} f ON fm.fid=f.fid WHERE f.fid IS NULL'); + while ($file = db_fetch_object($result)) { + db_query('DELETE FROM {filefield_meta_audio} WHERE fid = %d', $file->fid); + } + } /** @@ -50,6 +55,17 @@ function filefield_meta_file_insert(&$fi filefield_meta($file); $record = array_merge(array('fid' => $file->fid), $file->data); drupal_write_record('filefield_meta', $record); + // Remove any existing metadata. + db_query("DELETE FROM {filefield_meta_audio} WHERE fid=%d", $file->fid); + + // Save the new tags. + $allowed_tags = audio_get_tags_allowed(); + foreach ($file->data['tags'] as $tag => $value) { + if (in_array($tag, $allowed_tags) && $value) { + $metadata = array('fid' => $file->fid, 'tag' => $tag, 'value' => $value, 'clean' => audio_clean_tag($value)); + drupal_write_record('filefield_meta_audio', $metadata); + } + } } } @@ -68,6 +84,7 @@ function filefield_meta_file_update(&$fi */ function filefield_meta_file_delete($file) { db_query('DELETE FROM {filefield_meta} WHERE fid = %d', $file->fid); + db_query('DELETE FROM {filefield_meta_audio} WHERE fid = %d', $file->fid); } /** @@ -103,8 +120,32 @@ function filefield_meta(&$file) { $file->data['audio_bitrate'] = isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : NULL; //e.g. 64000 $file->data['audio_bitrate_mode'] = isset($info['audio']['bitrate_mode']) ? $info['audio']['bitrate_mode'] : NULL; //e.g. cbr } + + // Read the id3v1 and then id3v2 + foreach (array('id3v1', 'id3v2') as $format ) { + if (isset($info['tags'][$format])) { + foreach ( (array) $info['tags'][$format] as $key => $value ) { + $ret['tags'][$key] = trim(array_pop($value)) ; + } + } + } + + $file->data['tags'] = $ret['tags'] ; + // warnings + if (!empty($info['warning']) && variable_get('audio_getid3_show_warnings', FALSE)) { + $warning = t('While reading the ID3 tags, the following warnings were encountered:'); + $warning .= ''; + drupal_set_message($warning, 'error'); + } + // report errors and then exit + if (isset($info['error'])) { + $error = t("The following errors where encountered while reading the file's ID3 tags: "); + $error .= ''; + form_set_error('', $error); + } }; + /** * Convert the float duration into a pretty string. * @@ -134,3 +175,62 @@ function theme_filefield_meta_samplerate function theme_filefield_meta_bitrate($bitrate) { return sprintf("%d Kbps", $bitrate/1000); } +/** + * Get an array of the allowed tags. + * + * @return + * Array of allowed tags. + */ +function audio_get_tags_allowed() { + return array_keys(audio_get_tag_settings()); +} + +/** + * Get an array of the tags and their settings. + * + * @return + * Array of allowed tags. + */ +function audio_get_tag_settings() { + $defaults = array( + 'artist' => array('autocomplete' => 1, 'required' => 1, 'hidden' => 0, + 'writetofile' => 1, 'browsable' => 1, 'weight' => -2), + 'title' => array('autocomplete' => 1, 'required' => 1, 'hidden' => 0, + 'writetofile' => 1, 'browsable' => 1, 'weight' => -2), + 'album' => array('autocomplete' => 1, 'required' => 0, 'hidden' => 0, + 'writetofile' => 1, 'browsable' => 1, 'weight' => -1), + 'track' => array('autocomplete' => 0, 'required' => 0, 'hidden' => 0, + 'writetofile' => 1, 'browsable' => 0, 'weight' => -1), + 'genre' => array('autocomplete' => 1, 'required' => 0, 'hidden' => 0, + 'writetofile' => 1, 'browsable' => 1, 'weight' => 0), + 'year' => array('autocomplete' => 0, 'required' => 0, 'hidden' => 0, + 'writetofile' => 1, 'browsable' => 1, 'weight' => 1), + ); + return variable_get('audio_tag_settings', $defaults); +} +/** + * Take a tag and force it to be a-z 0-9 _ - + * + * @param $string + * ID3 tag value + * @return + * cleaned up tag value for URL or database + */ +function audio_clean_tag($string) { + // If we've got characters besides 0-9 A-Z a-z hyphen and underscore, replace + // them. + if (preg_match('/[^-\w]/', $string)) { + // Remove accents... + $string = strtr($string, '������������������������������������������������������������', 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy'); + // ...convert to equivalent chars... + $string = strtr($string, array('�' => 'TH', '�' => 'th', '�' => 'DH', '�' => 'dh', '�' => 'ss', '�' => 'OE', '�' => 'oe', '�' => 'AE', '�' => 'ae', '�' => 'u')); + // ... and remove anything else that's not alphanumeric and replace it with an underscore. + $string = preg_replace('/[^-\w]+/', '_', $string); + } + // Remove leading and trailing underscores. + $string = trim($string, '_'); + // Finally, make it to lower case. + return strtolower($string); +} + +