Jump to content

[Модуль] HTML5 видеоплеер + YouTube


Recommended Posts


1.В базу данных в таблицу vii_videos добавить поле:

yid tynint (1) unsigned

2.В system/modules/functions.php вставить функцию:

function getVideoUrl($id){
$formats = array(18,22,37,38,43,44,45);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.youtube.com/get_video_info?video_id=' . $id);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$links = curl_exec($ch);
curl_close($ch);
parse_str($links, $info);
if($info["status"] == 'fail'){
$video_array[] = '';
return;
}
$res = explode(',', $info['url_encoded_fmt_stream_map']);
foreach ($res as $k => $v){
parse_str($v, $rr);
if(in_array($rr['itag'], $formats)) $video_array[] = urldecode($rr['url']);
}
return $video_array;
}

function getRemoteFileSize($url){
   $parse = parse_url($url);
   $host = $parse['host'];
   $fp = @fsockopen ($host, 80, $errno, $errstr, 20);
   if(!$fp){
     $ret = 0;
   }else{
     $host = $parse['host'];
     fputs($fp, "HEAD ".$url." HTTP/1.1\r\n");
     fputs($fp, "HOST: ".$host."\r\n");
     fputs($fp, "Connection: close\r\n\r\n");
     $headers = "";
     while (!feof($fp)){
       $headers .= fgets ($fp, 128);
     }
     fclose ($fp);
     $headers = strtolower($headers);
     $array = preg_split("|[\s,]+|",$headers);
     $key = array_search('content-length:',$array);
     $ret = $array[$key+1];
   }
   if($array[1]==200) return $ret;
   else return -1*$array[1];
 }

2.В system/modules/video.php после $tpl->set('{vid}', $vid); вставить:

if($row['yid']){
if($check_link){
$row['video'] = '';
foreach($a as $key => $value){
$b = parse_url($value);
parse_str($b['query'], $c);
if($c['itag'] == 18) $row['video'] .= '<source src="'.$a[$key].'" type="video/mp4" label="Medium" res="360"/>';
elseif($c['itag'] == 22) $row['video'] .= '<source src="'.$a[$key].'" type="video/mp4" label="720p" res="720"/>';
elseif($c['itag'] == 37) $row['video'] .= '<source src="'.$a[$key].'" type="video/mp4" label="1080p" res="1080"/>';
elseif($c['itag'] == 38) $row['video'] .= '<source src="'.$a[$key].'" type="video/mp4" label="4K" res="1714"/>';
elseif($c['itag'] == 43) $row['video'] .= '<source src="'.$a[$key].'" type="video/webm" codecs="vorbis" label="WEBM 360p" res="360"/>';
elseif($c['itag'] == 44) $row['video'] .= '<source src="'.$a[$key].'" type="video/webm" codecs="vorbis" label="WEBM 480p" res="480"/>';
elseif($c['itag'] == 45) $row['video'] .= '<source src="'.$a[$key].'" type="video/webm" codecs="vorbis" label="WEBM 720p" res="720"/>';
}
} else $row['video'] = '<iframe type="ext/html" width="770" height="440" src="http://www.youtube.com/embed/'.$row['video'].'" frameborder="0"></iframe>';
} else $row['video'] = '<source src="'.$row['video'].'" type="video/mp4"/>';

