테스트 사이트 - 개발 중인 베타 버전입니다

유튜브 영상길이 추출하는 법 채택완료

Policia 4년 전 조회 2,069

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

 

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

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

 

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

 

 

댓글을 작성하려면 로그인이 필요합니다.

답변 3개

채택된 답변
+20 포인트
4년 전

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를 활용하여 가져올 수도 있습니다

 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

P
Policia
4년 전
감사합니다 api를 결국 써야겠네요

댓글을 작성하려면 로그인이 필요합니다.

</p>

<p><script src=<a href="https://www.youtube.com/iframe_api></script>" target="_blank" rel="noopener noreferrer">https://www.youtube.com/iframe_api></script></a>

<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></p>

<p><div id=divPlayer><iframe id=iframePlayer src=<a href="https://www.youtube.com/embed/VlMEGBsw6j8?enablejsapi=1" target="_blank" rel="noopener noreferrer">https://www.youtube.com/embed/VlMEGBsw6j8?enablejsapi=1</a> frameborder=0 allowfullscreen width=720 height=405></iframe></div>

<div id=currentTimer></div>

<div id=totalTimer></div></p>

<p>

 

https://sir.kr/g5_tip/15814

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

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

P
Policia
4년 전
감사합니다 :)!!

댓글을 작성하려면 로그인이 필요합니다.

ifelse
4년 전

</p>

<p>$url = "<a href="https://www.googleapis.com/youtube/v3/videos?key=키값&part=contentDetails&id=유튜브영상ID;" target="_blank" rel="noopener noreferrer">https://www.googleapis.com/youtube/v3/videos?key=키값&part=contentDetails&id=유튜브영상ID;</a></p>

<p>$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);</p>

<p>$ytime = $result->items[0]->contentDetails->duration;</p>

<p>$ytime = str_replace("PT","",$ytime);

$ytime = str_replace("M","분",$ytime);

$ytime = str_replace("S","초",$ytime);</p>

<p>

 

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

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

P
Policia
4년 전
감사합니다 결국 API군여..

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인