$row->nid)); $file = db_fetch_array(db_query("SELECT * FROM {files} WHERE nid=%d limit 1", $node->nid)); $filepath = file_create_path($file['filepath']); $filename = basename($filepath); if (!$file['fid'] || !file_exists($filepath)) { $errors[] = $node; drupal_set_message( t('%node was NOT be upgraded because the file "%filepath" could not be found.', array('%node' => l($node->title, 'node/'. $node->nid), '%filepath' => theme('placeholder', $filepath))), 'error' ); } else { $audio = db_fetch_array(db_query("SELECT * FROM {audio_node_metadata} WHERE fid=%d", $file['fid'])); $id3 = audio_46to47_read_id3tags($filepath); $fileinfo = $id3['fileinfo']; var_dump($audio); var_dump($fileinfo); // audio files table db_query("INSERT INTO {audio_file} (vid, origname, filename, filepath, filemime, filesize) VALUES (%d, '%s', '%s', '%s', '%s', '%s')", $node->nid, $filename, $filename, $filepath, $file['filemime'], filesize($filepath)); // audio table db_queryd("INSERT INTO {audio} (nid, vid, title_format, play_count, downloadable, fileformat, sample_rate, channel_mode, bitrate, bitrate_mode, playtime) VALUES (%d, %d, '%s', %d, %d, '%s', %d, '%s', %f, '%s', '%s')", $node->nid, $node->vid, $node->title, $audio['playcount'], $audio['downloadable'], $fileinfo['fileformat'], $fileinfo['sample_rate'], $fileinfo['channel_mode'], $fileinfo['bitrate'], $fileinfo['bitrate_mode'], $fileinfo['playtime']); foreach(array('artist', 'title', 'album', 'year', 'track', 'genre', 'comment') as $tag) { db_query("INSERT INTO {audio_metadata} (vid, tag, value, clean) VALUES (%d, '%s', '%s', '%s')", $node->nid, $tag, $audio[$tag], audio_46to47_clean_tag($audio[$tag])); } drupal_set_message(t('%node was upgraded successfully.', array('%node' => l($node->title, 'node/'. $node->nid)))); } } if ($errors) { drupal_set_message(t('There were errors upgrading the audio module.'), 'error'); } else { drupal_set_message(t('The audio module was upgraded successfully. You can now remove the audio_node_metadata table.')); } } /** * Uses ID3 tags to get information about an audio file... * Returns one masive array (or false) if the file is not found. * * @param $filepath * string full path to audio file to examine * @return * array with two sub arrays keyed to 'tags' and 'fileinfo'. */ function audio_46to47_read_id3tags($filepath) { $getid3_path = variable_get('audio_getid3_path', drupal_get_path('module', 'audio') .'/getid3/getid3/'); require_once($getid3_path .'getid3.php'); $getID3 = new getID3; $getID3->encoding = 'UTF-8'; $getID3->encoding_id3v1 = 'ISO-8859-1'; $getID3->option_tags_html = FALSE; // Analyze file $info = $getID3->analyze($filepath); // Copies data from all subarrays of [tags] into [comments] so metadata is // all available in one location for all tag formats metainformation is // always available under [tags] even if this is not called. getid3_lib::CopyTagsToComments($info); // 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 .= '