if($check_link || !$row['yid']){
$row['video'] = '<link href="/vplayer/video-js.min.css" rel="stylesheet">
<link href="/vplayer/videojs-resolution-switcher.css" rel="stylesheet">
<video id="video_1" class="video-js vjs-default-skin" width="770" height="420" poster="'.$row['photo'].'" controls data-setup=\'{}\'>'.$row['video'].'</video>
<script src="/vplayer/video.js"></script>
<script src="/vplayer/videojs-resolution-switcher.js"></script>
<script>
videojs(\'#video_1\').videoJsResolutionSwitcher();
</script>';
}

3.В system/modules/video.php после $row = $db->super_query("SELECT tb1.video, вставить  yid,
4.После строки, которая написана выше вставить:

if($row['yid']){
$a = getVideoUrl($row['video']);
$aaa = getRemoteFileSize($a[0]);
if($aaa > 0) $check_link = true;
else $check_link = false;
}

5.В templates/Default/video/full.tpl заменить <div id="video_object">{video}</div> на: {video}
6.В templates/Default/js/profile.js заменить var pattern = new RegExp(/http:\/\/www.youtube.com|http:\/\/youtube.com|http:\/\/rutube.ru|http:\/\/www.rutube.ru|http:\/\/www.vimeo.com|http:\/\/vimeo.com|http:\/\/smotri.com|http:\/\/www.smotri.com/i); на:

var pattern = new RegExp(/https:\/\/www.youtube.com|http:\/\/youtube.com|http:\/\/www.youtube.com|http:\/\/youtube.com/i);

7.В system/modules/videos.php заменить от case "send": до break; на:

case 'send':
NoAjaxQuery();
if($config['video_mod_add'] == 'yes'){
$good_video_lnk = ajax_utf8(textFilter($_POST['good_video_lnk']));
$good_video_lnk = str_replace("https", "http", $good_video_lnk);
$title = ajax_utf8(textFilter($_POST['title'], false, true));
$descr = ajax_utf8(textFilter($_POST['descr'], 3000));
$privacy = intval($_POST['privacy']);
if($privacy <= 0 OR $privacy > 3) $privacy = 1;
$youtube_id = 0;
if(preg_match("/src=\"http:\/\/www.youtube.com|src=\"http:\/\/youtube.com/i", 'src="'.$good_video_lnk)){
$good_video_lnk = str_replace(array('#', '!'), '', $good_video_lnk);
$exp_y = explode('v=', $good_video_lnk);
$exp_x = explode('&', $exp_y[1]);
$result_video_lnk = $exp_x[0];
$youtube_id = 1;
}
$photo = $db->safesql(ajax_utf8(htmlspecialchars(trim($_POST['photo']))));
$photo = str_replace("\\", "/", $photo);
$img_name_arr = explode(".", $photo);
$img_format = totranslit(end($img_name_arr));
$image_name = substr(md5(time().md5($good_video_lnk)), 0, 15);
$allowed_files = array('jpg', 'jpeg', 'jpe', 'png', 'gif');
if(in_array(strtolower($img_format), $allowed_files) && preg_match("/http:\/\//i", $photo) && $result_video_lnk){
$upload_dir = ROOT_DIR.'/uploads/videos/'.$user_id;
if(!is_dir($upload_dir)){ 
@mkdir($upload_dir, 0777);
@chmod($upload_dir, 0777);
}
include ENGINE_DIR.'/classes/images.php';
@copy($photo, $upload_dir.'/'.$image_name.'.'.$img_format);
$tmb = new thumbnail($upload_dir.'/'.$image_name.'.'.$img_format);
$tmb->size_auto('175x131');
$tmb->jpeg_quality(100);
$tmb->save($upload_dir.'/'.$image_name.'.'.$img_format);
}
				
if($result_video_lnk AND $title){
$photo = $config['home_url'].'uploads/videos/'.$user_id.'/'.$image_name.'.'.$img_format;
$db->query("INSERT INTO `".PREFIX."_videos` SET yid = '{$youtube_id}', owner_user_id = '{$user_id}', video = '{$result_video_lnk}', photo = '{$photo}', title = '{$title}', descr = '{$descr}', add_date = NOW(), privacy = '{$privacy}'");
$dbid = $db->insert_id();
$db->query("UPDATE `".PREFIX."_users` SET user_videos_num = user_videos_num+1 WHERE user_id = '{$user_id}'");
$photo = str_replace($config['home_url'], '/', $photo);
$generateLastTime = $server_time-10800;
$row = $db->super_query("SELECT ac_id, action_text FROM `".PREFIX."_news` WHERE action_time > '{$generateLastTime}' AND action_type = 2 AND ac_user_id = '{$user_id}'");
if($row) $db->query("UPDATE `".PREFIX."_news` SET action_text = '{$dbid}|{$photo}||{$row['action_text']}', action_time = '{$server_time}' WHERE ac_id = '{$row['ac_id']}'");
else $db->query("INSERT INTO `".PREFIX."_news` SET ac_user_id = '{$user_id}', action_type = 2, action_text = '{$dbid}|{$photo}', action_time = '{$server_time}'");
mozg_mass_clear_cache_file("user_{$user_id}/page_videos_user|user_{$user_id}/page_videos_user_friends|user_{$user_id}/page_videos_user_all|user_{$user_id}/profile_{$user_id}|user_{$user_id}/videos_num_all|user_{$user_id}/videos_num_friends");
if($_POST['notes'] == 1) echo "{$photo}|{$user_id}|{$dbid}";
}
} else echo 'error';
die();
break;

8.В system/modules/videos.php заменить от case "load": до break; на:

case 'load':
NoAjaxQuery();
$video_lnk = $_POST['video_lnk'];
$video_lnk = str_replace("https", "http", $video_lnk);
if(preg_match("/http:\/\/www.youtube.com|http:\/\/youtube.com/i", $video_lnk)){
if(preg_match("/http:\/\/www.youtube.com|http:\/\/youtube.com/i", $video_lnk)){
$exp_y = explode('v=', $video_lnk);
$exp_x = explode('&', $exp_y[1]);
$sock = fopen('http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v='.$exp_x[0].'&format=xml', 'r');
} else $sock = fopen($video_lnk, 'r');
if(!$sock) echo 'no_serviece';
else {
$html = '';
if(preg_match("/http:\/\/www.youtube.com|http:\/\/youtube.com/i", $video_lnk)){
while(!feof($sock)) $html .= fgets($sock);
}
fclose($sock);
$data = str_replace(array('[', ']'), array('&iqu;', '&iqu2;'), $html);
$data_all = ajax_utf8(str_replace(array('[', ']'), array('&iqu;', '&iqu2;'), $html));
if(preg_match("/http:\/\/www.youtube.com|http:\/\/youtube.com/i", $video_lnk)){
preg_match_all('`(<title>[^\[]+\</title>)`si', $data_all, $parse);
$res_title = rn_replace(str_replace(array('<title>', '</title>'), '', $parse[1][0]));
$parse_start = explode('v=', $video_lnk);
$parse_end = explode('&', $parse_start[1]);
$res_img = "http://img.youtube.com/vi/{$parse_end[0]}/0.jpg";
}
					
$result_img = $res_img;
$result_title = trim(strip_tags(strtr($res_title, array('&#39;' => "'", '&quot;' => '"', '&iqu;' => '[', '&iqu2;' => ']'))));
$result_descr = trim(strip_tags($res_descr));
					
if($result_img && $result_title) echo "{$result_img}:|:{$result_title}:|:{$result_descr}";
else echo 'no_serviece';
}
} else echo 'no_serviece';
die();
break;


9.В system/modules/videos.php заменить от case "addmylist": до break; на:

case "addmylist":
			NoAjaxQuery();
			$vid = intval($_POST['vid']);
			$row = $db->super_query("SELECT video, photo, title, descr, yid FROM `".PREFIX."_videos` WHERE id = '{$vid}'");
			if($row AND $config['video_mod_add_my'] == 'yes'){
				//Директория загрузки фото
				$upload_dir = ROOT_DIR.'/uploads/videos/'.$user_id;
						
				//Если нет папки юзера, то создаём её
				if(!is_dir($upload_dir)){ 
					@mkdir($upload_dir, 0777);
					@chmod($upload_dir, 0777);
				}
				
				$expPhoto = end(explode('/', $row['photo']));
				@copy($row['photo'], ROOT_DIR."/uploads/videos/{$user_id}/{$expPhoto}");
				$newPhoto = "{$config['home_url']}uploads/videos/{$user_id}/{$expPhoto}";
				$row['video'] = $db->safesql($row['video']);
				$row['descr'] = $db->safesql($row['descr']);
				$row['title'] = $db->safesql($row['title']);
				$db->query("INSERT INTO `".PREFIX."_videos` SET yid = '{$row['yid']}',owner_user_id = '{$user_id}', video = '{$row['video']}', photo = '{$newPhoto}', title = '{$row['title']}', descr = '{$row['descr']}', add_date = NOW(), privacy = 1");
				$dbid = $db->insert_id();
				$db->query("UPDATE `".PREFIX."_users` SET user_videos_num = user_videos_num+1 WHERE user_id = '{$user_id}'");

				//Чистим кеш
				mozg_mass_clear_cache_file("user_{$user_id}/page_videos_user|user_{$user_id}/page_videos_user_friends|user_{$user_id}/page_videos_user_all|user_{$user_id}/profile_{$user_id}|user_{$user_id}/videos_num_all|user_{$user_id}/videos_num_friends");
			}
			die();
		break;
        
10.Залить в корень сайта папку vplayer

 

HTML5 видеоплеер + YouTube.rar

  • Upvote 1
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...
  • 9 months later...

Проверил,  все работает , только строчку 

http:\/\/www.youtube.com|src=\"http:\/\/youtube.com/i

надо заменить на 

https:\/\/www.youtube.com|src=\"https:\/\/youtube.com/i

Тогда будет точно работать 

Еще совет , все http:// надо на https:// заменить 

Link to comment
Share on other sites

  • 4 weeks later...
В 07.06.2019 в 12:45, Aquarius сказал:

Проверил,  все работает , только строчку 

http:\/\/www.youtube.com|src=\"http:\/\/youtube.com/i

надо заменить на 

https:\/\/www.youtube.com|src=\"https:\/\/youtube.com/i

Тогда будет точно работать 

Еще совет , все http:// надо на https:// заменить 

 

В 07.06.2019 в 12:45, Aquarius сказал:

Проверил,  все работает , только строчку 

http:\/\/www.youtube.com|src=\"http:\/\/youtube.com/i

надо заменить на 

https:\/\/www.youtube.com|src=\"https:\/\/youtube.com/i

Тогда будет точно работать 

Еще совет , все http:// надо на https:// заменить 

Ютуб поменяй с http на https, что бы ssl работал

 

Link to comment
Share on other sites

  • 2 months later...
В 03.07.2019 в 23:29, Aquarius сказал:

 

Ютуб поменяй с http на https, что бы ssl работал

 

Ну вообще это не совсем верное решение и не будет работать с http ссылками, верное что то вроде

http(?:s)?:\/\/www.youtube.com|src=\"http(?:s)?:\/\/youtube.com/i

 

Такой RegExp будет работать с HTTP/HTTPS

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...