Class: Yt::Playlist

Inherits:
Resource show all
Defined in:
lib/yt/playlist.rb

Overview

Provides methods to interact with YouTube playlists.

Instance Attribute Summary collapse

Attributes inherited from Resource

#data

Instance Method Summary collapse

Methods inherited from Resource

#id, #initialize, #inspect, #select, where

Constructor Details

This class inherits a constructor from Yt::Resource

Instance Attribute Details

#channel_idString (readonly)

Returns the ID of the channel that published the playlist.

Returns:

  • (String)

    the ID of the channel that published the playlist.


23
# File 'lib/yt/playlist.rb', line 23

has_attribute :channel_id, in: :snippet

#channel_titleString (readonly)

Returns the title of the channel that published the playlist.

Returns:

  • (String)

    the title of the channel that published the playlist.


27
# File 'lib/yt/playlist.rb', line 27

has_attribute :channel_title, in: :snippet

#descriptionString (readonly)

Returns the playlist’s description.

Returns:

  • (String)

    the playlist’s description.


# File 'lib/yt/playlist.rb', line 9

#item_count<Integer> (readonly)

Returns the number of videos in the playlist.

Returns:

  • (<Integer>)

    the number of videos in the playlist.


40
# File 'lib/yt/playlist.rb', line 40

has_attribute :item_count, in: :content_details, type: Integer

#privacy_statusString (readonly)

Returns the playlist’s privacy status. Valid values are: “private”, “public”, and “unlisted”.

Returns:

  • (String)

    the playlist’s privacy status. Valid values are: “private”, “public”, and “unlisted”.


36
# File 'lib/yt/playlist.rb', line 36

has_attribute :privacy_status, in: :status

#published_atTime (readonly)

Returns the date and time that the playlist was created.

Returns:

  • (Time)

    the date and time that the playlist was created.


15
# File 'lib/yt/playlist.rb', line 15

has_attribute :published_at, in: :snippet, type: Time

#thumbnailsHash<String, Hash> (readonly)

Returns the thumbnails associated with the playlist.

Returns:

  • (Hash<String, Hash>)

    the thumbnails associated with the playlist.


19
# File 'lib/yt/playlist.rb', line 19

has_attribute :thumbnails, in: :snippet

#titleString (readonly)

Returns the playlist’s title.

Returns:

  • (String)

    the playlist’s title.


7
# File 'lib/yt/playlist.rb', line 7

has_attribute :title, in: :snippet

Instance Method Details

#canonical_urlString

Returns the canonical form of the playlist’s URL.

Returns:

  • (String)

    the canonical form of the playlist’s URL.


55
56
57
# File 'lib/yt/playlist.rb', line 55

def canonical_url
  "https://www.youtube.com/playlist?list=#{id}"
end

#itemsYt::Relation<Yt::PlaylistItem>

Returns the items of the playlist.

Returns:


60
61
62
63
64
# File 'lib/yt/playlist.rb', line 60

def items
  @items ||= Relation.new(PlaylistItem, playlist_id: id) do |options|
    get '/youtube/v3/playlistItems', playlist_items_params(options)
  end
end

#thumbnail_url(size = :default) ⇒ String?

Returns the URL of the playlist’s thumbnail.

Parameters:

  • size (Symbol, String) (defaults to: :default)

    The size of the playlist’s thumbnail.

Returns:

  • (String)

    if size is :default, the URL of a 120x90px image.

  • (String)

    if size is :medium, the URL of a 320x180px image.

  • (String)

    if size is :high, the URL of a 480x360px image.

  • (String)

    if size is :standard, the URL of a 640x480px image.

  • (String)

    if size is :maxres, the URL of a 1280x720px image.

  • (nil)

    if the size is none of the above.


50
51
52
# File 'lib/yt/playlist.rb', line 50

def thumbnail_url(size = :default)
  thumbnails.fetch(size.to_s, {})['url']
end

#videosYt::Relation<Yt::Video>

Returns the videos of the playlist.

Returns:

  • (Yt::Relation<Yt::Video>)

    the videos of the playlist.


67
68
69
70
71
72
73
# File 'lib/yt/playlist.rb', line 67

def videos
  @videos ||= Relation.new(Video, playlist_id: id) do |options|
    params = playlist_items_params(options.merge parts: [:content_details])
    items = get '/youtube/v3/playlistItems', params
    videos_for items, 'contentDetails', options
  end
end