Playlist Items
Yt::PlaylistItem represents a playlist item.
Initialize using an ID or using Yt::Playlist#playlist_items:
item = Yt::PlaylistItem.new id: 'PLjW_GNR5Ir0GWEP_ove'
item = Yt::Playlist.new(id: 'PLSWYkYzOrPMRUYaLE6C9').playlist_items.first
# => All these methods return #<Yt::PlaylistItem:0x... @id="PLjW_GNR5Ir0GWEP_ove">
Some methods from other classes also return a Yt::PlaylistItem object
(e.g.: Yt::Playlist#add_video) or a collection of Yt::PlaylistItem
objects (e.g.: Playlist#playlist_items).
Authentication
Most methods of Yt::PlaylistItem retrieve public data from YouTube (e.g.: the position in the playlist).
To use these methods (marked with below), you only need to get a Server API key from Google and configure:
Yt.configuration.api_key = "<your api key>" ## replace with your API key
item = Yt::PlaylistItem.new id: 'PLjW_GNR5Ir0GWEP_ove'
item.position
# => 3
Other methods acts on behalf of YouTube accounts (e.g.: delete an item from a playlist).
To use these methods (marked with below), you need to get an API Client ID/Secret from Google, obtain an access or refresh token from the account you want to act as, and pass the account as the :auth parameter:
Yt.configuration.client_id = "<your ID>" ## replace with your client ID
Yt.configuration.client_secret = "<your secret>" ## replace with your client secret
account = Yt::Account.new refresh_token: "<token>" ## use the account’s refresh token
item = Yt::PlaylistItem.new id: 'PLjW_GNR5Ir0GWEP_ove', auth: account
item.delete
# => trueList of Yt::PlaylistItem methods
- any authentication works Playlist Item’s Snippet
→ Yt docs
item.id # => "PLjW_GNR5Ir0GWEP_ove"→ Yt docsitem.title # => "Welcome to Fullscreen"→ Yt docsitem.description # => "We are Fullscreen"→ Yt docsitem.published_at # => 2013-08-14 19:14:21 UTC→ Yt docsitem.thumbnail_url # => "https://i.ytimg.com/vi/JhRmvEP4IJ8/default.jpg"→ Yt docsitem.channel_id # => "UCxO1tY8h1AhOz0T4ENwmpow"→ Yt docsitem.channel_title # => "Fullscreen"→ Yt docsitem.playlist_id # => "PLSWYkYzOrPMRUYaLE6C9"→ Yt docsitem.video_id # => "BPNYv0vd78A"→ Yt docsitem.position # => 3- any authentication works Playlist Item’s Privacy Status
- must authenticate as the playlist item’s account or content owner Playlist Item’s Updates
- any authentication works Playlist Item’s Associations
→ Yt docs
item.video # => #<Yt::Video …>