http://drupal.org/node/201983#comment-828698)
* Moshe Weitzman (http://drupal.org/moshe)
* Sean Effel, code scavenger/bottomfeeder
*/
// ***** CONFIGURATION *******
// Set the base URL of your site including http://...
$base = 'http://www.mysite.com';
// Set the file field that you have already created and configured as per Prerequisites.
$field_name = 'field_file';
// Set the content type that you have already created as per Prerequisites.
$type_name = 'video2';
// ***** END CONFIGURATION *******
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Populate the field_video table for every video node.
$table = 'content_'. $field_name;
$fid = $field_name. '_fid';
$description = $field_name. '_description';
$list = $field_name. '_list';
$path = variable_get('vidfile', 'video');
$video_name = basename(str_replace("http://", "", $path));
// insert values into the filefield table from the video table
$sql = "INSERT INTO $table (vid, nid, '%d', '%s', '%d') SELECT n.vid, n.nid, f.fid, '%s', '1' FROM video WHERE n.nid = f.nid AND n.type = 'video' AND video.vidfile LIKE '%s' ";
if (db_query($sql, $fid, $description, $list, $video_name, $base)) {
Ê echo "- $table populated.
\n";
}
// Detect mimetype from each video file in the video module table
function getmime($video_ext = '') { switch ($video_ext) {
case 'mov':
return 'video/quicktime';
case 'avi' :
return 'video/x-msvideo';
case 'mpg' :
case 'mpeg' :
return 'video/mpeg';
case 'divx':
return 'video/vnd.divx';
case 'rm':
return 'application/vnd.rn-realmedia';
case 'flv':
return 'flv-application/octet-stream';
case 'asf':
return 'video/x-ms-asf';
case 'wmv':
return 'video/x-ms-wmv';
case '3gp':
return 'video/3gpp';
case 'mp4':
return 'video/mp4';
case 'dir':
case 'dcr':
return 'application/x-director';
case 'ogg':
return 'application/ogg';
default:
// No mimetype detected.
return '';
}
// Populate the files table since video.module doesn't even use it - Needs work
$route = str_replace( $base, "", $path );
$video_path = str_replace( $video_name, "", $route );
$video_size = variable_get('size', 'video');
$video_info = pathinfo($video_name);
$video_ext = $video_info['extension'];
$video_mimetype = getmime($video_ext);
// insert values into the files table from the video table
$sql = "INSERT INTO files ( fid, nid, filename, filepath, filemime, filesize ) SELECT f.fid, n.nid, '%s', '%s', '%s', '%d' FROM video WHERE n.nid = f.nid AND n.type = 'video' AND video.vidfile LIKE '%s' ";
if (db_query($sql, $video_name, $video_path, $video_mimetype, $video_size, $base)) {
Ê echo "- files table populated.
\n";
}
// Change the content type from 'video' to the configured type per Prerequisites.
$sql = "UPDATE node SET type = '%s' WHERE type = 'video' AND video.vidfile LIKE '%s'";
db_query($sql, $type_name, $base);
// Clear CCK cache.
$sql = "DELETE FROM cache_content";
db_query($sql);
}
?>