for Worcester Community Cable Access http://wccatv.com/ Mike Benedetti is the current technical contact. You can reach WCCA at 508-755-1880 or 415 Main St., Worcester, MA 01608 Notes: Tested with Drupal 5.7, emfield 5.x-1.2, and cck 5.x-1.7 Due to a bug in emfield (or Drupal core?), item data isn't available in the preview Custom colors aren't available since archive.org doesn't support them Version 0.0: Initial version 07/26/2008 Version 0.1: Added support for non-derived mp4s 08/26/2008 Version 0.2: 11/07/1008 Changed method for finding "best" file to embed All archive.org data is now stored in $item["data"]["formats"] Version 0.2.1: 11/15/2005 Turned off "autoBuffering" */ define('VIDEO_CCK_ARCHIVE_MAIN_URL', 'http://www.archive.org/'); /* Regular expressions to match archive.org video URLs Currently supports the forms: http://www.archive.org/details/soapbox_615/ (with or without trailing slash) http://www.archive.org/details.php?identifier=soapbox_615 */ define('VIDEO_CCK_ARCHIVE_URL_REGEXP1','@archive\.org/details/([^"\&/]+)@i'); define('VIDEO_CCK_ARCHIVE_URL_REGEXP2','@archive\.org/details\.php\?identifier=([^"\&]+)@i'); define('VIDEO_CCK_ARCHIVE_URL_REGEXP3','@Replace this with something that will match other internet archive URLs@'); // Array Constants global $VIDEO_CCK_ARCHIVE_NON_VIDEO_FORMATS; $VIDEO_CCK_ARCHIVE_NON_VIDEO_FORMATS = array("Thumbnail","Metadata","Animated GIF"); /* Function to match preferred video format */ function video_cck_find_best_file($files_by_format) { if (!is_array($files_by_format)) return array(); // Use the 512Kb MPEG4 if it's available. It's H264 and will play in // Flash. if (array_key_exists("512Kb MPEG4",$files_by_format)) { return $files_by_format["512Kb MPEG4"][0]; // Use Flash Video if it's available } elseif (array_key_exists("Flash Video",$files_by_format)) { // Look for a derived flash first foreach ($files_by_format["Flash Video"] as $thisfile) { if ($thisfile["source"] == "derivative") return $thisfile; } // If there's none derived by archive.org, use the first flash video return $files_by_format["Flash Video"][0]; // Use 256Kb MPEG4 as a last resort. Not Flash compatible. } elseif (array_key_exists("256Kb MPEG4",$files_by_format)) { return $files_by_format["256Kb MPEG4"][0]; // Give up. Text list of files will be displayed. } else { return array(); } } function video_cck_archive_info() { $name = t('The Internet Archive'); $features = array( array(t('Autoplay'), t('Yes'), 'Starts playing the embedded video when the page loads'), array(t('RSS Attachment'), t('Yes'), ''), array(t('Show related videos'), t('No'), t('Not supported')), array(t('Thumbnails'), t('Yes'), t('Uses thumbnail from video embedding example')), array(t('Custom player colors'), t('No'), t('Not supported')), ); return array( 'provider' => 'archive', 'name' => $name, 'url' => VIDEO_CCK_ARCHIVE_MAIN_URL, 'settings_description' => t('Settings for videos from !archive.', array('!archive' => l($name, VIDEO_CCK_ARCHIVE_MAIN_URL, array('target' => '_blank')))), 'supported_features' => $features, ); } function video_cck_archive_settings() { return $form; } function video_cck_archive_data($field, $item) { global $VIDEO_CCK_ARCHIVE_NON_VIDEO_FORMATS; $data = array(); $id = $item['value']; $data['video_cck_archive_version'] = 0; // Grab the metadata // // It might be possible to use emfield_request_xml(), but there's a bug // in it that prevents it from working with pages with redirects $url = "http://www.archive.org/download/$id/${id}_files.xml"; $result = drupal_http_request($url); if (200 == $result->code || 200 == $result->redirect_code) { $parser = drupal_xml_parser_create($result->data); $vals = array(); $index = array(); xml_parse_into_struct($parser, $result->data, $vals, $index); xml_parser_free($parser); $data["formats"] = array(); for ($i = 0;$i < count($vals);$i++) { if ($vals[$i]["tag"] == "FILE" && $vals[$i]["type"] == "open") { $thisfile = array(); $filename = $thisfile["name"] = $vals[$i]["attributes"]["NAME"]; $thisfile["source"] = $vals[$i]["attributes"]["SOURCE"]; $level = $vals[$i]["level"]; for ($i++;!($vals[$i]["level"] == $level && $vals[$i]["tag"] == "FILE" && $vals[$i]["type"] == "close");$i++) { if (!($vals[$i]["tag"] == "FILE" && $vals[$i]["type"] == "cdata")) { if (!array_key_exists($vals[$i]["tag"], $thisfile)) { $thisfile[$vals[$i]["tag"]] = ""; } $thisfile[$vals[$i]["tag"]] .= $vals[$i]["value"]; } } $thisfile['url'] = "http://www.archive.org/download/$id/$filename"; if (!in_array($thisfile["FORMAT"],$VIDEO_CCK_ARCHIVE_NON_VIDEO_FORMATS)) { // The file size and type aren't included in the metadata, so we // need to request the file to find them $result = drupal_http_request($thisfile['url'],array(),"HEAD"); if (200 == $result->code || 200 == $result->redirect_code) { $thisfile['size'] = $result->headers["Content-Length"]; $thisfile['mime'] = $result->headers["Content-Type"]; } else { video_cck_archive_error(t("Could not find video size and type for !id on archive.org. The emfield Internet Archive module may need to be updated.",array('!id' => $id))); } } if (!array_key_exists($thisfile["FORMAT"],$data["formats"])) $data["formats"][$thisfile["FORMAT"]] = array(); $data["formats"][$thisfile["FORMAT"]][] = $thisfile; } } if (array_key_exists("Thumbnail",$data["formats"])) { if (count($data["formats"]["Thumbnail"]) >=3) $data['thumbnail']['url'] = $data["formats"]["Thumbnail"][2]["url"]; else $data['thumbnail']['url'] = $data["formats"]["Thumbnail"][count($data["formats"]["Thumbnail"])-1]["url"]; } // The title and description are in this file $url = "http://www.archive.org/download/$id/${id}_meta.xml"; $result = drupal_http_request($url); if (200 == $result->code || 200 == $result->redirect_code) { $parser = drupal_xml_parser_create($result->data); $vals = array(); $index = array(); xml_parse_into_struct($parser, $result->data, $vals, $index); xml_parser_free($parser); foreach ($vals as $val) { if ($val["tag"] == "TITLE" && $val["type"] == "complete") $data['archive_title'] = $val["value"]; if ($val["tag"] == "DESCRIPTION" && $val["type"] == "complete") $data['archive_description'] = $val["value"]; } } else { video_cck_archive_error(t("Could not load metadata meta XML for !id on archive.org. The emfield Internet Archive module may need to be updated.",array('!id' => $id))); } } else { video_cck_archive_error(t("Could not load metadata files XML for !id on archive.org. The emfield Internet Archive module may need to be updated.",array('!id' => $id))); } return $data; } function video_cck_archive_rss($item, $teaser = NULL) { $file = array(); if (is_array($item['data']['mp4'])) { $file['filepath'] = $item['data']['mp4']['url']; $file['filesize'] = $item['data']['mp4']['size']; $file['filemime'] = $item['data']['mp4']['mime']; } else { $bestfile = video_cck_find_best_file($item['data']['formats']); if (count($bestfile)>0) { $file['filepath'] = $bestfile['url']; $file['filesize'] = $bestfile['size']; $file['filemime'] = $bestfile['mime']; } } $file['thumbnail']['filepath'] = $data['thumbnail']['url']; return $file; } function video_cck_archive_extract($embed = '') { return array(VIDEO_CCK_ARCHIVE_URL_REGEXP1, VIDEO_CCK_ARCHIVE_URL_REGEXP2, VIDEO_CCK_ARCHIVE_URL_REGEXP3); } function video_cck_archive_embedded_link($video_code) { return 'http://www.archive.org/details/' . $video_code; } function video_cck_archive_thumbnail($field, $item, $formatter, $node, $width, $height) { return $item['data']['thumbnail']['url']; } // Dispatch to the appropriate embedded video code function video_cck_archive_video($embed, $width, $height, $field, $item, $autoplay) { if (array_key_exists("flv",$item['data'])) return theme('video_cck_archive_flash_legacy', $embed, $width, $height, $autoplay, $item); $bestfile = video_cck_find_best_file($item['data']['formats']); if (array_key_exists("FORMAT",$bestfile)) { if ($bestfile["FORMAT"] == "Flash Video") return theme('video_cck_archive_flash', $embed, $width, $height, $autoplay, $item, $bestfile); elseif ($bestfile["FORMAT"] == "512Kb MPEG4") return theme('video_cck_archive_mp4', $embed, $width, $height, $autoplay, $item, $bestfile); } return theme('video_cck_archive_allvids', $embed, $width, $height, $autoplay, $item); } function video_cck_archive_preview($embed, $width, $height, $field, $item, $autoplay) { return theme('video_cck_archive_video', $embed, $width, $height, $field , $item, $autoplay); } function theme_video_cck_archive_mp4($embed, $width, $height, $autoplay, $item, $bestfile) { global $base_url; if ($autoplay) { $autoplay = "true"; } else { $autoplay = "false"; } if (count($item['data']) > 1) { $link = $vid = $bestfile['url']; $size = floor($bestfile['size']/(1024*1024)); $title = $item['data']['archive_title']; $desc = $item['data']['archive_description']; if (isset($item['data']['emthumb']['filepath'])) { $thumb = "$base_url/".$item['data']['emthumb']['filepath']; } else { $thumb = $item['data']['thumbnail']['url']; } } else { $vid = ""; $size = "?"; $link = $base_url; $title = t('Not available in preview'); $desc = t('Not available in preview'); $thumb = ""; } return "
Download the mp4 video directly ($size MB) or see other formats.
"; } function theme_video_cck_archive_flash($embed, $width, $height, $autoplay, $item, $bestfile) { global $base_url; if ($autoplay) { $autoplay = "true"; } else { $autoplay = "false"; } if (count($item['data']) > 1) { $link = $vid = $bestfile['url']; $size = floor($bestfile['size']/(1024*1024)); $title = $item['data']['archive_title']; $desc = $item['data']['archive_description']; if (isset($item['data']['emthumb']['filepath'])) { $thumb = "$base_url/".$item['data']['emthumb']['filepath']; } else { $thumb = $item['data']['thumbnail']['url']; } } else { $vid = ""; $size = "?"; $link = $base_url; $title = t('Not available in preview'); $desc = t('Not available in preview'); $thumb = ""; } return "
Download the flash video directly ($size MB) or see other formats.
"; } // If we can't find a preferred video format, list all the formats function theme_video_cck_archive_allvids($embed, $width, $height, $autoplay, $item) { global $VIDEO_CCK_ARCHIVE_NON_VIDEO_FORMATS; $output = ""; return $output; } // Display flash video created before version we loaded data for every file function theme_video_cck_archive_flash_legacy($embed, $width, $height, $autoplay, $item) { global $base_url; if ($autoplay) { $autoplay = "true"; } else { $autoplay = "false"; } if (count($item['data']) > 1) { $vid = $item['data']['flv']['url']; $size = floor($item['data']['mp4']['size']/(1024*1024)); $link = $item['data']['mp4']['url']; $title = $item['data']['archive_title']; $desc = $item['data']['archive_description']; if (isset($item['data']['emthumb']['filepath'])) { $thumb = "$base_url/".$item['data']['emthumb']['filepath']; } else { $thumb = $item['data']['thumbnail']['url']; } } else { $vid = ""; $size = "?"; $link = $base_url; $title = t('Not available in preview'); $desc = t('Not available in preview'); $thumb = ""; } return "
Download the mp4 video ($size MB) or see other formats.
"; } // Display an error for the user and log an emfield error function video_cck_archive_error($text) { emfield_set_error($text); drupal_set_message(t("ERROR: ").$text); }