Class: YouTube::Video

Inherits:
Object
  • Object
show all
Defined in:
lib/you_tube/objects/video.rb

Instance Method Summary collapse

Methods inherited from Object

#to_ostruct

Constructor Details

#initialize(options = {}) ⇒ Video

Returns a new instance of Video.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/you_tube/objects/video.rb', line 4

def initialize(options = {})
  super options

  if options["snippet"]
    self.title        = options["snippet"]["title"]
    self.description  = options["snippet"]["description"]
    self.published_at = options["snippet"]["publishedAt"]
    self.channel_id   = options["snippet"]["channelId"]

    if options["snippet"]["thumbnails"]
      thumb = options["snippet"]["thumbnails"]
      self.thumbnail_default  = thumb["default"]["url"]   if thumb["default"]
      self.thumbnail_medium   = thumb["medium"]["url"]    if thumb["medium"]
      self.thumbnail_high     = thumb["high"]["url"]      if thumb["high"]
      self.thumbnail_standard = thumb["standard"]["url"]  if thumb["standard"]
      self.thumbnail_maxres   = thumb["maxres"]["url"]    if thumb["maxres"]
    end
  end

  # Is a Video is blocked in any countries?
  if options["contentDetails"]
    self.blocked = !options["contentDetails"]["regionRestriction"].nil?
    self.age_restricted = !options["contentDetails"]["contentRating"].nil? && options["contentDetails"]["contentRating"]["ytRating"] == "ytAgeRestricted"
  end

  if options["liveStreamingDetails"]
    self.live_stream = options["liveStreamingDetails"]["actualStartTime"].present?
  else
    self.live_stream = false
  end

  if options["status"]
    self.upload_status  = options["status"]["uploadStatus"]
    self.privacy_status = options["status"]["privacyStatus"]
  end
end