다음TV 인기동영상 추출 후 동영상보기 curl 예제 > 웹개발팁

웹개발팁

모아보자 [기타] 다음TV 인기동영상 추출 후 동영상보기 curl 예제 웹개발팁

[기타] 다음TV 인기동영상 추출 후 동영상보기 curl 예제

본문

본 예제는 https://entertain.daum.net/tv 에서

코드가 수정되면 본 코드도 수정해야합니다.

 
<style> 
.divs {text-align:center;margin-top:200px} 
.reveal {position:fixed;top:0;left:0;right:0;bottom:0;z-index: 99998;} 
.video-wrapper {width:100%;z-index:99999;} 
.video-wrapper_div2 {width:768px;margin:100px auto;} 
.video-wrapper_div {position:relative;height:0;padding-bottom:56.25%;} 
.video-wrapper iframe {border:0px;box-shadow: 30px 30px 50px rgba(0, 0, 0, 0.2);z-index:99999;} 
.reveal .video-popup-closer {position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0, 0, 0, 0.5);z-index:99998;} 
@media all and (max-width:768px){ 
.video-wrapper_div2 {width:100%;margin-top:30px;} 
} 
.tv-box {position:relative;display:block;width:100%;padding:10px 0;border-bottom:1px solid #ddd;} 
.tv-left {display:inline-block;width:110px;} 
.tv-left img{width:100%;height:60px;object-fit:cover;} 
.tv-right {position:absolute;left:175px;top:10px;display:block;color:#000 !important;font-size:1.2em;overflow:hidden;height:auto;line-height:24px;} 
.tv-rank {float:left;margin-right:1px;width:50px;line-height:60px;font-size:1.5em;color:#fff;background:#333;text-align:center;font-weight:bold;} 
</style> 
<?php 
$url = "https://entertain.daum.net/tv"; 
$User_Agent = 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31'; 
 
$request_headers = array(); 
$request_headers[] = 'User-Agent: '. $User_Agent; 
$request_headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'; 
$cookies = 'CookieName1=Value;CookieName2=Value'; 
$request_headers[] = 'Cookie: '. $cookies; 
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_HTTPHEADER, $request_headers); 
curl_setopt ($ch, CURLOPT_USERAGENT, $User_Agent); 
curl_setopt ($ch, CURLOPT_COOKIE, $cookies); 
$file_contents = curl_exec($ch); 
 
$tmp_daum = explode("<ul class=\"list_gallery\">",$file_contents); 
$tmp_daum = explode("<\/ul>",$tmp_daum[1]); 
$tv_daum = $tmp_daum[0]; 
 
$daum_tv = explode("data-tiara-layer=\"vod\">",$tv_daum); 
?> 
<?php 
for($i=1; $i<count($daum_tv); $i++) { 
 
preg_match_all("/video\/(.*)\"/iU",$daum_tv[$i],$match1); 
$tv_video = $match1[1][0]; 
 
preg_match_all("/<img src=\"(.*)\"/iU",$daum_tv[$i],$match2); 
$tv_img = $match2[1][0]; 
 
preg_match_all("/class=\"link_txt\">(.*)<\/a>/iU",$daum_tv[$i],$match3); 
$tv_tit = $match3[1][0]; 
 
preg_match_all("/재생횟수<\/span>(.*)<\/span>/iU",$daum_tv[$i],$match4); 
$tv_play = $match4[1][0]; 
 
preg_match_all("/<span class=\"txt_time\">(.*)<\/span>/iU",$daum_tv[$i],$match5); 
$tv_time = $match5[1][0]; 
?> 
<a data-video='<?php echo $tv_video; ?>' class='popyt mov_b2' style='cursor:pointer;'> 
<div class="tv-box"> 
<div class="tv-rank"><?php echo $i; ?></div> 
<div class="tv-left"><img src="<?php echo $tv_img; ?>"></div> 
<div class="tv-right"> 
<?php echo $tv_tit; ?> 
<br>재생시간 : <?php echo $tv_time; ?> | 재생횟수 : <?php echo $tv_play; ?> 
</div> 
</div> 
</a> 
<?php } ?> 
<div class="video-popup" id="video-popup-closer2"> 
<div class="video-popup-closer" id="video-popup-closer2"></div> 
</div> 
<script> 
$(".popyt").click(function() { 
$(".video-popup").addClass("reveal"), 
$(".video-popup .video-wrapper").remove(), 
$(".video-popup").append("<div class='video-wrapper'><div class='video-wrapper_div2'><div class='video-wrapper_div'><iframe src='https://play-tv.kakao.com/embed/player/cliplink/" + $(this).data("video") + "?service=kakao_tv' frameborder='0' style='position: absolute; width:100%; height:100%;'></iframe></div></div></div>") 
}) 
 
$(".video-popup-closer").click(function() { 
$(".video-popup .video-wrapper").remove(), 
$(".video-popup").removeClass("reveal") 
}); 
 
$("#video-popup-closer2").click(function() { 
$(".video-popup .video-wrapper").remove(), 
$(".video-popup").removeClass("reveal") 
}); 
</script> 

게시물 검색
상단으로 PC 버전으로 보기