If I have a YouTube video URL, is there any way to use PHP and cURL to get the associated thumbnail from the YouTube API?YouTube 동영상 URL이 있는 경우, PHP와 cURL을 사용하여 YouTube API에서 관련 섬네일을 얻을 수 있는 방법이 있습니까?
질문에 대한 답변
Each YouTube video has four generated images.각 YouTube 비디오는 4개의 생성된 이미지를 가지고 있다. They are predictably formatted as follows:이러한 형식은 다음과 같습니다.
https://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg https://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg https://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg https://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
The first one in the list is a full size image and others are thumbnail images.목록의 첫 번째 이미지는 풀사이즈 이미지이고 다른 이미지는 섬네일 이미지입니다. The default thumbnail image (i.e., one of 디폴트 섬네일 이미지(즉,1.jpg
, ,2.jpg
, ,3.jpg
) is:)는 다음과 같습니다.
https://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
For the high quality version of the thumbnail use a URL similar to this:고품질 버전의 섬네일에는 다음과 같은 URL을 사용합니다.
https://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg
There is also a medium quality version of the thumbnail, using a URL similar to the HQ:또한 HQ와 유사한 URL을 사용하는 중간 품질의 섬네일 버전도 있습니다.
https://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg
For the standard definition version of the thumbnail, use a URL similar to this:썸네일의 표준 정의 버전에는 다음과 같은 URL을 사용합니다.
https://img.youtube.com/vi/<insert-youtube-video-id-here>/sddefault.jpg
For the maximum resolution version of the thumbnail use a URL similar to this:썸네일의 최대 해상도 버전은 다음과 같은 URL을 사용합니다.
https://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
All of the above URLs are available over HTTP too.위의 URL은 모두 HTTP를 통해서도 사용할 수 있습니다. Additionally, the slightly shorter hostname 또, 호스트명이 약간 짧아집니다.i3.ytimg.com
works in place of 대용품img.youtube.com
in the example URLs above.를 참조해 주세요.
Alternatively, you can use the YouTube Data API (v3) to get thumbnail images.또는 YouTube Data API(v3)를 사용하여 미리 보기 이미지를 가져올 수 있습니다.
You can use YouTube Data API to retrieve video thumbnails, caption, description, rating, statistics and more.YouTube Data API를 사용하여 비디오 썸네일, 캡션, 설명, 등급, 통계 등을 검색할 수 있습니다. API version 3 requires a key*.API 버전 3에는 키*가 필요합니다. Obtain the key and create a videos: list request:키를 가져와 비디오를 만듭니다.목록 요청:
https://www.googleapis.com/youtube/v3/videos?key=YOUR_API_KEY&part=snippet&id=VIDEO_ID
Example PHP CodePHP 코드 예시
$data = file_get_contents("https://www.googleapis.com/youtube/v3/videos?key=YOUR_API_KEY&part=snippet&id=T0Jqdjbed40"); $json = json_decode($data); var_dump($json->items[0]->snippet->thumbnails);
Output산출량
object(stdClass)#5 (5) { ["default"]=> object(stdClass)#6 (3) { ["url"]=> string(46) "https://i.ytimg.com/vi/T0Jqdjbed40/default.jpg" ["width"]=> int(120) ["height"]=> int(90) } ["medium"]=> object(stdClass)#7 (3) { ["url"]=> string(48) "https://i.ytimg.com/vi/T0Jqdjbed40/mqdefault.jpg" ["width"]=> int(320) ["height"]=> int(180) } ["high"]=> object(stdClass)#8 (3) { ["url"]=> string(48) "https://i.ytimg.com/vi/T0Jqdjbed40/hqdefault.jpg" ["width"]=> int(480) ["height"]=> int(360) } ["standard"]=> object(stdClass)#9 (3) { ["url"]=> string(48) "https://i.ytimg.com/vi/T0Jqdjbed40/sddefault.jpg" ["width"]=> int(640) ["height"]=> int(480) } ["maxres"]=> object(stdClass)#10 (3) { ["url"]=> string(52) "https://i.ytimg.com/vi/T0Jqdjbed40/maxresdefault.jpg" ["width"]=> int(1280) ["height"]=> int(720) } }
* Not only that you need a key, you might be asked for billing information depending on the number of API requests you plan to make.* 키가 필요할 뿐만 아니라 API 요청 수에 따라 청구 정보를 요구할 수 있습니다. However, few thousand requests per day are free.그러나 하루에 몇 천 건의 요청은 무료입니다.
Source article.소스 기사
What Asaph said is right.아삽의 말이 맞아 However, not every YouTube video contains all nine thumbnails.그러나 모든 유튜브 동영상이 9개의 썸네일을 모두 포함하는 것은 아니다. Also, the thumbnails’ image sizes depends on the video (the numbers below are based on one).또, 썸네일의 이미지 사이즈는 비디오에 의해서 다릅니다(아래의 수치는 1을 기준으로 하고 있습니다). There are some thumbnails guaranteed to exist:몇 가지 썸네일이 존재합니다.
Width Height URL ------ -------- ---- 120 90 https://i.ytimg.com/vi/<VIDEO ID>/1.jpg 120 90 https://i.ytimg.com/vi/<VIDEO ID>/2.jpg 120 90 https://i.ytimg.com/vi/<VIDEO ID>/3.jpg 120 90 https://i.ytimg.com/vi/<VIDEO ID>/default.jpg 320 180 https://i.ytimg.com/vi/<VIDEO ID>/mq1.jpg 320 180 https://i.ytimg.com/vi/<VIDEO ID>/mq2.jpg 320 180 https://i.ytimg.com/vi/<VIDEO ID>/mq3.jpg 320 180 https://i.ytimg.com/vi/<VIDEO ID>/mqdefault.jpg 480 360 https://i.ytimg.com/vi/<VIDEO ID>/0.jpg 480 360 https://i.ytimg.com/vi/<VIDEO ID>/hq1.jpg 480 360 https://i.ytimg.com/vi/<VIDEO ID>/hq2.jpg 480 360 https://i.ytimg.com/vi/<VIDEO ID>/hq3.jpg 480 360 https://i.ytimg.com/vi/<VIDEO ID>/hqdefault.jpg
Additionally, the some other thumbnails may or may not exist.또, 그 외의 썸네일은 존재하거나 존재하지 않을 수 있습니다. Their presence is probably based on whether the video is high-quality.그들의 존재는 아마도 비디오가 고품질인지 아닌지에 따라 결정될 것이다.
Width Height URL ------ -------- ---- 640 480 https://i.ytimg.com/vi/<VIDEO ID>/sd1.jpg 640 480 https://i.ytimg.com/vi/<VIDEO ID>/sd2.jpg 640 480 https://i.ytimg.com/vi/<VIDEO ID>/sd3.jpg 640 480 https://i.ytimg.com/vi/<VIDEO ID>/sddefault.jpg 1280 720 https://i.ytimg.com/vi/<VIDEO ID>/hq720.jpg 1920 1080 https://i.ytimg.com/vi/<VIDEO ID>/maxresdefault.jpg
You can find JavaScript and PHP scripts to retrieve thumbnails and other YouTube information in:JavaScript 및 PHP 스크립트를 검색하여 미리 보기 및 기타 YouTube 정보를 검색할 수 있습니다.
- How to get YouTube Video Info with PHPPHP로 YouTube 비디오 정보를 얻는 방법
- Retrieve YouTube Video Details using JavaScript – JSON & API v2JavaScript를 사용한 YouTube 비디오 상세 검색 – JSON 및 API v2
You can also use the YouTube Video Information Generator tool to get all the information about a YouTube video by submitting a URL or video id.또한 YouTube Video Information Generator 도구를 사용하여 URL 또는 비디오 ID를 전송하여 YouTube 비디오에 대한 모든 정보를 얻을 수 있습니다.
In YouTube API V3 we can also use these URLs for obtaining thumbnails…유튜브 APIV3에서 우리는 또한 미리 보기를 취득하기 위한 이러한 URL을 사용할 수 있다. They are classified based on their quality.그들은 품질에 따라 분류된다.
https://i1.ytimg.com/vi/<insert-youtube-video-id-here>/default.jpg - default https://i1.ytimg.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg - medium https://i1.ytimg.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg - high https://i1.ytimg.com/vi/<insert-youtube-video-id-here>/sddefault.jpg - standard
And for the maximum resolution..그리고 최대 해상도를 위해..
https://i1.ytimg.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
One advantage of these URLs over the URLs in the first answer is that these URLs don’t get blocked by firewalls.첫 번째 답변의 URL에 비해 이러한 URL의 장점은 이러한 URL이 방화벽에 의해 차단되지 않는다는 것입니다.
If you want to get rid of the “black bars” and do it like YouTube does it, you can use:“검은 막대”를 없애고 YouTube가 하는 것처럼 하고 싶다면 다음을 사용할 수 있습니다.
https://i.ytimg.com/vi_webp/<video id>/mqdefault.webp
And if you can’t use the 사용할 수 없는 경우.webp
file extension you can do it like this:파일 확장자는 다음과 같이 할 수 있습니다.
https://i.ytimg.com/vi/<video id>/mqdefault.jpg
Also, if you need the unscaled version, use 또, 언스케일 버전이 필요한 경우는,maxresdefault
instead of 대신mqdefault
..
Note: I’m not sure about the aspect ratio if you’re planning to use 주의: 애스펙트 비율을 알 수 없습니다.maxresdefault
..