getid3.module

Tracking 7.x-1.x branch
  1. drupal
    1. 7 contributions/getid3/getid3.module

Functions & methods

NameDescription
getid3_analyzeAnalyze file and return its media information.
getid3_get_pathReturns the path where getID3() is installed.
getid3_get_versionReturns the version number of getID3() that is installed.
getid3_helpImplements hook_help().
getid3_instanceCreate and initialize an instance of getID3 class.
getid3_loadLoad the getID3 library.
getid3_menuImplements hook_menu().

Constants

NameDescription
GETID3_RECOMMEND_VERSION

File

View source
  1. <?php
  2. define('GETID3_RECOMMEND_VERSION', '1.8.2');
  3. /**
  4. * Implements hook_help().
  5. */
  6. function getid3_help($section, $arg) {
  7. switch ($section) {
  8. case 'admin/config/media/getid3':
  9. $help = '<p>' . t("To use this module you'll need to <a href='!download-link'>download the library</a> from the <a href='!info-link'>getID3 website</a> and extract the contents into the module's getid3 directory. Currently, the recommended version of the getID3 library is %recommended-version.",
  10. array('!download-link' => url('http://prdownloads.sourceforge.net/getid3'), '!info-link' => url('http://getid3.org/'), '%recommended-version' => GETID3_RECOMMEND_VERSION)) . '</p>';
  11. return $help;
  12. }
  13. }
  14. /**
  15. * Implements hook_menu().
  16. */
  17. function getid3_menu() {
  18. $items['admin/config/media/getid3'] = array(
  19. 'title' => 'getID3()',
  20. 'description' => 'Configure settings associated with getID3().',
  21. 'page callback' => 'drupal_get_form',
  22. 'page arguments' => array('getid3_admin_settings_form', NULL),
  23. 'access arguments' => array('administer site configuration'),
  24. 'file' => 'getid3.admin.inc',
  25. );
  26. return $items;
  27. }
  28. /**
  29. * Load the getID3 library.
  30. *
  31. * @return
  32. * Boolean indicating if the library was successfully loaded.
  33. */
  34. function getid3_load($display_warning = TRUE) {
  35. $getid3_path = getid3_get_path();
  36. if (file_exists($getid3_path . '/getid3.php') && file_exists($getid3_path . '/write.php')) {
  37. // A little workaround for getID3 on Windows.
  38. if (!defined('GETID3_HELPERAPPSDIR')) {
  39. define('GETID3_HELPERAPPSDIR', realpath($getid3_path . '/../helperapps') . '/');
  40. }
  41. include_once($getid3_path . '/getid3.php');
  42. // Initialize getID3 tag-writing module. NOTE: Their wanky dependency setup
  43. // requires that this file must be included AFTER an instance of the getID3
  44. // class has been instantiated.
  45. $getid3 = new getID3;
  46. require_once($getid3_path . '/write.php');
  47. return method_exists($getid3, 'version') || defined('GETID3_VERSION');
  48. }
  49. else {
  50. drupal_set_message(t("The getid3() module cannot find the getID3 library used to read and write ID3 tags. The site administrator will need to verify that it is installed and then update the <a href='!admin-settings-audio-getid3'>settings</a>.", array('!admin-settings-audio-getid3' => url('admin/config/media/getid3'))), 'error', FALSE);
  51. return FALSE;
  52. }
  53. }
  54. /**
  55. * Create and initialize an instance of getID3 class.
  56. */
  57. function getid3_instance() {
  58. $id3 = NULL;
  59. if (getid3_load()) {
  60. $id3 = new getID3();
  61. // MD5 is a big performance hit. Disable it by default.
  62. $id3->option_md5_data = FALSE;
  63. $id3->option_md5_data_source = FALSE;
  64. $id3->encoding = 'UTF-8';
  65. }
  66. return $id3;
  67. }
  68. /**
  69. * Analyze file and return its media information.
  70. *
  71. * @param $filepath
  72. * A string specifying a file path.
  73. * @return
  74. * An array with the information returned by getID3.
  75. */
  76. function getid3_analyze($filepath) {
  77. $info = array();
  78. if ($id3 = getid3_instance()) {
  79. $info = $id3->analyze($filepath);
  80. unset($id3);
  81. }
  82. return $info;
  83. }
  84. /**
  85. * Returns the path where getID3() is installed.
  86. */
  87. function getid3_get_path() {
  88. return variable_get('getid3_path', 'sites/all/libraries/getid3/getid3');
  89. }
  90. /**
  91. * Returns the version number of getID3() that is installed.
  92. */
  93. function getid3_get_version() {
  94. if (getid3_load(FALSE)) {
  95. $getid3 = new getID3;
  96. // 1.9 and newer has a version method.
  97. if (method_exists($getid3, 'version')) {
  98. return $getid3->version();
  99. }
  100. // Older versions defined a constant.
  101. if (defined('GETID3_VERSION')) {
  102. return GETID3_VERSION;
  103. }
  104. }
  105. return NULL;
  106. }