Namespace: ThumbnailUtils

utils/thumb-utils~ThumbnailUtils

A namespace containing all utility functions to process YouTube thumbnails.

Since:
  • 2.0.0
Source:

Methods

(static) getAllThumbnails(videoDetails, sortopt) → {AllThumbnailsObject}

Retrieves all thumbnails for a video, including the author and video thumbnails, and optionally sorts the thumbnails by resolution.

Parameters:
Name Type Attributes Default Description
videoDetails ytdl.videoDetails

The details of the video containing author and video information, retrieved from ytdl.getInfo() or ytmp3.getVideosInfo().

sort boolean <optional>
true

Whether to sort the thumbnails by resolution. Defaults to true.

Since:
  • 2.0.0
Source:
Throws:

If the provided videoDetails is not a plain object.

Type
InvalidTypeError
Returns:

An object containing all thumbnails including author and video thumbnails, and optionally sorted by resolution.

Type
AllThumbnailsObject

(static) getAuthorThumbnails(videoDetails, sortopt) → {Array.<ThumbnailObject>}

Retrieves the author's thumbnails from the provided video details object and optionally sorts the thumbnails by resolution.

Parameters:
Name Type Attributes Default Description
videoDetails ytdl.videoDetails

The video details object containing author information, retrieved from ytdl.getInfo() or ytmp3.getVideosInfo().

sort boolean <optional>
true

Whether to sort the thumbnails by resolution. Defaults to true.

Since:
  • 2.0.0
Source:
Throws:

If the provided videoDetails is not a plain object.

Type
InvalidTypeError
Returns:

An array of author thumbnails, optionally sorted by resolution. If no thumbnails are found, an empty array is returned.

Type
Array.<ThumbnailObject>

(static) getThumbnail(thumbnails, resolutionTypeopt) → {ThumbnailObject|null}

Alias for ThumbnailUtils.getThumbnailByResolution.

A bit different from getThumbnailByResolution, this function will use 'high' as the default resolution type if not provided. This resolution type prioritizes the 'maxresdefault' thumbnail if available, otherwise falls back to 'sddefault'.

Resolution Level

  • low: Corresponds to hqdefault thumbnail.
  • medium: Corresponds to mqdefault thumbnail.
  • high: Prioritizes the maxresdefault thumbnail if available, otherwise falls back to sddefault.
  • max: Corresponds to maxresdefault thumbnail if available, otherwise return null.

Note: It is recommended to use 'high' to have a fallback value in case the maxresdefault is unavailable.

Parameters:
Name Type Attributes Description
thumbnails Array.<ThumbnailObject>

An array of thumbnail objects.

resolutionType 'low' | 'medium' | 'high' | 'max' <optional>

Desired resolution level type.

Since:
  • 2.0.0
Source:
Throws:

If the resolution type is invalid.

Type
InvalidTypeError
Returns:

Thumbnail object matching the desired resolution, or null if the desired thumbnail is unavailable.

Type
ThumbnailObject | null

(static) getThumbnailByResolution(thumbnails, resolutionType) → {ThumbnailObject|null}

Retrieves a thumbnail based on the desired resolution level.

Resolution Level

  • low: Corresponds to hqdefault thumbnail.
  • medium: Corresponds to mqdefault thumbnail.
  • high: Prioritizes the maxresdefault thumbnail if available, otherwise falls back to sddefault.
  • max: Corresponds to maxresdefault thumbnail if available, otherwise return null.

Note: It is recommended to use 'high' to have a fallback value in case the maxresdefault is unavailable.

Parameters:
Name Type Description
thumbnails Array.<ThumbnailObject>

An array of thumbnail objects.

resolutionType 'low' | 'medium' | 'high' | 'max'

Desired resolution level type.

Since:
  • 2.0.0
Source:
Throws:

If the resolution type is invalid.

Type
InvalidTypeError
Returns:

Thumbnail object matching the desired resolution, or null if the desired thumbnail is unavailable.

Type
ThumbnailObject | null

(static) getVideoThumbnails(videoDetails, sortopt) → {Array.<ThumbnailObject>}

Retrieves the video thumbnails from the provided video details object and optionally sorts the thumbnails by resolution.

Parameters:
Name Type Attributes Default Description
videoDetails ytdl.videoDetails

The video details object containing video information, retrieved from ytdl.getInfo() or ytmp3.getVideosInfo().

sort boolean <optional>
true

Whether to sort the thumbnails by resolution. Defaults to true.

Since:
  • 2.0.0
Source:
Throws:

If the provided videoDetails is not a plain object.

Type
InvalidTypeError
Returns:

An array of video thumbnails, optionally sorted by resolution. If no thumbnails are found, returns an empty array.

Type
Array.<ThumbnailObject>

(static) sortThumbnailsByResolution(thumbnails) → {Array.<ThumbnailObject>}

Sorts an array of thumbnail objects by their resolution in ascending order.

Each thumbnail object is expected to have width and height properties. The resolution of a thumbnail is calculated as the product of its width and height.

Parameters:
Name Type Description
thumbnails Array.<ThumbnailObject>

An array of thumbnail objects to be sorted.

Since:
  • 2.0.0
Source:
Throws:

If the input is not an array of thumbnail objects.

Type
InvalidTypeError
Returns:

A new array of thumbnail objects sorted by resolution in ascending order.

Type
Array.<ThumbnailObject>