You are here

getid3.module in getID3() 8

Same filename and directory in other branches
  1. 5 getid3.module
  2. 6 getid3.module
  3. 7.2 getid3.module
  4. 7 getid3.module

File

getid3.module
View source
<?php

use Drupal\Core\Url;
define('GETID3_RECOMMENDED_VERSION', '1.9.9');

/**
 * Implements hook_help().
 */
function getid3_help($route_name) {
  switch ($route_name) {
    case 'help.page.getid3':

      //case 'admin/help#getid3':
      return '<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.", array(
        '!download-link' => Url::fromUri('http://prdownloads.sourceforge.net/getid3'),
        '!info-link' => Url::fromUri('http://getid3.org/'),
        '%recommended-version' => GETID3_RECOMMENDED_VERSION,
      )) . '</p>';
  }
}

/**
 * Load the getID3 library.
 *
 * @return
 *   Boolean indicating if the library was successfully loaded.
 */
function getid3_load($display_warning = TRUE) {
  $getid3_path = getid3_get_path();
  if (file_exists($getid3_path . '/getid3.php') && file_exists($getid3_path . '/write.php')) {

    // A little workaround for getID3 on Windows.
    if (!defined('GETID3_HELPERAPPSDIR')) {
      define('GETID3_HELPERAPPSDIR', realpath($getid3_path . '/../helperapps') . '/');
    }
    include_once $getid3_path . '/getid3.php';

    // Initialize getID3 tag-writing module. NOTE: Their wanky dependency setup
    // requires that this file must be included AFTER an instance of the getID3
    // class has been instantiated.
    $getid3 = new getID3();
    require_once $getid3_path . '/write.php';
    return method_exists($getid3, 'version') || defined('GETID3_VERSION');
  }
  return FALSE;
}

/**
 * Create and initialize an instance of getID3 class.
 */
function getid3_instance() {
  $id3 = NULL;
  $id3_lib_available = getid3_load();
  if ($id3_lib_available == FALSE) {
    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::fromRoute('getid3.config'),
    )), 'error', FALSE);
    return $id3;
  }
  $id3 = new getID3();

  // MD5 is a big performance hit. Disable it by default.
  $id3->option_md5_data = FALSE;
  $id3->option_md5_data_source = FALSE;
  $id3->encoding = 'UTF-8';
  return $id3;
}

/**
 * Analyze file and return its media information.
 *
 * @param $filepath
 *   A string specifying a file path.
 * @return
 *   An array with the information returned by getID3.
 */
function getid3_analyze($filepath) {
  $info = array();
  if ($id3 = getid3_instance()) {
    $info = $id3
      ->analyze($filepath);
    unset($id3);
  }
  return $info;
}

/**
 * Returns the path where getID3() is installed.
 */
function getid3_get_path() {
  $config = \Drupal::config('getid3.settings');
  $path = $config
    ->get('path');
  if (empty($path) || strlen($path) < 1) {
    $path = 'libraries/getid3/getid3';
    $config
      ->set('path', $path)
      ->save();
  }
  return $path;
}

/**
 * Returns the version number of getID3() that is installed.
 */
function getid3_get_version() {
  if (getid3_load() == FALSE) {
    return NULL;
  }
  $getid3 = new getID3();

  // 1.9 and newer has a version method.
  if (method_exists($getid3, 'version')) {
    return $getid3
      ->version();
  }

  // Older versions defined a constant.
  if (defined('GETID3_VERSION')) {
    return GETID3_VERSION;
  }
  return NULL;
}

Functions

Namesort descending Description
getid3_analyze Analyze file and return its media information.
getid3_get_path Returns the path where getID3() is installed.
getid3_get_version Returns the version number of getID3() that is installed.
getid3_help Implements hook_help().
getid3_instance Create and initialize an instance of getID3 class.
getid3_load Load the getID3 library.

Constants