2026, 새로운 도약을 시작합니다.

유튜브/비메오 ID로부터 비디오 썸네일 갖고오기 (youtube.lib.php)

· 10개월 전 · 716

[code]

<?php

if (!defined('_GNUBOARD_')) exit;

function get_youtube_id($contents)

{

    if(!$contents)

        return false;

preg_match('/(?:youtube(?:-nocookie)?\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|shorts\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/', $contents, $match); //all working included shorts and iframe

return $match[1] ?? false;

}

function get_youtube_thumbnail($youtube_id, $thumb_str="0"){

    if(!$youtube_id)

        return false;

    return "https://img.youtube.com/vi/".$youtube_id."/".$thumb_str.".jpg";

}

function get_vimeo_id($contents)

{

    if(!$contents)

        return false;

        $pattern = '/(?:https?:\/\/)?(?:www\.)?(?:player\.)?vimeo\.com\/(?:video\/|channels\/(?:\w+\/)?|groups\/(?:[^\/]*)\/videos\/|album\/(?:\d+)\/video\/|)(\d+)(?:[a-zA-Z0-9_-]+)?/i';

    preg_match($pattern, $contents, $match);

    return $match[1] ?? false;

function get_vimeo_thumbnail($id) {

    if (!$id) return false;

    $url = "https://vimeo.com/api/oembed.json?url=https://vimeo.com/" . $id;

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    $response = curl_exec($ch);

    curl_close($ch);

    if ($response) {

        $data = json_decode($response);

        return $data->thumbnail_url ?? false;

    }

    return false;

}

[/code]

|

댓글 작성

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

로그인하기

그누보드5 팁자료실

번호 제목 글쓴이 날짜 조회
공지 3년 전 조회 4,598
2741 3일 전 조회 111
2740 4일 전 조회 103
2739 1주 전 조회 209
2738 1주 전 조회 217
2737 1주 전 조회 181
2736 1주 전 조회 280
2735 3주 전 조회 281
2734 3주 전 조회 263
2733 1개월 전 조회 265
2732 1개월 전 조회 301
2731 1개월 전 조회 267
2730 1개월 전 조회 226
2729 1개월 전 조회 356
2728 1개월 전 조회 245
2727 1개월 전 조회 422
2726 1개월 전 조회 256
2725 1개월 전 조회 330
2724 1개월 전 조회 358
2723 1개월 전 조회 267
2722 1개월 전 조회 300
2721 1개월 전 조회 211
2720 2개월 전 조회 304
2719 2개월 전 조회 307
2718 2개월 전 조회 202
2717 2개월 전 조회 336
2716 2개월 전 조회 202
2715 2개월 전 조회 311
2714 2개월 전 조회 273
2713 2개월 전 조회 376
2712 2개월 전 조회 289
🐛 버그신고