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
    [ [포토샵] 사진이미지에서 원하는 부분만 잘라내서 사용하는 방법 ]

    [포토샵] 사진이미지에서 원하는 부분만 잘라내서 사용하는 방법사진을 둥글게 모서리를 만들기http://11q.kr/g5s/bbs/board.ph…

    [ ●더크루 영화 "넷플릭스"에서 꼭 봐야 하는 레전드 1위 범죄 액션 [영화리뷰 결말포함] ]

    ●더크루 영화"넷플릭스"에서 꼭 봐야 하는 레전드 1위 범죄 액션 [영화리뷰 결말포함] https://youtu.be/aJiL4GjdCu0 ☞h…

    [ ● 실시간 서울 한강 라이브캠 Seoul Hangang 4K Live Cam Korea Webcam w/Lo… ]

    ●실시간 서울 한강 라이브캠 Seoul Hangang 4K Live Cam Korea Webcam w/Lofi 韓国ライブカメラ, 반포대교 노을멍…

    [ 일본군을 무찌르는 말달리는 동영상 음악 html5 ]

    아래는 html5 code로 동영상 url을 직접 압력 \r\n\r\n \r\n\n[이 게시물은 관리자님에 의해 2013-06-10 21:38:…

    [ 부부간의 운전 연습 ]

    \n[이 게시물은 관리자님에 의해 2013-06-10 21:39:21 65.V_Youtube에서 이동 됨]\n[이 게시물은 관리자님에 의해 20…

    [ Girls' Generation(소녀시대) _ Oh! _ MusicVideo Oh! _ MusicVideo… ]

    Girls' Generation(소녀시대) _ Oh! _ MusicVideo.......................\n[이 게시물은 관리자님에…

    [ 동명상avi 모바일에서 첨부1에 추가 ] 댓글 1

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

    [ psy_싸이 시청앞 공영 동영상 ]

    psy_싸이 시청앞 공영 동영상\r\n\n[이 게시물은 관리자님에 의해 2013-06-10 21:37:00 62.V_PDS에서 이동 됨]\n[이…

    [ 금위의 영화 정보 ] 댓글 3

    Homepc.11q.kr\r\n============================= \r\nhttp://m.blog.naver.com/PostV…

    [ 자막 오류 자동 수정 프로그램 ( Sami Error Auto Fix Program ) ] 댓글 1

    영화가 pc에서 잘나오는데 divx에서 자막이 나오지 않을시- 불러와 저장만 하세요- 설치는 압축풀고 실행자막 오류 자동 수정 프로그램 ( Sa…

    [ 크롬캐스트에서 티빙으로 지상파 실시간 방송보기 ::: 티빙/웨이브/왓챠/SPOTV ::: ]

    아이티보이 IT boy구독자 6.7천명구독국내 OTT 서비스 중 하나인 티빙 TVING 은,미박스, 미스틱, 쉴드TV,그리고 구글의 크롬캐스트 …

    [ ● Netflix 영화 레드 노티스//액션 추천영화 ]

    ●Netflix영화레드 노티스스트림 파일로 저장 소장 하세요Korea 넷플릭스 코리아구독선수와 사기꾼의 화끈한 대결 레드 노티스. 인터폴이 중범…

    [ ● capcut 현존 최강 무료 동영상 편집기 ]

    ● capcut현존최강무료동영상편집기https://capcut.kr.uptodown.com/windows|이게있는데유료를왜써?https://yo…

    [ piwigo 나모웹html 삽입 ]

    [이 게시물은 관리자님에 의해 2013-04-05 00:55:48 74.DS_BBS/PDS에서 이동 됨][이 게시물은 관리자님에 의해 2013-…

    [ 동영상 첨부2 올리기로 ]

    동영상 첨부2 올리기로 ■ Homepc.11q.kr =============================\r\n\r\n\r\n\r\n\r\n\r…

    [ 소녀시대_I GOT A BOY_Music Video 1080.mp4 ]

    소녀시대_I GOT A BOY_Music Video .......................\n[이 게시물은 관리자님에 의해 2013-11-1…

    [ 유튜부 동영상 iframe ,링크1 ] 댓글 1

    \r\niframe\r\n================\r\n \r\n\r\n\n[이 게시물은 관리자님에 의해 2013-11-17 19:40:2…



    ♥간단_메모글♥


    최근글


    새댓글



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

    오늘의 홈 현황


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

    QR코드


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

    알림 0








    최신글↑