35.Youtube






펌자료)유튜브 동영상 API 썸네일 이미지 자동 출력

♨ 카랜더 일정 :
  • 링크

  • 첨부

  • 컨텐츠 정보

    본문

    ■ 펌자료)유튜브 동영상 API 썸네일 이미지 자동 출력

    유튜브 API를 활용해서 주소만 넣으면 동영상 썸네일 이미지를 게시판 목록에 자동으로 출력하는 방법입니다.

    유튜브 이미지를 출력하기 위해서는 우선 동영상 ID 값이 필요합니다.

    예를 들어 유튜브에서 동영상 퍼가기를 클릭하면 코드가 이런식으로 되어 있는데

    https://youtu.be/0wlXaHmmOVc 

    여기서 맨 뒷부분 값이 필요합니다.



    유튜브 API 에서는 사이즈별로 다양하게 썸네일 이미지를 기본으로 제공하고 있습니다.


    120X90 (default.jpg) 

    https://img.youtube.com/vi/0wlXaHmmOVc/default.jpg


    320X180 (mqdefault.jpg)

    https://img.youtube.com/vi/0wlXaHmmOVc/mqdefault.jpg


    480X360 (hqdefault.jpg)

    https://img.youtube.com/vi/0wlXaHmmOVc/hqdefault.jpg


    640X480 (sddefault.jpg) 

    https://img.youtube.com/vi/0wlXaHmmOVc/sddefault.jpg


    동영상 최대 해상도 (maxresdefault.jpg)

    https://img.youtube.com/vi/0wlXaHmmOVc/maxresdefault.jpg


    스킨 만드실 때 적당한 사이즈로 골라서 사용하시면 됩니다.

    (빨간색 부분 변경하면 됩니다.)



    그누보드 기본 gallery 스킨에 실제 적용을 해보겠습니다.

    일단 link 필드나 여분 필드를 활용해서 저 주소값을 입력받아야겠죠.

    예제는 여분 필드로 설명하겠습니다.



    write.skin.php 파일 수정


    wr_1 여분필드를 사용해서 유튜브 동영상 주소값을 입력받습니다.


    <tr>

        <th scope="row"><label for="youtube">유튜브주소</label></th>

        <td><input type="text" name="wr_1" value="<?php echo $write['wr_1'] ?>" id="wr_1" class="frm_input" size="50"><p style="margin-top:5px">입력예 : https://youtu.be/0wlXaHmmOVc</p></td>

    </tr>



    list.skin.php 파일 수정


    <?php

    if ($list[$i]['is_notice']) { // 공지사항  ?>

        <strong style="width:<?php echo $board['bo_gallery_width'] ?>px;height:<?php echo $board['bo_gallery_height'] ?>px">공지</strong>

    <?php } else {

        $thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height']);


        if($thumb['src']) {

            $img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'">';

        } else {

            $img_content = '<span style="width:'.$board['bo_gallery_width'].'px;height:'.$board['bo_gallery_height'].'px">no image</span>';

        }


        echo $img_content;

    }

    ?>


    위 코드를 이렇게 변경합니다. 빨간색 부분이 변경된 부분입니다.


    <?php

    if ($list[$i]['is_notice']) { // 공지사항  ?>

        <strong style="width:<?php echo $board['bo_gallery_width'] ?>px;height:<?php echo $board['bo_gallery_height'] ?>px">공지</strong>

    <?php } else {

        $thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height']);


        if($list[$i]['wr_1']) {

            $youtube_id = str_replace("https://youtu.be/", "", $list[$i]['wr_1']);

            $img_content = '<img src="https://img.youtube.com/vi/'.$youtube_id.'/mqdefault.jpg" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'">';

        } else if($thumb['src']) {

            $img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'">';

        } else {

            $img_content = '<span style="width:'.$board['bo_gallery_width'].'px;height:'.$board['bo_gallery_height'].'px">no image</span>';

        }


        echo $img_content;

    }

    ?>



    유튜브 주소값을 입력했으면 유튜브 썸네일을 출력하고

    없으면 에디터나 파일 첨부로 등록한 이미지를 출력하라는 내용입니다.


    코드를 유심히 보면 처음에 설명해드린 유튜브에서 기본으로 제공하는 형태는 이렇고..

    https://img.youtube.com/vi/0wlXaHmmOVc/mqdefault.jpg


    예제에 사용된 그누보드 스킨에서는 동영상 ID 값을 이렇게 적용했습니다.

    https://img.youtube.com/vi/'.$youtube_id.'/mqdefault.jpg


    그리고 $youtube_id 값은 wr_1 여분필드에서 입력받은 값에서 이렇게 추출을 했고요.

    $youtube_id = str_replace("https://youtu.be/", "", $list[$i]['wr_1']);


    유튜브 동영상 ID 입 출력 방법은 기본적인 방법으로 했으며 더 나은 방법이 있으면 변경하셔도 됩니다.




    * 참고사항


    view 페이지에서의 동영상 출력은 view.skin.php 파일 적당한 곳에 이렇게 추가


    <?php

    if($view['wr_1']) {

    $youtube_id = str_replace("https://youtu.be/", "", $view['wr_1']);

    ?>

    <iframe width="560" height="315" src="https://www.youtube.com/embed/<?php echo $youtube_id ?>" frameborder="0" allowfullscreen></iframe>

    <?php } ?>

    ===================================

    설치응용1



    <!-- <iframe width="640" height="360" src="https://www.youtube.com/embed/nVCubhQ454c" frameborder="0" allowfullscreen></iframe> -->
    <!-- 게시판 목록 시작 { -->

    <?
    $url=$list[0]['wr_link1'];
             $urls  = explode("?v=",$url);
             $urls2 = explode("&"$urls[1]);
     $img_content = '<img src="http://img.youtube.com/vi/'.$urls2[0].'/0.jpg" alt="" width="'.$board['bo_gallery_width'].'" >';
     echo $img_content;
     ?>



    <!-- <iframe id='testID' width="280" height="160" src="https://www.youtube.com/embed/<?=$urls2[0]?>" frameborder="0" allowfullscreen></iframe></center> -->
    <iframe id='testID' width="280" height="160" src="https://www.youtube.com/embed/<?=$urls2[0]?>" frameborder="0" allowfullscreen></iframe></center>
    <!-- 아래 ok -->
     <!-- <iframe width="280" height="160" src="https://www.youtube.com/embed/<?=$uls2[0]?>" frameborder="0" allowfullscreen></iframe> -->
     <!-- <iframe width="280" height="160" src="https://www.youtube.com/embed/<?=$urls2[0]?>" frameborder="0" allowfullscreen></iframe> -->
    <br><br><br><br><br><br>

    <script type="text/javascript">
    function ChangeSrc(url_yo,w_i,h_i) {
    document
    var newSrc = "https://www.youtube.com/embed/"+url_yo;
            document.getElementById("testID").src = newSrc;
            document.getElementById("testID").style.width = w_i+'px';
            document.getElementById("testID").style.height = h_i+'px';
        }
    </script>

    <!-- 출처: https://webdir.tistory.com/472 [WEBDIR] -->
    <!-- 소스코드 : <iframe width="640" height="360" src="https://www.youtube.com/embed/nVCubhQ454c" frameborder="0" allowfullscreen></iframe> -->

    <!-- 출처: https://webdir.tistory.com/472 [WEBDIR] -->
    <!-- https://img.youtube.com/vi/nVCubhQ454c/mqdefault.jpg -->
    <!-- 출처: https://webdir.tistory.com/472 [WEBDIR] -->


    설치응용2

    <?php
    // ================================================================================================================
    if ($list[$i]['is_notice']) { // 공지사항  ?>
        <strong style="width:<?php echo $board['bo_gallery_width'?>px;height:<?php echo $board['bo_gallery_height'?>px">공지</strong>
    <?php } else {
        $thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height']);

        if($list[$i]['wr_1']) {
            $youtube_id = str_replace("https://youtu.be/"""$list[$i]['wr_1']);
            $img_content = '<img src="https://img.youtube.com/vi/'.$youtube_id.'/mqdefault.jpg" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'">';
        } else if($thumb['src']) {
            $img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'">';
        } else {
            // $img_content = '<span style="width:'.$board['bo_gallery_width'].'px;height:'.$board['bo_gallery_height'].'px">no image</span>';
            $img_content = '<span style="width:'.$board['bo_gallery_width'].'px;height:'.$board['bo_gallery_height'].'px">유튜브 첨부</span>';

        }
        echo $img_content;
      }

    ?>


    실제 해보시면 방법은 매우 간단합니다.

    ▶ ☞ 정보찾아 공유 드리며 출처는 링크 참조 바랍니다 ♠ . ☞ 본자료는 https://11q.kr 에 등록 된 자료 입니다♠.

    [ 추가 정보 ... 더보기) ]
    뷰PDF 1,2



    office view

    관련자료

    댓글목록

    profile_image

    11qkr님의 댓글

    11qkr 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 아이피 (192.♡.0.1) 작성일

    <?php
    if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
    include_once(G5_LIB_PATH.'/thumbnail.lib.php');

    // add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
    add_stylesheet('<link rel="stylesheet" href="'.$board_skin_url.'/style.css">', 0);


    ?>
    <?
    $url=$list[0]['wr_link1'];
    $urls = explode("?v=",$url);
    $urls2 = explode("&", $urls[1]);
     $img_content = '<img src="http://img.youtube.com/vi/'.$urls2[0].'/0.jpg" alt="" width="'.$board['bo_gallery_width'].'" >';
     echo $img_content;
     ?>



    <!-- <iframe id='testID' width="280" height="160" src="https://www.youtube.com/embed/<?=$url[0]?>" frameborder="0" allowfullscreen></iframe></center> -->
    <!-- <iframe id='testID' width="280" height="160" src="https://www.youtube.com/embed/<?=$urls2[0]?>" frameborder="0" allowfullscreen></iframe></center> -->
    <!-- 아래 ok -->
     <!-- <iframe width="280" height="160" src="https://www.youtube.com/embed/<?=$uls2[0]?>" frameborder="0" allowfullscreen></iframe> -->
     <iframe width="280" height="160" src="https://www.youtube.com/embed/<?=$urls2[0]?>" frameborder="0" allowfullscreen></iframe>
    <br><br><br><br><br><br>

    <script type="text/javascript">
    function ChangeSrc(url_yo,w_i,h_i) {
    document
    var newSrc = "https://www.youtube.com/embed/" url_yo;
            document.getElementById("testID").src = newSrc;
            document.getElementById("testID").style.width = w_i+'px';
    document.getElementById("testID").style.height = h_i+'px';
        }
    </script>

    <!-- 출처: https://webdir.tistory.com/472 [WEBDIR] -->
    <!-- 소스코드 : <iframe width="640" height="360" src="https://www.youtube.com/embed/nVCubhQ454c" frameborder="0" allowfullscreen></iframe> -->

    <!-- 출처: https://webdir.tistory.com/472 [WEBDIR] -->
    <!-- https://img.youtube.com/vi/nVCubhQ454c/mqdefault.jpg -->

    목록



    • 일간 조회수
        • 게시물이 없습니다.
    • 주간 조회수
        • 게시물이 없습니다.
    • 월간 조회수
        • 게시물이 없습니다.


    Total 222 / 3 Page
    [ 화면 달린 AI스피커 '구글 네스트 허브' 사용기 ]

    ■ ▶ ☞ 정보찾아 공유 드리며 출처는 링크 참조 바랍니다 ♠ . ☞ 본자료는 https://11q.kr 에 등록 된 자료 입니다♠.

    [ 청부1 동영상avi ] 댓글 1

    ■ \r\n\r\nHomepc.11q.kr\r\n=============================\n[이 게시물은 관리자님에 의해 2013-…

    [ 바다에누워 포토스태이션 ]

    ■ \r\n\r\n.....\r\nShims HomePage[https://11q.kr 홈피]\r\n========================…

    [ 첨부2의 동영상을 html 5 의 tag를 이용 모바일에서 사용하고 싶습니다 ] 댓글 1

    첨부2의 동영상을 html 5 의 tag를 이용 모바일에서 사용하고 싶습니다\r\n아래의 tag중에 첨부2의 path 를 자동으로 연결되게 하고…

    [ 영화의 명장며 ]

    Homepc.11q.kr\r\n=============================\n[이 게시물은 관리자님에 의해 2013-11-17 19:4…

    [ 싸이노래 ]

    ] ] Shims HomePage[https://11q.kr 홈피]\n[이 게시물은 관리자님에 의해 2013-11-17 19:40:25 24.P…

    [ LIFE360 ]

    ###■ https://11q.kr는 정보를 찾아 공유 합니다..■ https://11q.kr\r\n\r\n\n[이 게시물은 관리자님에 의해 2…

    [ 엄선된 html5 오디오 플레이어 10종류 - 그누보드 SIR ] 댓글 2

    \r\n\r\n\r\n\r\n\r\n엄선된 html5 오디오 플레이어 10종류 - 그누보드 SIR\r\n\r\n\r\n\r\n\r\nsir.co…

    [ 신들의 전쟁_극장에서 본것 _추천 ]

    Homepc.11q.kr\r\n=============================\n[이 게시물은 관리자님에 의해 2013-11-17 21:1…

    [ 다음팟인코더 자막합치기,쉬운방법 ]

    다음팟인코더 자막합치기,쉬운방법 :: 풋볼라이프footballlife.tistory.com/48\r\n다음팟인코더 영상과 자막 합치기 - You…

    [ 2큐션45도입사각위치계산방법 ]

    -------------------------------------- ♠ 출처는 링크 참조 바랍니다. https://11q.kr ♠

    [ 당구분석)코너각 ]

    https://youtu.be/ohZ_R_UIl18◎ ■ ▶ ☞ ♠ 정보찾아 공유 드리며 출처는 링크 참조 바랍니다. https://11q.kr…

    [ 구글 네스트 허브를 활용한 52가지 유용한 한국어 명령어 모음입니다. ] 댓글 1

    구글 네스트 허브를 활용한 52가지 유용한 한국어 명령어 모음입니다. 초등학생 이하 자녀가 있으신 부모분들께 적극 추천드립니다. 제품의 특징은 …

    [ ●소장 ● 내일은 미스트롯 9회 결승 , 준결승 레전드 미션 내용입니다. ]

    ● ● 내일은 미스트롯 9회 결승 , 준결승 레전드 미션 내용입니다.●내일은 미스트롯 9회 준결승 레전드 미션 내용입니다.●내일은 미스트롯 9회…

    [ 간단하게 유투브 동영상 받기 강좌 그림 설명 ]

    간단하게 유투브 동영상 받기 강좌 그림 설명 1.북마크 하나 복사2.북마크 이름변경3.북마크 url 아래 내용 붙이기 - 속성창이 뜨면 'URL…

    [ swf 자동실행 첨부 3에 .swf(2.5M_pc ok ]

    swf 자동실행 첨부 3에 .swf(2.5M_pc ok\r\n\r\n\r\nHomepc.11q.kr\r\n=====================…

    [ 영화의 명장면 유튜브 올리기 ]

    Shims HomePage[https://11q.kr 홈피영dvd화의 명장면 유튜브] ZenaPlus\r\n====================…



    ♥간단_메모글♥


    최근글


    새댓글



    PHP 안에 HTML ☞ 홈페이지 화면갱신 시간은 ♨
    ▶ 2024-05-20 04:09:34

    오늘의 홈 현황


    • 현재 접속자♨ 76 명
    • 오늘 가입자※ 0 명
    • 어제 가입자※ 2 명
    • 주간 가입자※ 12 명
    • 오늘 방문자 294 명
    • 어제 방문자 1,215 명
    • 최대 방문자 13,042 명
    • 전체 방문자 4,331,496 명
    • 전체 게시물※ 8,580 개
    • 전체 댓글수※ 24,628 개
    • 전체 회원수 10,975 명

    QR코드


    ☞ QR코드 스캔은 kakao앱 자체 QR코드

    알림 0








    최신글↑