\n";
}
// Clean out the rows from {video} that we have taken care of.
//db_query('DELETE FROM {video} WHERE n.vid IN (SELECT nid FROM {". $table ."})');
// 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);
// If you run the delete query on row ~83, the subquery here isn't needed...
$result = db_query("
SELECT v.vidfile, n.nid, n.vid, n.uid
FROM {video} v
INNER JOIN {node} n
ON n.nid = v.nid
WHERE v.nid NOT IN
(SELECT nid FROM {". $table ."})
AND v.vidfile LIKE '%%%s%%'", $base);
while ($row = db_fetch_object($result)) {
$filename = substr($row->vidfile, strlen($base));
$fid = db_next_id('files_fid');
$filepath = file_directory_path() .'/'. $filename;
if (file_exists($filepath)) {
$size = filesize($filepath);
}
else {
$size = 0;
echo "- Couldn't find $filepath!
\n";
}
db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)",
$fid,
$row->nid,
basename($filename),
$filepath,
getmime(substr($filename, -3)),
$size);
}
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 v.vidfile LIKE '%%%s%%'";
db_query($sql, $type_name, $base);
// Clear CCK cache.
$sql = "DELETE FROM {cache_content}";
db_query($sql);