/[drupal]/contributions/modules/audio/audio_getid3.module
ViewVC logotype

Diff of /contributions/modules/audio/audio_getid3.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.35 by drewish, Wed May 14 03:41:57 2008 UTC revision 1.36 by drewish, Sun May 25 17:21:26 2008 UTC
# Line 8  define('AUDIO_GETID3_RECOMMEND_VERSION', Line 8  define('AUDIO_GETID3_RECOMMEND_VERSION',
8  /**  /**
9   * Implementation of hook_help   * Implementation of hook_help
10   */   */
11  function audio_getid3_help($section) {  function audio_getid3_help($section, $arg) {
12    switch ($section) {    switch ($section) {
13      case 'admin/help#audio_getid3':      case 'admin/help#audio_getid3':
14        $help  = '<p>'. t('The Audio getID3 module enhances the audio module to read metadata from and write to audio files. The module uses the <a href="!elink-www-getid3-org">getID3 library</a> to read and write <a href="!elink-en-wikipedia-org">ID3 tags</a> from the audio file. getID3 can read metadata from a many different audio and video formats giving the audio module a great deal of flexibility.',        $help  = '<p>'. t('The Audio getID3 module enhances the audio module to read metadata from and write to audio files. The module uses the <a href="!elink-www-getid3-org">getID3 library</a> to read and write <a href="!elink-en-wikipedia-org">ID3 tags</a> from the audio file. getID3 can read metadata from a many different audio and video formats giving the audio module a great deal of flexibility.',
# Line 18  function audio_getid3_help($section) { Line 18  function audio_getid3_help($section) {
18           <ul>           <ul>
19              <li>Download and install the <em>required</em> getID3 library from <a href="!elink-prdownloads-sourceforge-net">getID3 sourceforge</a> page. Currently, the recommended version of the getID3 library is %recommended-version.</li>              <li>Download and install the <em>required</em> getID3 library from <a href="!elink-prdownloads-sourceforge-net">getID3 sourceforge</a> page. Currently, the recommended version of the getID3 library is %recommended-version.</li>
20              <li>Administer the Audio getID3 module at <a href="!admin-settings-audio-getid3">administer &gt;&gt; site configuration &gt;&gt; audio &gt;&gt; getid3</a>.</li>              <li>Administer the Audio getID3 module at <a href="!admin-settings-audio-getid3">administer &gt;&gt; site configuration &gt;&gt; audio &gt;&gt; getid3</a>.</li>
21           </ul>',           </ul>', array('!admin-settings-audio-getid3' => url('admin/settings/audio/getid3'), '!elink-prdownloads-sourceforge-net' => 'http://prdownloads.sourceforge.net/getid3', '%recommended-version' => AUDIO_GETID3_RECOMMEND_VERSION));
          array('!admin-settings-audio-getid3' => url('admin/settings/audio/getid3'), '!elink-prdownloads-sourceforge-net' => 'http://prdownloads.sourceforge.net/getid3', '%recommended-version' => AUDIO_GETID3_RECOMMEND_VERSION));  
22        $help .= '<p>'. t('For more information please read the configuration and customization handbook <a href="!audio">Audio page</a>.',        $help .= '<p>'. t('For more information please read the configuration and customization handbook <a href="!audio">Audio page</a>.',
23          array('!audio' => 'http://www.drupal.org/handbook/modules/audio/')) .'</p>';          array('!audio' => 'http://www.drupal.org/handbook/modules/audio/')) .'</p>';
24        return $help;        return $help;
# Line 31  function audio_getid3_help($section) { Line 30  function audio_getid3_help($section) {
30    }    }
31  }  }
32    
33  function audio_getid3_menu($may_cache) {  function audio_getid3_menu() {
34    $items = array();    $items = array();
35    if ($may_cache) {    $items['admin/settings/audio/getid3'] = array(
36      $items[] = array('path' => 'admin/settings/audio/getid3',      'title' => 'getID3',
37        'title' => t('getID3'),      'page callback' => 'drupal_get_form',
38        'callback' => 'drupal_get_form',      'page arguments' => array('audio_getid3_admin_settings'),
39        'callback arguments' => array('audio_getid3_admin_settings'),      'access arguments' => array('administer site configuration'),
40        'access' => user_access('administer site configuration'),      'type' => MENU_LOCAL_TASK,
41        'type' => MENU_LOCAL_TASK);    );
   }  
42    return $items;    return $items;
43  }  }
44    
# Line 83  function audio_getid3_admin_settings() { Line 81  function audio_getid3_admin_settings() {
81      '#title' => t('Path'),      '#title' => t('Path'),
82      '#default_value' => variable_get('audio_getid3_path', drupal_get_path('module', 'audio') .'/getid3/getid3'),      '#default_value' => variable_get('audio_getid3_path', drupal_get_path('module', 'audio') .'/getid3/getid3'),
83      '#description' => t("The path to the getID3 library. For example: 'modules/audio/getid3/getid3' or 'sites/default/modules/audio/getid3'"),      '#description' => t("The path to the getID3 library. For example: 'modules/audio/getid3/getid3' or 'sites/default/modules/audio/getid3'"),
84      '#after_build'=> array('_audio_getid3_settings_check_path'),      '#after_build' => array('_audio_getid3_settings_check_path'),
85    );    );
86    
87    if (audio_getid3_isfound()) {    if (audio_getid3_isfound()) {
# Line 118  function audio_getid3_admin_settings() { Line 116  function audio_getid3_admin_settings() {
116  /**  /**
117   * Edit the audio node form and insert our file info stuff.   * Edit the audio node form and insert our file info stuff.
118   */   */
119  function audio_getid3_form_alter($form_id, &$form) {  function audio_getid3_form_alter(&$form, &$form_state, $form_id) {
120    // We only alter audio node edit forms    // We only alter audio node edit forms
121    if ($form_id == 'audio_node_form' && isset($form['#node']->audio_file)) {    if ($form_id == 'audio_node_form' && isset($form['#node']->audio_file)) {
122      $node = $form['#node'];      $node = $form['#node'];
# Line 250  function _audio_getid3_load() { Line 248  function _audio_getid3_load() {
248    define('GETID3_HELPERAPPSDIR', realpath($path .'/../helperapps') .'/');    define('GETID3_HELPERAPPSDIR', realpath($path .'/../helperapps') .'/');
249    
250    require_once($path .'/getid3.php');    require_once($path .'/getid3.php');
251    $getID3 = new getID3;    $getid3 = new getID3;
252    $getID3->encoding         = 'UTF-8';    $getid3->encoding         = 'UTF-8';
253    $getID3->encoding_id3v1   = 'ISO-8859-1';    $getid3->encoding_id3v1   = 'ISO-8859-1';
254    $getID3->option_tags_html = FALSE;    $getid3->option_tags_html = FALSE;
255    
256    // Initialize getID3 tag-writing module. NOTE: Their wanky dependency setup    // Initialize getID3 tag-writing module. NOTE: Their wanky dependency setup
257    // requires that this file must be included AFTER an instance of the getID3    // requires that this file must be included AFTER an instance of the getID3
258    // class has been instantiated.    // class has been instantiated.
259    require_once($path .'/write.php');    require_once($path .'/write.php');
260    
261    return $getID3;    return $getid3;
262  }  }
263    
264  /**  /**
# Line 276  function _audio_getid3_load() { Line 274  function _audio_getid3_load() {
274   *   there's an error.   *   there's an error.
275   */   */
276  function audio_read_id3tags($filepath, $load_pics = FALSE) {  function audio_read_id3tags($filepath, $load_pics = FALSE) {
277    $getID3 = _audio_getid3_load();    $getid3 = _audio_getid3_load();
278    if (!$getID3) {    if (!$getid3) {
279      // getid3 isn't setup correctly. an error should have already been printed      // getid3 isn't setup correctly. an error should have already been printed
280      // so just return.      // so just return.
281      return FALSE;      return FALSE;
282    }    }
283    
284    // Analyze file    // Analyze file
285    $info = $getID3->analyze($filepath);    $info = $getid3->analyze($filepath);
286    
287    // copy out the basic file info    // copy out the basic file info
288    $ret = array(    $ret = array(
# Line 306  function audio_read_id3tags($filepath, $ Line 304  function audio_read_id3tags($filepath, $
304    foreach (array('id3v1', 'id3v2') as $format) {    foreach (array('id3v1', 'id3v2') as $format) {
305      if (isset($info['tags'][$format])) {      if (isset($info['tags'][$format])) {
306        foreach ((array) $info['tags'][$format] as $key => $value ) {        foreach ((array) $info['tags'][$format] as $key => $value ) {
307          $ret['tags'][$key] = array_pop(str_replace("\0", '', $value));          $ret['tags'][$key] = array_pop($value);
308        }        }
309      }      }
310    }    }
# Line 363  function audio_read_id3tags($filepath, $ Line 361  function audio_read_id3tags($filepath, $
361   *   FALSE on error.   *   FALSE on error.
362   */   */
363  function audio_write_id3tags($filepath, $tags, $images = array(), $tagformats = array('id3v1', 'id3v2.3')) {  function audio_write_id3tags($filepath, $tags, $images = array(), $tagformats = array('id3v1', 'id3v2.3')) {
364    $getID3 = _audio_getid3_load();    $getid3 = _audio_getid3_load();
365    if (!$getID3) {    if (!$getid3) {
366      // getid3 isn't setup correctly. an error should have already been printed      // getid3 isn't setup correctly. an error should have already been printed
367      // so just return.      // so just return.
368      return FALSE;      return FALSE;
# Line 430  function _audio_getid3_save_to_file(&$no Line 428  function _audio_getid3_save_to_file(&$no
428    $tags = array();    $tags = array();
429    foreach ($node->audio_tags as $tag => $value) {    foreach ($node->audio_tags as $tag => $value) {
430      if ($settings[$tag]['writetofile']) {      if ($settings[$tag]['writetofile']) {
431        // try and remove weird null characters generated by getid3. see issue # 186801        $tags[$tag] = $value;
       $tags[$tag] = str_replace("\0", '', $value);  
432      }      }
433    }    }
434    

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.36

  ViewVC Help
Powered by ViewVC 1.1.3