Languages
[Edit]
EN

JavaScript - get YouTube image url by video id

0 points
Created by:
Paris-Bateman
504

In this article, we would like to show you how to get YouTube image url by video id using JavaScript.

Quick solution:

Warning:

To avoid common mistake, remember not to add www to the src, e.g. use http://i.ytimg.com instead of: http://www.i.ytimg.com.

 Used resources:

  • Video id: SOGpvHun6vg
  • Full link: https://www.youtube.com/watch?v=SOGpvHun6vg

 

Practical example

Edit

Video id

Edit

URL Template

Edit

Configurations

Edit
imageQualityimageNumberDescription
'''default', '1', '2' or '3'low quality
'mq''default', '1', '2' or '3'medium quality
'hq''default', '1', '2' or '3'high quality
'sd''default', '1', '2' or '3'standard quality
'maxres''default', '1', '2' or '3'maximum resolution

Fully builded URLs

Edit
image typereturned URLs
Main frame image

Hint: hqdefault configuration we can replace with 0.

Random frame images (1-3)

Runnable example

Edit

In this example, we create a function that accepts two arguments YouTube video id and image quality. It returns the src of the YouTube video thumbnail image.

Reusable function

Edit

In this example, we present a reusable functions that get the images using given YouTube video id and appends them inside the placeholderElement.

 

See also

Edit
  1. JavaScript - create dynamically html element

Alternative titles

  1. JavaScript - get YouTube thumbnail image url by video id
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join