케빈엉클

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

· 2025-02-27 (목) 14:01:31 · 3031

[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 팁자료실

2,788건
+
제목 글쓴이 날짜 조회
25-04-10 조회 3,687
25-04-09 조회 4,035
25-04-08 조회 3,252
25-04-02 조회 3,260
25-03-30 조회 3,236
25-03-27 조회 3,186
25-03-26 조회 3,108
25-03-26 조회 3,255
25-03-25 조회 3,311
25-03-23 조회 3,277
25-03-21 조회 3,378
25-03-20 조회 3,201
25-03-19 조회 3,252
25-03-18 조회 3,500
25-03-17 조회 3,025
25-03-13 조회 3,139
25-03-12 조회 3,539
25-03-09 조회 3,101
25-03-06 조회 3,267
25-03-05 조회 3,431
25-03-04 조회 3,391
25-03-04 조회 2,865
25-02-27 조회 3,352
25-02-27 조회 3,032
25-02-27 조회 2,889
25-02-27 조회 3,086
25-02-27 조회 3,208
25-02-24 조회 3,218
25-02-22 조회 3,117
25-02-21 조회 3,092