The machine name of the provider. This must be the same as * the base name of this filename, before the .inc extension. * 'name' => The translated name of the provider. * 'url' => The url to the main page for the provider. * 'settings_description' => A description of the provider that will be * posted in the admin settings form. * 'supported_features' => An array of rows describing the state of certain * supported features by the provider. These will be rendered in a table, * with the columns being 'Feature', 'Supported', 'Notes'. In general, * the 'Feature' column will give the name of the feature, 'Supported' * will be Yes or No, and 'Notes' will give an optional description or * caveats to the feature. */ function emaudio_archive_audio_info() { $features = array( array(t('Thumbnails'), t('No'), ''), array(t('Autoplay'), t('Yes'), ''), array(t('RSS attachment'), t('No'), ''), ); return array( 'provider' => 'archive_audio', 'name' => t('Archive'), 'url' => EMAUDIO_ARCHIVE_MAIN_URL, 'settings_description' => t('These settings specifically affect audio played from !archive. You can also read more about its !api.', array('!archive' => l(t('Archive.com'), EMAUDIO_ARCHIVE_MAIN_URL), '!api' => l(t("developer's API"), EMAUDIO_ARCHIVE_API_URL))), 'supported_features' => $features, ); } /** * hook emaudio_PROVIDER_settings * This should return a subform to be added to the emaudio_settings() admin * settings page. * * Note that a form field set will already be provided at $form['archive'], * so if you want specific provider settings within that field set, you should * add the elements to that form array element. */ function emaudio_archive_audio_settings() { /* No Settings for this provider */ } /** * hook emaudio_PROVIDER_extract * * This is called to extract the audio code from a pasted URL or embed code. * * We'll be passed a URL or the embed code from a audio when an editor pastes * that in the field's textfield. We'll need to either pass back an array of * regex expressions to match, or do the matching ourselves and return the * resulting audio code. * * @param $parse * An optional string with the pasted URL or embed code. * @return * Either an array of regex expressions to be tested, or a string with the * audio code to be used. If the hook tests the code itself, it should * return either the string of the audio code (if matched), or an empty * array. Otherwise, the calling function will handle testing the embed code * against each regex string in the returned array. */ function emaudio_archive_audio_extract($parse = '') { // Here we assume that a URL will be passed in the form of // http://www.archive.org/details/text-audio-title // or embed code in the form of // $value) { $item_files[$key]['name'] = $key; } //Get playlist files only (.m3u files) $files_playlists = array_filter($item_files, "_archive_audio_isplaylist"); //If there is no playlist then fail if (is_null($files_playlists)) { form_set_error($error_field, 'This archive.org item does not appear to have a playlist.'); return $data; } //We'll custom sort the array so we'll get first VBR playlists, then other //playlists sorted by highest bitrate. Goal is to present the highest //bitrate playlist offered for this item. $data['playlists'] = $files_playlists; $worked = uasort($files_playlists, "_archive_audio_playlistsort"); $candidate_playlist = array_shift($files_playlists); $data['playlist_file_used'] = $candidate_playlist; //Retrieve the playlist $result = drupal_http_request('http://' . $server_url . $candidate_playlist['name']); if (!empty($result->error)) { form_set_error($error_field, 'The playlist for the item at archive.org could not be retrieved. The audio can not be displayed.'); return $data; } $playlist = $result->data; //We'll store it in the data element as it is used in our theme function to //output the player later. $data['playlist'] = explode("\n", trim($playlist)); return $data; } /** * Sort playlist files */ function _archive_audio_playlistsort($file1, $file2) { $components1 = explode(" ", $file1['format']); $components2 = explode(" ", $file2['format']); if ($components1[0] == $components2[0]) { return 0; } //We'll prefer the Variable Bitrate (VBR) elseif ($components1[0] == "VBR") { return -1; } elseif ($components2[0] == "VBR") { return 1; } //Otherwise we'll look for the highest bitrate playlist $br1 = (int)$components1[0]; $br2 = (int)$components2[0]; if ($br1 > $br2) { return -1; } else { return 1; } } /** * Is this file a playlist (.m3u) file? */ function _archive_audio_isplaylist($file) { if (substr($file['format'], -3, 3) == "M3U") { return TRUE; } else { return FALSE; } } /** * hook emfield_PROVIDER_rss */ function emaudio_archive_audio_rss($item, $teaser = NULL) { // Get size and mime type of first playlist file $url = $item['data']['playlist'][0]; $response = emfield_request_header('archive_audio', $url, $cached = FALSE); if ($response->code == 200) { $data['size'] = $response->headers['Content-Length']; $data['mime'] = $response->headers['Content-Type']; } if ($data['size']) { $file = array(); $file['filepath'] = $url; $file['filesize'] = $data['size']; $file['filemime'] = $data['mime']; } return $file; } /** * hook emaudio_PROVIDER_embedded_link($audio_code) * returns a link to view the audio at the provider's site. * @param $audio_code * The string containing the audio item. * @return * A string containing the URL the audio item at the original provider's site. */ function emaudio_archive_audio_embedded_link($audio_code) { return 'http://www.archive.org/details/'. $audio_code; } /** * Implementation of hook emaudio_archive_audio_audio(). * * This actually displays the full/normal-sized audio we want, usually on the default page view. * * @param $embed * The audio code for the audio to embed. * @param $width * The width to display the audio. * @param $height * The height to display the audio. * @param $field * The field info from the requesting node. * @param $item * The actual content from the field. * @return * The html of the embedded audio. */ function emaudio_archive_audio_audio($embed = NULL, $width = 0, $height = 0, $field = NULL, $item, $node, $autoplay) { $output = theme('emaudio_archive_audio_flash', $embed, $width, $height, $field, $item, $node, $autoplay); return $output; } /** * The embedded flash displaying the archive audio. */ function theme_emaudio_archive_audio_flash($embed, $width, $height, $field, $item, $node, $autoplay) { $output = ''; if ($item) { $flowplayerplaylist = _media_archive_flowplayer_playlist($item['data']['playlist']); $controlplaylist = (count($item['data']['playlist'])>1) ? "true" : "false"; $clipautoplay = $autoplay ? 'true' : 'false'; $output = << EOD; } return $output; } /** * Implementation of hook_emfield_subtheme(). */ function emaudio_archive_audio_emfield_subtheme() { return array( 'emaudio_archive_audio_flash' => array( 'arguments' => array('embed' => NULL, 'width' => NULL, 'height' => NULL, 'field' => NULL, 'data' => NULL, 'node' => NULL, 'autoplay' => NULL), 'file' => 'providers/emaudio/archive_audio.inc', 'path' => drupal_get_path('module', 'media_archive'), ) ); }