Videos

Yt::Video represents a YouTube video. Initialize using its YouTube ID:

→ Yt docsvideo = Yt::Video.new id: "gknzFj_0vvY"
# => #<Yt::Video @id=gknzFj_0vvY>
→ Yt docsvideo.canonical_url
# => "https://www.youtube.com/watch?v=gknzFj_0vvY"

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:

Yt.configuration.api_key = "<your api key>"                        ## use your API key

video = Yt::Video.new id: 'gknzFj_0vvY'                            ## use any video ID
video.title # => "First public video"

List of Yt::Video data methods

any authentication works Video’s snippet
→ Yt docsvideo.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
→ Yt docsvideo.privacy_status # => "public"
→ Yt docsvideo.upload_status # => "processed"
→ Yt docsvideo.license # => "creative_common"
→ Yt docsvideo.embeddable # => true
→ Yt docsvideo.public_stats_viewable # => false
any authentication works Video’s statistics
→ Yt docsvideo.view_count # => 123
→ Yt docsvideo.like_count # => 93
→ Yt docsvideo.dislike_count # => 42
→ Yt docsvideo.comment_count # => 62
any authentication works Video’s content details
→ Yt docsvideo.duration # => "PT2S"
→ Yt docsvideo.seconds # => 2
→ Yt docsvideo.length # => "00:00:02"
→ Yt docsvideo.dimension # => "2d"
→ Yt docsvideo.definition # => "sd"
→ Yt docsvideo.caption # => false
→ Yt docsvideo.licensed_content # => false
→ Yt docsvideo.projection # => "rectangular"

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 docsvideo.channel
# => #<Yt::Channel @id=UCwCnUcLcb9-eSrHa_RQGkQQ>