Playlist items
Yt::PlaylistItem represents a YouTube playlist item.
Initialize using its YouTube ID:
item = Yt::PlaylistItem.new id: 'UEwtTGVUdXRjOUdSS0Qze'
# => #<Yt::PlaylistItem:0x... @id=UEwtTGVUdXRjOUdSS0Qze>Authentication
Most methods of Yt::PlaylistItem retrieve public data from YouTube (e.g.: fetch an item’s position).
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
item = Yt::PlaylistItem.new id: 'UEwtTGVUdXRjOUdSS0Qze' ## use any playlist item ID
item.position # => 0List of Yt::PlaylistItem data methods
- any authentication works Playlist item’s snippet
→ Yt docs
item.id # => "UEwtTGVUdXRjOUdSS0Qze"→ Yt docsitem.title # => "First public video"→ Yt docsitem.description # => "A YouTube video to test the yt gem."→ Yt docsitem.published_at # => 2016-11-18 23:40:55 UTC→ Yt docsitem.thumbnail_url # => "https://i.ytimg.com/vi/gknzFj_0vvY/default.jpg"→ Yt docsitem.channel_id # => "UCwCnUcLcb9-eSrHa_RQGkQQ"→ Yt docsitem.channel_title # => "Yt Test"→ Yt docsitem.playlist_id # => "PL-LeTutc9GRKD3yBDhnRF_yE8UTaQI5Jf"→ Yt docsitem.position # => 0→ Yt docsitem.video_id # => "gknzFj_0vvY"- any authentication works Playlist item’s status
→ Yt docs
item.privacy_status # => "public"
To limit the number of HTTP requests, use select to specify which parts of the item’s data to load:
slow = item # => without select: 2 HTTP requestsslow.title # => one HTTP request to fetch the item’s snippetslow.privacy_status # => => another HTTP request to fetch the item’s status→ Yt docsfast = item.select :snippet, :status # => with select: 1 HTTP requestfast.title # => one HTTP request to fetch both the item’s snippet and statusfast.privacy_status # => => no extra HTTP requests