케빈엉클

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

· 12개월 전 · 835

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

+
제목 글쓴이 날짜 조회
11개월 전 조회 897
11개월 전 조회 1,088
11개월 전 조회 807
11개월 전 조회 940
11개월 전 조회 1,081
11개월 전 조회 695
11개월 전 조회 813
11개월 전 조회 1,186
11개월 전 조회 777
11개월 전 조회 944
11개월 전 조회 973
11개월 전 조회 996
11개월 전 조회 630
12개월 전 조회 1,040
12개월 전 조회 836
12개월 전 조회 681
12개월 전 조회 751
12개월 전 조회 729
1년 전 조회 840
1년 전 조회 791
1년 전 조회 706
1년 전 조회 800
1년 전 조회 893
1년 전 조회 803
1년 전 조회 768
1년 전 조회 1,331
1년 전 조회 719
1년 전 조회 1,305
1년 전 조회 855
1년 전 조회 704