Videos
Yt::Video
represents a YouTube video.
Initialize using its YouTube ID:
Authentication
Most methods of Yt::Video
retrieve public data from YouTube (e.g.: fetch a video’s title).
To use these methods (marked with below), you only need to generate an API key and configure:
List of Yt::Video
data methods
- any authentication works Video’s snippet
→ Yt docs
video.id # => "gknzFj_0vvY"
→ Yt docsvideo.title # => "First public video"
→ Yt docsvideo.description # => "A YouTube video to test the yt gem."
→ Yt docsvideo.published_at # => 2016-10-20 02:19:05 UTC
→ Yt docsvideo.thumbnail_url # => "https://i.ytimg.com/vi/gknzFj_0vvY/default.jpg"
→ Yt docsvideo.channel_id # => "UCwCnUcLcb9-eSrHa_RQGkQQ"
→ Yt docsvideo.channel_title # => "Yt Test"
→ Yt docsvideo.tags # => ["yt", "test", "tag"]
→ Yt docsvideo.category_id # => 22
→ Yt docsvideo.category_title # => "People & Blogs"
→ Yt docsvideo.live_broadcast_content # => "none"
- any authentication works Video’s status
- any authentication works Video’s statistics
- any authentication works Video’s content details
To limit the number of HTTP requests, use select
to specify which parts of the video’s data to load:
slow = video # => without select: 2 HTTP requests
slow.title # => one HTTP request to fetch the video’s snippet
slow.privacy_status # => => another HTTP request to fetch the video’s status
→ Yt docsfast = video.select :snippet, :status # => with select: 1 HTTP request
fast.title # => one HTTP request to fetch both the video’s snippet and status
fast.privacy_status # => => no extra HTTP requests
- any authentication works Video’s channel
→ Yt docs
video.channel
# => #<Yt::Channel @id=UCwCnUcLcb9-eSrHa_RQGkQQ>