유튜브 영상길이 추출하는 법

유튜브 영상길이 추출하는 법

QA

유튜브 영상길이 추출하는 법

본문

특정 유튜브영상의 영상길이를 추출하고싶습니다

 

PHP에서는 https://www.youtube.com/get_video_info 통해서 추출하는 방법들이 구글링을 통해 알아봤었는데요

문제는 이 https://www.youtube.com/get_video_info 링크가 죽었네요..

 

스크립트로라도 좋고... PHP여도 좋으니 특정영상의 영상길이를 구하는 방법이 있을까요?

 

 

이 질문에 댓글 쓰기 :

답변 3

https://developers.google.com/youtube/iframe_api_reference?hl=ko 를 활용해 불러온 동영상의 경우

 

동영상 길이나 정보, 제목 등을 가져올 수 있습니다
 

https://developers.google.com/youtube/v3/docs/videos/list?hl=ko

또는 youtueb data api v3를 활용하여 가져올 수도 있습니다

 


$url = "https://www.googleapis.com/youtube/v3/videos?key=키값&part=contentDetails&id=유튜브영상ID;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
$result = json_decode($content);
$ytime = $result->items[0]->contentDetails->duration;
$ytime = str_replace("PT","",$ytime);
$ytime = str_replace("M","분",$ytime);
$ytime = str_replace("S","초",$ytime);

 

제가 쓰는 소스코드중에 일부


<script src=https://www.youtube.com/iframe_api></script>
<script>
function onYouTubeIframeAPIReady() {
    divPlayer = new YT.Player('iframePlayer', { events: {'onReady': onPlayerReady} });
}
function onPlayerReady(event) {
    event.target.playVideo();
}
function youtubeState() {
    youtubeTimer = setInterval(youtubeCurrent, 500);
}
function youtubeCurrent() {
    currentTimer.innerText = divPlayer.getCurrentTime();
    totalTimer.innerText = divPlayer.getDuration();
}
youtubeState();
</script>
<div id=divPlayer><iframe id=iframePlayer src=https://www.youtube.com/embed/VlMEGBsw6j8?enablejsapi=1 frameborder=0 allowfullscreen width=720 height=405></iframe></div>
<div id=currentTimer></div>
<div id=totalTimer></div>

 

https://sir.kr/g5_tip/15814

http://www.mediaplayer.kr/main/tip/12

답변을 작성하시기 전에 로그인 해주세요.
전체 445
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT